@govuk-pay/cli 0.0.31 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handler = exports.builder = exports.desc = exports.command = void 0;
7
+ const node_child_process_1 = require("node:child_process");
8
+ const app_client_js_1 = __importDefault(require("../app_client/app_client.js"));
9
+ const standardContent_1 = require("../../../core/standardContent");
10
+ exports.command = 'token';
11
+ exports.desc = 'Create a token';
12
+ const builder = (yargs) => {
13
+ return yargs
14
+ .usage(`$0 local token [--gateway-account-id <gateway-account-id>]\n\n${exports.desc}`)
15
+ .option('gateway-account-id', {
16
+ type: 'string',
17
+ description: 'ID of the gateway account'
18
+ });
19
+ };
20
+ exports.builder = builder;
21
+ exports.handler = tokenHandler;
22
+ async function tokenHandler(argv) {
23
+ await (0, standardContent_1.showHeader)();
24
+ let gatewayAccountID = argv.gatewayAccountID;
25
+ if (await app_client_js_1.default.isUnhealthy('publicauth')) {
26
+ console.error('The publicauth service is unhealthy, so an API token cannot be created');
27
+ return;
28
+ }
29
+ if (gatewayAccountID === undefined) {
30
+ console.log('No gateway_account_id provided, creating service and gateway account');
31
+ if (await app_client_js_1.default.isUnhealthy('adminusers')) {
32
+ console.error('The adminusers service is unhealthy, so an API token cannot be created');
33
+ return;
34
+ }
35
+ if (await app_client_js_1.default.isUnhealthy('connector')) {
36
+ console.error('The connector service is unhealthy, so an API token cannot be created');
37
+ return;
38
+ }
39
+ const serviceExternalID = await app_client_js_1.default.createService();
40
+ if (serviceExternalID === undefined) {
41
+ console.error('Service creation failed');
42
+ return;
43
+ }
44
+ const account = await app_client_js_1.default.createAccountInServiceWithEmailCollectionMode(serviceExternalID, 'MANDATORY');
45
+ if (account === undefined) {
46
+ console.error('Failed to create a fully set up account');
47
+ return;
48
+ }
49
+ gatewayAccountID = account.gateway_account_id;
50
+ }
51
+ const token = await app_client_js_1.default.createToken(gatewayAccountID);
52
+ if (token === undefined) {
53
+ console.error('Failed to create an API token');
54
+ return;
55
+ }
56
+ copyToClipboard(token);
57
+ console.log(`📋 API token “${token}” copied to clipboard`);
58
+ }
59
+ exports.default = tokenHandler;
60
+ function copyToClipboard(token) {
61
+ const proc = (0, node_child_process_1.spawn)('pbcopy');
62
+ proc.stdin.write(token);
63
+ proc.stdin.end();
64
+ }
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ENVIRONMENT_OVERRIDES_PATH = exports.DOCKER_COMPOSE_SERVICES_CONFIG_PATH = exports.DOCKER_COMPOSE_RENDERED_TEMPALTES_PATH = void 0;
6
+ exports.upCommandHandler = exports.handler = exports.builder = exports.desc = exports.command = exports.ENVIRONMENT_OVERRIDES_PATH = exports.DOCKER_COMPOSE_SERVICES_CONFIG_PATH = exports.DOCKER_COMPOSE_RENDERED_TEMPLATES_PATH = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const docker_compose_controller_js_1 = __importDefault(require("../docker_compose_controller.js"));
9
9
  const configs_js_1 = require("../../../util/configs.js");
@@ -11,28 +11,98 @@ const pay_local_cluster_js_1 = require("../config/pay_local_cluster.js");
11
11
  const renderer_js_1 = require("../config/renderer.js");
12
12
  const last_up_record_js_1 = require("../config/last_up_record.js");
13
13
  const default_config_setup_js_1 = require("../config/default_config_setup.js");
14
- exports.DOCKER_COMPOSE_RENDERED_TEMPALTES_PATH = path_1.default.join('local', 'docker-compose', 'rendered-templates');
14
+ const standardContent_1 = require("../../../core/standardContent");
15
+ exports.DOCKER_COMPOSE_RENDERED_TEMPLATES_PATH = path_1.default.join('local', 'docker-compose', 'rendered-templates');
15
16
  exports.DOCKER_COMPOSE_SERVICES_CONFIG_PATH = path_1.default.join('local', 'docker-compose', 'default-configs-DO-NOT-EDIT');
