()
| 72 | } |
| 73 | |
| 74 | export function buildProgram(){ |
| 75 | |
| 76 | const analyticsClient = AnalyticsManager.get() |
| 77 | const coreConfig = getCoreConfig() |
| 78 | const program = new Command() |
| 79 | |
| 80 | program |
| 81 | .name('cloudypad') |
| 82 | .description('Cloudy Pad CLI to manage your own gaming instance in the Cloud.') |
| 83 | .option("-v, --verbose", |
| 84 | "Verbosity level (0: silly, 1: trace, 2: debug, 3: info, 4: warn, 5: error, 6: fatal). Alternatively, use CLOUDYPAD_LOG_LEVEL environment variable.", |
| 85 | (v) => { setLogVerbosity(Number.parseInt(v)) }) |
| 86 | .configureHelp({ showGlobalOptions: true}) |
| 87 | .version(CLOUDYPAD_VERSION) |
| 88 | |
| 89 | const createCmd = program |
| 90 | .command('create') |
| 91 | .description('Create a new instance. See subcommands for each provider options.') |
| 92 | |
| 93 | createCmd.addCommand(new AwsCliCommandGenerator().buildCreateCommand({ coreConfig: coreConfig })) |
| 94 | createCmd.addCommand(new AzureCliCommandGenerator().buildCreateCommand({ coreConfig: coreConfig })) |
| 95 | createCmd.addCommand(new GcpCliCommandGenerator().buildCreateCommand({ coreConfig: coreConfig })) |
| 96 | createCmd.addCommand(new PaperspaceCliCommandGenerator().buildCreateCommand({ coreConfig: coreConfig })) |
| 97 | createCmd.addCommand(new ScalewayCliCommandGenerator().buildCreateCommand({ coreConfig: coreConfig })) |
| 98 | createCmd.addCommand(new SshCliCommandGenerator().buildCreateCommand({ coreConfig: coreConfig })) |
| 99 | createCmd.addCommand(new DummyCliCommandGenerator().buildCreateCommand({ coreConfig: coreConfig }), { hidden: true }) |
| 100 | |
| 101 | const updateCmd = program |
| 102 | .command('update') |
| 103 | .description('Update an existing instance. See subcommands for each provider options.') |
| 104 | |
| 105 | updateCmd.addCommand(new AwsCliCommandGenerator().buildUpdateCommand({ coreConfig: coreConfig })) |
| 106 | updateCmd.addCommand(new AzureCliCommandGenerator().buildUpdateCommand({ coreConfig: coreConfig })) |
| 107 | updateCmd.addCommand(new GcpCliCommandGenerator().buildUpdateCommand({ coreConfig: coreConfig })) |
| 108 | updateCmd.addCommand(new PaperspaceCliCommandGenerator().buildUpdateCommand({ coreConfig: coreConfig })) |
| 109 | updateCmd.addCommand(new ScalewayCliCommandGenerator().buildUpdateCommand({ coreConfig: coreConfig })) |
| 110 | updateCmd.addCommand(new SshCliCommandGenerator().buildUpdateCommand({ coreConfig: coreConfig })) |
| 111 | updateCmd.addCommand(new DummyCliCommandGenerator().buildUpdateCommand({ coreConfig: coreConfig }), { hidden: true }) |
| 112 | |
| 113 | program |
| 114 | .command('list') |
| 115 | .description('List all instances') |
| 116 | .option('--format <format>', 'Output format, one of [plain|json] ', 'plain') |
| 117 | .action(async (options) => { |
| 118 | try { |
| 119 | analyticsClient.sendEvent(RUN_COMMAND_LIST) |
| 120 | |
| 121 | const coreClient = buildCoreClient() |
| 122 | const instanceNames = await coreClient.getAllInstances(); |
| 123 | if (instanceNames.length === 0) { |
| 124 | console.info('No instances found.'); |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | const outputFormat = options.format |
| 129 | |
| 130 | if(outputFormat == 'json'){ |
| 131 | console.info(JSON.stringify(instanceNames)) |
no test coverage detected