mirror of
https://github.com/Lydanne/spaceflow.git
synced 2026-03-11 19:52:45 +08:00
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { Command, CommandRunner, Option } from "nest-commander";
|
|
import { t } from "@spaceflow/core";
|
|
import { CiShellService } from "./ci-shell.service";
|
|
|
|
export interface CiShellOptions {
|
|
dryRun: boolean;
|
|
}
|
|
|
|
@Command({
|
|
name: "ci-shell",
|
|
description: t("ci-shell:description"),
|
|
arguments: "<command>",
|
|
argsDescription: {
|
|
command: t("ci-shell:argsDescription.command"),
|
|
},
|
|
})
|
|
export class CiShellCommand extends CommandRunner {
|
|
constructor(protected readonly ciShellService: CiShellService) {
|
|
super();
|
|
}
|
|
|
|
async run(passedParams: string[], options: CiShellOptions): Promise<void> {
|
|
const command = passedParams.join(" ");
|
|
|
|
if (!command) {
|
|
console.error(t("ci-shell:noCommand"));
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`DRY-RUN mode: ${options.dryRun ? "enabled" : "disabled"}`);
|
|
|
|
try {
|
|
const context = this.ciShellService.getContextFromEnv(options);
|
|
await this.ciShellService.execute(context, command);
|
|
} catch (error) {
|
|
console.error(
|
|
t("common.executionFailed", { error: error instanceof Error ? error.message : error }),
|
|
);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
@Option({
|
|
flags: "-d, --dry-run",
|
|
description: t("common.options.dryRun"),
|
|
})
|
|
parseDryRun(val: boolean): boolean {
|
|
return val;
|
|
}
|
|
}
|