unity-builder/src/model/cli/cli.ts

50 lines
1.5 KiB
TypeScript
Raw Normal View History

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-25 19:35:09 +00:00
export class CLI {
static async RunCli(options: any) {
2021-12-29 14:36:55 +00:00
core.info(`Entrypoint: ${options.mode}`);
2021-12-25 20:14:55 +00:00
2021-12-25 19:35:09 +00:00
if (options.mode === 'remote-cli') {
await RemoteClient.Run(options);
} else {
options.versioning = 'None';
Input.cliOptions = options;
const buildParameter = await BuildParameters.create();
const baseImage = new ImageTag(buildParameter);
await CloudRunner.run(buildParameter, baseImage.toString());
}
}
static isCliMode(options: any) {
switch (options.mode) {
case 'cli':
case 'remote-cli':
return true;
default:
return false;
}
}
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:`);
for (const element of properties) {
2021-12-25 20:14:55 +00:00
// TODO pull description from action.yml
2021-12-25 19:35:09 +00:00
program.option(`--${element} <${element}>`, 'default description');
if (Input[element] !== undefined && Input[element] !== '') {
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();
}
}