2022-02-01 02:31:20 +00:00
|
|
|
import { Command } from 'commander-ts';
|
|
|
|
|
import { BuildParameters, CloudRunner, ImageTag, Input } from '..';
|
|
|
|
|
import * as core from '@actions/core';
|
|
|
|
|
import { ActionYamlReader } from '../input-readers/action-yaml';
|
|
|
|
|
import CloudRunnerLogger from '../cloud-runner/services/cloud-runner-logger';
|
2022-04-07 17:52:12 +00:00
|
|
|
import { CliFunction, GetAllCliModes, GetCliFunctions } from './cli-decorator';
|
2022-04-04 21:44:44 +00:00
|
|
|
import CloudRunnerQueryOverride from '../cloud-runner/services/cloud-runner-query-override';
|
2022-02-01 02:31:20 +00:00
|
|
|
|
|
|
|
|
export class CLI {
|
2022-04-04 22:09:26 +00:00
|
|
|
public static options;
|
|
|
|
|
static get cliMode() {
|
|
|
|
|
return CLI.options !== undefined && CLI.options.mode !== undefined && CLI.options.mode !== '';
|
|
|
|
|
}
|
2022-04-05 02:58:57 +00:00
|
|
|
public static query(key, alternativeKey) {
|
|
|
|
|
if (CLI.options && CLI.options[key] !== undefined) {
|
|
|
|
|
return CLI.options[key];
|
|
|
|
|
}
|
|
|
|
|
if (CLI.options && alternativeKey && CLI.options[alternativeKey] !== undefined) {
|
|
|
|
|
return CLI.options[alternativeKey];
|
|
|
|
|
}
|
|
|
|
|
return;
|
2022-04-04 22:09:26 +00:00
|
|
|
}
|
2022-02-01 02:31:20 +00:00
|
|
|
|
2022-04-02 23:12:35 +00:00
|
|
|
public static InitCliMode() {
|
2022-02-01 02:31:20 +00:00
|
|
|
const program = new Command();
|
|
|
|
|
program.version('0.0.1');
|
|
|
|
|
const properties = Object.getOwnPropertyNames(Input);
|
|
|
|
|
const actionYamlReader: ActionYamlReader = new ActionYamlReader();
|
|
|
|
|
for (const element of properties) {
|
|
|
|
|
program.option(`--${element} <${element}>`, actionYamlReader.GetActionYamlValue(element));
|
|
|
|
|
}
|
|
|
|
|
program.option(
|
|
|
|
|
'-m, --mode <mode>',
|
|
|
|
|
GetAllCliModes()
|
|
|
|
|
.map((x) => `${x.key} (${x.description})`)
|
|
|
|
|
.join(` | `),
|
|
|
|
|
);
|
2022-04-04 22:09:26 +00:00
|
|
|
program.option('--populateOverride <populateOverride>', 'should use override query to pull input false by default');
|
2022-04-04 21:44:44 +00:00
|
|
|
program.option('--cachePushFrom <cachePushFrom>', 'cache push from source folder');
|
|
|
|
|
program.option('--cachePushTo <cachePushTo>', 'cache push to caching folder');
|
|
|
|
|
program.option('--artifactName <artifactName>', 'caching artifact name');
|
2022-02-01 02:31:20 +00:00
|
|
|
program.parse(process.argv);
|
2022-04-02 23:12:35 +00:00
|
|
|
CLI.options = program.opts();
|
2022-04-04 22:09:26 +00:00
|
|
|
return CLI.cliMode;
|
2022-04-02 23:12:35 +00:00
|
|
|
}
|
2022-02-01 02:31:20 +00:00
|
|
|
|
2022-04-02 23:41:12 +00:00
|
|
|
static async RunCli(): Promise<void> {
|
|
|
|
|
Input.githubInputEnabled = false;
|
2022-04-04 22:09:26 +00:00
|
|
|
if (CLI.options['populateOverride'] === `true`) {
|
2022-04-04 21:44:44 +00:00
|
|
|
await CloudRunnerQueryOverride.PopulateQueryOverrideInput();
|
2022-04-04 21:05:46 +00:00
|
|
|
}
|
2022-04-02 23:41:12 +00:00
|
|
|
CLI.logInput();
|
|
|
|
|
const results = GetCliFunctions(CLI.options.mode);
|
|
|
|
|
CloudRunnerLogger.log(`Entrypoint: ${results.key}`);
|
|
|
|
|
CLI.options.versioning = 'None';
|
|
|
|
|
return await results.target[results.propertyKey]();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-07 00:45:15 +00:00
|
|
|
@CliFunction(`print-input`, `prints all input`)
|
2022-04-02 23:12:35 +00:00
|
|
|
private static logInput() {
|
|
|
|
|
core.info(`\n`);
|
|
|
|
|
core.info(`INPUT:`);
|
|
|
|
|
const properties = Object.getOwnPropertyNames(Input);
|
|
|
|
|
for (const element of properties) {
|
|
|
|
|
if (
|
|
|
|
|
Input[element] !== undefined &&
|
|
|
|
|
Input[element] !== '' &&
|
|
|
|
|
typeof Input[element] !== `function` &&
|
|
|
|
|
element !== 'length' &&
|
|
|
|
|
element !== 'cliOptions' &&
|
|
|
|
|
element !== 'prototype'
|
|
|
|
|
) {
|
|
|
|
|
core.info(`${element} ${Input[element]}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
core.info(`\n`);
|
2022-02-01 02:31:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@CliFunction(`cli`, `runs a cloud runner build`)
|
|
|
|
|
public static async CLIBuild(): Promise<string> {
|
|
|
|
|
const buildParameter = await BuildParameters.create();
|
|
|
|
|
const baseImage = new ImageTag(buildParameter);
|
|
|
|
|
return await CloudRunner.run(buildParameter, baseImage.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|