2021-12-25 19:35:09 +00:00
|
|
|
import { Command } from 'commander-ts';
|
|
|
|
|
import { BuildParameters, CloudRunner, ImageTag, Input } from '..';
|
|
|
|
|
import * as core from '@actions/core';
|
2021-12-25 20:05:17 +00:00
|
|
|
import { RemoteClient } from './remote-client';
|
2021-12-29 15:15:39 +00:00
|
|
|
import { ActionYamlReader } from '../input-readers/action-yaml';
|
2021-12-25 19:35:09 +00:00
|
|
|
export class CLI {
|
2021-12-30 03:01:38 +00:00
|
|
|
static async RunCli(options: any): Promise<void> {
|
2021-12-29 14:36:55 +00:00
|
|
|
core.info(`Entrypoint: ${options.mode}`);
|
2021-12-25 20:14:55 +00:00
|
|
|
|
2021-12-31 02:08:16 +00:00
|
|
|
const container = new Array();
|
|
|
|
|
container.push(
|
|
|
|
|
{
|
|
|
|
|
key: `remote-cli`,
|
|
|
|
|
asyncFunc: RemoteClient.Run,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: `cli`,
|
|
|
|
|
asyncFunc: async () => {
|
|
|
|
|
options.versioning = 'None';
|
|
|
|
|
Input.cliOptions = options;
|
|
|
|
|
const buildParameter = await BuildParameters.create();
|
|
|
|
|
const baseImage = new ImageTag(buildParameter);
|
|
|
|
|
return await CloudRunner.run(buildParameter, baseImage.toString());
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
const results = container.filter((x) => x.key === options.mode);
|
|
|
|
|
|
|
|
|
|
if (results.length === 0) {
|
|
|
|
|
throw new Error('no CLI mode found');
|
2021-12-25 19:35:09 +00:00
|
|
|
}
|
2021-12-31 02:08:16 +00:00
|
|
|
|
|
|
|
|
return await results[0].asyncFunc();
|
2021-12-25 19:35:09 +00:00
|
|
|
}
|
|
|
|
|
static isCliMode(options: any) {
|
2021-12-31 02:08:16 +00:00
|
|
|
return options.mode !== undefined && options.mode === '';
|
2021-12-25 19:35:09 +00:00
|
|
|
}
|
2021-12-31 02:08:16 +00:00
|
|
|
|
2021-12-25 19:35:09 +00:00
|
|
|
public static SetupCli() {
|
|
|
|
|
Input.githubEnabled = false;
|
|
|
|
|
const program = new Command();
|
|
|
|
|
program.version('0.0.1');
|
|
|
|
|
const properties = Object.getOwnPropertyNames(Input);
|
2021-12-29 14:35:13 +00:00
|
|
|
core.info(`\n`);
|
2021-12-25 19:35:09 +00:00
|
|
|
core.info(`INPUT:`);
|
2021-12-29 15:53:44 +00:00
|
|
|
const actionYamlReader: ActionYamlReader = new ActionYamlReader();
|
2021-12-25 19:35:09 +00:00
|
|
|
for (const element of properties) {
|
2021-12-29 15:53:44 +00:00
|
|
|
program.option(`--${element} <${element}>`, actionYamlReader.GetActionYamlValue(element));
|
2021-12-30 01:56:48 +00:00
|
|
|
if (Input[element] !== undefined && Input[element] !== '' && typeof Input[element] !== `function`) {
|
2021-12-25 19:35:09 +00:00
|
|
|
core.info(`${element} ${Input[element]}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-29 14:35:13 +00:00
|
|
|
core.info(`\n`);
|
2021-12-25 19:35:09 +00:00
|
|
|
program.option('-m, --mode <mode>', 'cli or default');
|
|
|
|
|
program.parse(process.argv);
|
|
|
|
|
|
|
|
|
|
return program.opts();
|
|
|
|
|
}
|
|
|
|
|
}
|