16
17
  exports.ENVIRONMENT_OVERRIDES_PATH = path_1.default.join('local', 'environment-overrides');
18
+ exports.command = ['up', 'launch'];
19
+ exports.desc = 'Launch a predefined cluster, or a user specified list of apps.';
20
+ const builder = (yargs) => {
21
+ return yargs
22
+ .usage(`$0 local up | launch [--cluster <cluster>] [--local <app>] [--proxy] [--apps] [--rebuild] [--with-egress-proxy]\n\n${exports.desc}\n\nSpecify a list of apps that should use your locally checked out code using --local`)
23
+ .option('cluster', {
24
+ type: 'string',
25
+ choices: pay_local_cluster_js_1.CLUSTERS,
26
+ default: 'all',
27
+ description: 'cluster'
28
+ })
29
+ .option('apps', {
30
+ type: 'array',
31
+ default: [],
32
+ description: ''
33
+ })
34
+ .option('local', {
35
+ type: 'array',
36
+ default: [],
37
+ description: ''
38
+ })
39
+ .option('proxy', {
40
+ type: 'boolean',
41
+ default: false,
42
+ description: ''
43
+ })
44
+ .option('with-egress-proxy', {
45
+ type: 'boolean',
46
+ default: false,
47
+ description: ''
48
+ })
49
+ .option('rebuild', {
50
+ type: 'boolean',
51
+ default: true,
52
+ description: ''
53
+ })
54
+ .option('pull', {
55
+ type: 'boolean',
56
+ default: true,
57
+ description: ''
58
+ })
59
+ .option('mount-local-node-apps', {
60
+ type: 'boolean',
61
+ default: false,
62
+ description: ''
63
+ })
64
+ .option('mount-pay-js-commons', {
65
+ type: 'boolean',
66
+ default: false,
67
+ description: 'If mount local node apps is also specified this will mount pay-js-commons into /pay-js-commons in the node containers'
68
+ });
69
+ };
70
+ exports.builder = builder;
71
+ exports.handler = upCommandHandler;
72
+ async function upCommandHandler(argv) {
73
+ await (0, standardContent_1.showHeader)();
74
+ const upOptions = {
75
+ cluster: argv.cluster,
76
+ proxy: argv.proxy,
77
+ withEgressProxy: argv.withEgressProxy,
78
+ apps: argv.apps,
79
+ local: argv.local,
80
+ rebuild: argv.rebuild,
81
+ pull: argv.pull,
82
+ mountLocalNodeApps: argv.mountLocalNodeApps,
83
+ mountPayJSCommons: argv.mountPayJsCommons
84
+ };
85
+ await UpHandler(upOptions, false);
86
+ }
87
+ exports.upCommandHandler = upCommandHandler;
17
88
  async function UpHandler(options, onlyWriteConfig = false) {
18
89
  const workspace = (0, configs_js_1.workspaceEnvVar)();
19
- const renderedTemplatesPath = (0, configs_js_1.ensureConfigDirectory)(exports.DOCKER_COMPOSE_RENDERED_TEMPALTES_PATH);
90
+ const renderedTemplatesPath = (0, configs_js_1.ensureConfigDirectory)(exports.DOCKER_COMPOSE_RENDERED_TEMPLATES_PATH);
20
91
  const composeServicesConfigPath = (0, configs_js_1.ensureConfigDirectory)(exports.DOCKER_COMPOSE_SERVICES_CONFIG_PATH);
21
92
  const environmentOverridesPath = (0, configs_js_1.ensureConfigDirectory)(exports.ENVIRONMENT_OVERRIDES_PATH);
22
93
  (0, default_config_setup_js_1.copyDefaultConfigs)(composeServicesConfigPath);
23
- const args = options instanceof Array ? parseArguments(options) : options;
24
- const clusterConfig = (0, pay_local_cluster_js_1.loadClusterConfig)(args, workspace, composeServicesConfigPath, environmentOverridesPath);
94
+ const clusterConfig = (0, pay_local_cluster_js_1.loadClusterConfig)(options, workspace, composeServicesConfigPath, environmentOverridesPath);
25
95
  const renderedTemplatePath = (0, renderer_js_1.renderDockerCompose)(clusterConfig, renderedTemplatesPath);
26
96
  console.log(`docker-compose yaml written to ${renderedTemplatePath}`);
27
97
  (0, last_up_record_js_1.recordUp)(renderedTemplatesPath, clusterConfig);
28
98
  if (onlyWriteConfig) {
29
99
  return renderedTemplatePath;
30
100
  }
31
- if (args.pull) {
101
+ if (options.pull) {
32
102
  console.log(`\nPulling containers for cluster ${clusterConfig.name}`);
33
103
  docker_compose_controller_js_1.default.pull(renderedTemplatePath);
34
104
  }
35
- if (args.local.length > 0 && args.rebuild) {
105
+ if (options.local.length > 0 && options.rebuild) {
36
106
  console.log(`\nBuilding all local apps for cluster ${clusterConfig.name}`);
37
107
  docker_compose_controller_js_1.default.build(renderedTemplatePath);
38
108
  }
@@ -41,15 +111,3 @@ async function UpHandler(options, onlyWriteConfig = false) {
41
111
  return renderedTemplatePath;
42
112
  }
43
113
  exports.default = UpHandler;
44
- function parseArguments(_options) {
45
- return {
46
- cluster: 'card',
47
- apps: [],
48
- local: ['cardid', 'frontend'],
49
- proxy: true,
50
- with_egress_proxy: false,
51
- rebuild: true,
52
- pull: true,
53
- mount_local_node_apps: false
54
- };
55
- }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handler = exports.builder = exports.desc = exports.command = void 0;
7
+ const node_child_process_1 = require("node:child_process");
8
+ const app_client_js_1 = __importDefault(require("../app_client/app_client.js"));
9
+ const pay_local_cluster_js_1 = require("../config/pay_local_cluster.js");
10
+ const standardContent_1 = require("../../../core/standardContent");
11
+ exports.command = 'url <service>';
12
+ exports.desc = 'Copy base URL of local service to clipboard';
13
+ const builder = (yargs) => {
14
+ return yargs.positional('service', {
15
+ type: 'string',
16
+ description: 'service'
17
+ }).option('proxy', {
18
+ type: 'boolean',
19
+ default: false,
20
+ description: 'Something about proxy'
21
+ });
22
+ };
23
+ exports.builder = builder;
24
+ exports.handler = urlHandler;
25
+ async function urlHandler(argv) {
26
+ await (0, standardContent_1.showHeader)();
27
+ const service = argv.service;
28
+ const proxy = argv.service;
29
+ const servicesConfig = (0, pay_local_cluster_js_1.loadServicesConfig)();
30
+ if (!(service in servicesConfig)) {
31
+ console.error(`The service specified (${service}) was not defined in the service_config.yaml file`);
32
+ return;
33
+ }
34
+ const serviceConfig = servicesConfig[service];
35
+ const url = app_client_js_1.default.externalUrlFor(service, '/', proxy);
36
+ copyToClipboard(url);
37
+ if (await app_client_js_1.default.isHealthy(serviceConfig.name)) {
38
+ console.log(`📋 “${url}” copied to clipboard`);
39
+ }
40
+ else {
41
+ console.error(`❌ “${url}” copied to clipboard, however the app did not respond successfully to ${url}/healthcheck`);
42
+ }
43
+ }
44
+ exports.default = urlHandler;
45
+ function copyToClipboard(url) {
46
+ const proc = (0, node_child_process_1.spawn)('pbcopy');
47
+ proc.stdin.write(url);
48
+ proc.stdin.end();
49
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handler = exports.builder = exports.desc = exports.command = void 0;
7
+ const app_client_js_1 = __importDefault(require("../app_client/app_client.js"));
8
+ const totp_generator_1 = require("totp-generator");
9
+ const node_child_process_1 = require("node:child_process");
10
+ const standardContent_1 = require("../../../core/standardContent");
11
+ exports.command = 'user';
12
+ exports.desc = 'Create a local user';
13
+ const builder = (yargs) => {
14
+ return yargs
15
+ .usage(`$0 local user [--create-payments]\n\n${exports.desc}`)
16
+ .option('create-payments', {
17
+ type: 'boolean',
18
+ default: false,
19
+ description: 'Create payments'
20
+ });
21
+ };
22
+ exports.builder = builder;
23
+ exports.handler = userHandler;
24
+ async function userHandler(argv) {
25
+ await (0, standardContent_1.showHeader)();
26
+ const createPayments = argv.createPayments;
27
+ if (await app_client_js_1.default.isUnhealthy('adminusers')) {
28
+ console.error('The adminusers service is unhealthy, so a user cannot be created');
29
+ return;
30
+ }
31
+ if (await app_client_js_1.default.isUnhealthy('connector')) {
32
+ console.error('The connector service is unhealthy, so a user cannot be created');
33
+ return;
34
+ }
35
+ console.warn('Creating card gateway account and API token');
36
+ const serviceExternalID = await app_client_js_1.default.createService();
37
+ if (serviceExternalID === undefined) {
38
+ console.error('Service creation failed');
39
+ return;
40
+ }
41
+ const account = await app_client_js_1.default.createAccountInServiceWithEmailCollectionMode(serviceExternalID, 'MANDATORY');
42
+ if (account === undefined) {
43
+ console.error('Failed to create a fully set up account');
44
+ return;
45
+ }
46
+ const apiToken = await app_client_js_1.default.createToken(account.gateway_account_id);
47
+ if (apiToken === undefined) {
48
+ console.error('Failed to create an API token');
49
+ return;
50
+ }
51
+ if (createPayments !== undefined && createPayments) {
52
+ console.warn('💸 Creating 10 payments in card sandbox gateway account (each . is a success, each ! is a failure)');
53
+ let createPaymentResult;
54
+ for (let i = 0; i < 10; i++) {
55
+ createPaymentResult = await app_client_js_1.default.createPayment(apiToken);
56
+ if (createPaymentResult === undefined) {
57
+ process.stderr.write('!');
58
+ }
59
+ else {
60
+ process.stderr.write('.');
61
+ }
62
+ }
63
+ }
64
+ console.warn('🤓 Creating admin user for service');
65
+ const user = await app_client_js_1.default.createUser([account.gateway_account_id], 'admin');
66
+ if (user === undefined) {
67
+ console.error('Failed to create an admin user');
68
+ return;
69
+ }
70
+ console.warn('😎 Creating view-only user for service');
71
+ const viewOnlyUser = await app_client_js_1.default.createUser([account.gateway_account_id], 'view-only');
72
+ if (viewOnlyUser === undefined) {
73
+ console.error('Failed to create a view-only user, continuing anyway since the admin user was successfully created');
74
+ }
75
+ const { otp } = totp_generator_1.TOTP.generate(user.otp_key);
76
+ console.log(`📧 Email: ${user.email}`);
77
+ console.log(`🛂 Password: ${user.password}`);
78
+ console.log(`🔑 OTP key: ${user.otp_key}`);
79
+ console.log(`📱 OTP token: ${otp}`);
80
+ console.log(`💁 Service ID: ${serviceExternalID}`);
81
+ console.log(`💳 Card gateway account ID: ${account.external_id}`);
82
+ console.log(`🎫 Card API token: ${apiToken}`);
83
+ console.log();
84
+ let selfserviceUrl;
85
+ if (await app_client_js_1.default.isProxyHealthy('selfservice')) {
86
+ selfserviceUrl = app_client_js_1.default.externalUrlFor('selfservice', '/', true);
87
+ }
88
+ else {
89
+ selfserviceUrl = app_client_js_1.default.externalUrlFor('selfservice', '/', false);
90
+ }
91
+ copyToClipboard(user.email);
92
+ console.log(`📋 “${user.email}” copied to clipboard`);
93
+ console.log(`🌎 Opening selfservice (${selfserviceUrl}) browser`);
94
+ console.log();
95
+ (0, node_child_process_1.spawn)('open', [selfserviceUrl]);
96
+ }
97
+ exports.default = userHandler;
98
+ function copyToClipboard(email) {
99
+ const proc = (0, node_child_process_1.spawn)('pbcopy');
100
+ proc.stdin.write(email);
101
+ proc.stdin.end();
102
+ }
@@ -1,98 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const standardContent_js_1 = require("../core/standardContent.js");
7
- const legacy_1 = __importDefault(require("../commands/legacy"));
8
- const otp_js_1 = __importDefault(require("./local/subcommands/otp.js"));
9
- const up_js_1 = __importDefault(require("./local/subcommands/up.js"));
10
- const down_js_1 = __importDefault(require("./local/subcommands/down.js"));
11
- const nuke_js_1 = __importDefault(require("./local/subcommands/nuke.js"));
12
- const restart_js_1 = __importDefault(require("./local/subcommands/restart.js"));
13
- const SUBCOMMANDS_NOT_YET_IMPLEMENTED = [
14
- 'account',
15
- 'browse',
16
- 'db',
17
- 'payment',
18
- 'paymentlink',
19
- 'token',
20
- 'url',
21
- 'user'
22
- ];
23
- var LocalCommand;
24
- (function (LocalCommand) {
25
- LocalCommand["OTP"] = "otp";
26
- LocalCommand["Up"] = "up";
27
- LocalCommand["Launch"] = "launch";
28
- LocalCommand["Down"] = "down";
29
- LocalCommand["Restart"] = "restart";
30
- LocalCommand["Nuke"] = "nuke";
31
- LocalCommand["Help"] = "help";
32
- LocalCommand["Unknown"] = "Unknown";
33
- })(LocalCommand || (LocalCommand = {}));
34
- async function localHandler(options) {
35
- // Not everything is implemented yet. Lets hand off to the legacy handler for unimplemented
36
- // subcommands
37
- if (options.arguments.length > 0 && SUBCOMMANDS_NOT_YET_IMPLEMENTED.includes(options.arguments[0])) {
38
- options.commandName = 'local';
39
- await (0, legacy_1.default)(options);
40
- return;
41
- }
42
- await (0, standardContent_js_1.showHeader)();
43
- const { subcommand, subcommandOptions } = parseArguments(options);
44
- switch (subcommand) {
45
- case LocalCommand.OTP: {
46
- await (0, otp_js_1.default)(subcommandOptions);
47
- break;
48
- }
49
- case LocalCommand.Up: {
50
- await (0, up_js_1.default)(subcommandOptions);
51
- break;
52
- }
53
- case LocalCommand.Launch: {
54
- await (0, up_js_1.default)(subcommandOptions);
55
- break;
56
- }
57
- case LocalCommand.Down: {
58
- await (0, down_js_1.default)(subcommandOptions);
59
- break;
60
- }
61
- case LocalCommand.Restart: {
62
- await (0, restart_js_1.default)(subcommandOptions);
63
- break;
64
- }
65
- case LocalCommand.Nuke: {
66
- await (0, nuke_js_1.default)();
67
- break;
68
- }
69
- case LocalCommand.Help:
70
- case LocalCommand.Unknown: {
71
- help();
72
- break;
73
- }
74
- default: {
75
- help();
76
- break;
77
- }
78
- }
79
- }
80
- exports.default = localHandler;
81
- // TODO: Replace this with yargs
82
- function parseArguments(options) {
83
- const subcommandOptions = options.arguments;
84
- const subcommand = subcommandOptions.shift();
85
- switch (subcommand) {
86
- case LocalCommand.OTP: return { subcommand, subcommandOptions };
87
- case LocalCommand.Up: return { subcommand, subcommandOptions };
88
- case LocalCommand.Launch: return { subcommand, subcommandOptions };
89
- case LocalCommand.Down: return { subcommand, subcommandOptions };
90
- case LocalCommand.Restart: return { subcommand, subcommandOptions };
91
- case LocalCommand.Nuke: return { subcommand, subcommandOptions };
92
- case LocalCommand.Help: return { subcommand, subcommandOptions };
93
- default: return { subcommand: LocalCommand.Unknown, subcommandOptions };
94
- }
95
- }
96
- function help() {
97
- console.error('USAGE FOLLOWS');
98
- }
3
+ exports.builder = exports.desc = exports.command = void 0;
4
+ exports.command = 'local';
5
+ exports.desc = 'Local pay for local people';
6
+ const builder = (yargs) => {
7
+ return yargs
8
+ .commandDir('local/subcommands')
9
+ .demandCommand();
10
+ };
11
+ exports.builder = builder;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.logTunnelCommands = void 0;
6
+ exports.handler = exports.builder = exports.desc = exports.command = void 0;
7
7
  const standardContent_js_1 = require("../core/standardContent.js");
8
8
  const client_ec2_1 = require("@aws-sdk/client-ec2");
9
9
  const client_ecs_1 = require("@aws-sdk/client-ecs");
@@ -24,12 +24,19 @@ const FORMAT = {
24
24
  ul: '\x1b[4m',
25
25
  ulstop: '\x1b[24m'
26
26
  };
27
- function logTunnelCommands() {
28
- console.log(`Commands:
29
- pay tunnel <ENVIRONMENT> <APP-NAME> # Open tunnel to application <APP-NAME> database in specified environment <ENVIRONMENT>
30
- pay tunnel help # Describe tunnel command`);
31
- }
32
- exports.logTunnelCommands = logTunnelCommands;
27
+ exports.command = 'tunnel <environment> <application>';
28
+ exports.desc = 'Open a tunnel to an app database in a given environment';
29
+ const builder = (yargs) => {
30
+ return yargs.positional('environment', {
31
+ describe: 'The environment to open the tunnel to',
32
+ choices: constants_js_1.ENVIRONMENTS
33
+ }).positional('application', {
34
+ describe: 'The application to connect to',
35
+ choices: constants_js_1.APPLICATIONS
36
+ });
37
+ };
38
+ exports.builder = builder;
39
+ exports.handler = tunnelHandler;
33
40
  async function readInputForReadOrWriteDBAccess() {
34
41
  const rl = promises_1.default.createInterface({
35
42
  input: process.stdin,
@@ -54,9 +61,10 @@ async function readInputForReadOrWriteDBAccess() {
54
61
  process.exit(1);
55
62
  }
56
63
  }
57
- async function tunnelHandler(options) {
64
+ async function tunnelHandler(argv) {
58
65
  await (0, standardContent_js_1.showHeader)();
59
- const { environment, application } = parseArguments(options);
66
+ const environment = argv.environment;
67
+ const application = argv.application;
60
68
  console.log(`Opening a database tunnel to ${environment} ${application}`);
61
69
  ec2 = new client_ec2_1.EC2Client();
62
70
  ecs = new client_ecs_1.ECSClient();
@@ -84,25 +92,6 @@ async function tunnelHandler(options) {
84
92
  }
85
93
  }
86
94
  exports.default = tunnelHandler;
87
- function parseArguments(options) {
88
- if (options.arguments.length !== 2 || options.arguments[0] === 'help') {
89
- logTunnelCommands();
90
- process.exit(0);
91
- }
92
- const environment = options.arguments[0];
93
- const application = options.arguments[1];
94
- if (!constants_js_1.APPLICATIONS.includes(application)) {
95
- printError(`Invalid application: "${application}". Must be one of ${constants_js_1.APPLICATIONS.join(', ')}`);
96
- process.exit(2);
97
- }
98
- if (!constants_js_1.ENVIRONMENTS.includes(environment)) {
99
- printError(`Invalid environment: "${environment}". Must be one of ${constants_js_1.ENVIRONMENTS.join(', ')}`);
100
- process.exit(2);
101
- }
102
- return {
103
- environment, application
104
- };
105
- }
106
95
  async function waitForExit() {
107
96
  const prompt = "\nTo shutdown bastion task and close tunnel type 'exit' or 'Ctrl-C'\n";
108
97
  const rl = readline_1.default.createInterface({
@@ -3,81 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const standardContent_js_1 = require("./standardContent.js");
7
- const browse_js_1 = __importDefault(require("../commands/browse.js"));
8
- const demo_js_1 = __importDefault(require("../commands/demo.js"));
9
- const legacy_1 = __importDefault(require("../commands/legacy"));
10
- const local_js_1 = __importDefault(require("../commands/local.js"));
11
- const help_1 = __importDefault(require("../commands/help"));
12
- const tunnel_js_1 = __importDefault(require("../commands/tunnel.js"));
13
6
  const package_json_1 = __importDefault(require("../../package.json"));
14
7
  const semver_1 = __importDefault(require("semver"));
15
- const handlers = new Map();
16
- handlers.set('browse', {
17
- handler: browse_js_1.default
18
- });
19
- handlers.set('tunnel', {
20
- handler: tunnel_js_1.default
21
- });
22
- handlers.set('legacy', {
23
- handler: legacy_1.default
24
- });
25
- handlers.set('doctor', {
26
- handler: legacy_1.default
27
- });
28
- handlers.set('help', {
29
- handler: help_1.default
30
- });
31
- handlers.set('local', {
32
- handler: legacy_1.default
33
- });
34
- handlers.set('localx', {
35
- handler: local_js_1.default
36
- });
37
- handlers.set('schema', {
38
- handler: legacy_1.default
39
- });
40
- handlers.set('secrets', {
41
- handler: legacy_1.default
42
- });
43
- handlers.set('demo', {
44
- handler: demo_js_1.default
45
- });
8
+ const yargs_1 = __importDefault(require("yargs/yargs"));
9
+ const helpers_1 = require("yargs/helpers");
46
10
  async function runCommand() {
47
- const command = process.argv[2];
48
11
  await checkVersion();
49
- await showUsageIfNoCommand(command);
50
- const commandDetails = await getCommandDetails(command);
51
- if (commandDetails === undefined) {
52
- console.error(`No command found for [${command}]`);
53
- process.exit(10);
54
- }
55
- await runHandler(command, commandDetails);
12
+ const yargsInstance = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv));
13
+ await yargsInstance
14
+ .commandDir('../commands', { exclude: /.*\.spec\..*/ })
15
+ .demandCommand()
16
+ .usage('pay <command>\n\nProvides usefull commands for managing and developing the GOV.UK Pay platform. Use `pay <command> help` to find more information on an individual pay command.')
17
+ .strict()
18
+ .help()
19
+ .wrap(yargsInstance.terminalWidth())
20
+ .parse();
56
21
  }
57
22
  exports.default = runCommand;
58
- async function getCommandDetails(commandName) {
59
- return handlers.get(commandName);
60
- }
61
- async function showUsageIfNoCommand(commandName) {
62
- if (commandName === undefined || commandName.trim() === '') {
63
- await (0, standardContent_js_1.showHeader)();
64
- await (0, standardContent_js_1.showUsage)();
65
- process.exit(2);
66
- }
67
- }
68
- async function runHandler(commandName, commandHandler) {
69
- try {
70
- await commandHandler.handler({
71
- commandName,
72
- arguments: process.argv.slice(3)
73
- });
74
- }
75
- catch (e) {
76
- console.error(`Failed to run command [${commandName}]`);
77
- console.error(e);
78
- process.exit(12);
79
- }
80
- }
81
23
  async function checkVersion() {
82
24
  try {
83
25
  const { version: currentVersion, engines: { node: requiredNodeVersion } } = package_json_1.default;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.showUsage = exports.showHeader = void 0;
26
+ exports.showHeader = void 0;
27
27
  const fsp = __importStar(require("fs/promises"));
28
28
  const path = __importStar(require("path"));
29
29
  const constants_js_1 = require("./constants.js");
@@ -31,7 +31,3 @@ async function showHeader() {
31
31
  console.log(await fsp.readFile(path.join(constants_js_1.rootDir, 'resources/header.txt'), 'utf8'));
32
32
  }
33
33
  exports.showHeader = showHeader;
34
- async function showUsage() {
35
- console.log(await fsp.readFile(path.join(constants_js_1.rootDir, 'resources/usageDetails.txt'), 'utf8'));
36
- }
37
- exports.showUsage = showUsage;
@@ -1,9 +0,0 @@
1
- Commands:
2
- pay browse # Opens web browser link to useful links
3
- pay doctor # Attempts to initialise or fix the Pay CLI
4
- pay help [COMMAND] # Describe available commands or one specific ...
5
- pay local # Sets up local Pay development environment
6
- pay localx # EXPERIMENTAL: Nodejs replacement of `pay local`
7
- pay schema # Generates web based database diagrams and me...
8
- pay secrets # Manage secrets in and between environments
9
- pay tunnel # Open tunnel to application database
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const legacy_1 = require("./legacy");
4
- const standardContent_1 = require("../core/standardContent");
5
- const browse_1 = require("./browse");
6
- async function helpHandler(options) {
7
- if (options.arguments[0] === 'browse') {
8
- await (0, standardContent_1.showHeader)();
9
- (0, browse_1.logBrowseCommands)();
10
- }
11
- else {
12
- await (0, legacy_1.proxyHandlerOptionsToLegacyCli)(options);
13
- }
14
- }
15
- exports.default = helpHandler;