Skip to content

Commit

Permalink
fix(commands): exit with code 0 when help command runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alnyli07 committed Jan 26, 2024
1 parent d24b9c6 commit 26a9a26
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/core/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,37 +163,37 @@ export const Commands: {
name: "branchId",
description: "Branch ID",
type: CommandParameterTypes.SELECT,
valueType: "string",
valueType: "uuid",
required: false,
params: [],
},
{
name: "commitId",
description: "Commit ID",
description: "Commit ID [Optional]",
type: CommandParameterTypes.SELECT,
valueType: "string",
valueType: "uuid",
required: false,
params: [],
},
{
name: "workflowId",
description: "Workflow ID",
type: CommandParameterTypes.SELECT,
valueType: "string",
valueType: "uuid",
required: false,
params: [],
},
{
name: "branch",
description: "Branch Name",
description: "Branch Name instead of 'branch ID'",
type: "string",
valueType: "string",
required: false,
params: [],
},
{
name: "workflow",
description: "Workflow Name",
description: "Workflow Name instead of 'workflow ID'",
type: "string",
valueType: "string",
required: false,
Expand Down
20 changes: 12 additions & 8 deletions src/program.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Command } from "commander";
import { readEnviromentConfigVariable } from "./config";
import { Commands } from "./core/commands";
import { configWriter } from "./core/writer";

const { createCommand } = require("commander");

export type ProgramCommand = { parent?: ProgramCommand, name: () => string; args: any; opts: () => { [key: string]: any } };
export type ProgramCommand = { parent?: ProgramCommand; name: () => string; args: any; opts: () => { [key: string]: any } };

export const createProgram = () => {
const program = createCommand();
Expand All @@ -16,7 +13,10 @@ export const createProgram = () => {
program.option("-o, --output <type>", "output type (json, plain)", "plain");

//Add config command with subcommands
const configCommand = program.command("config").description("View and edit Appcircle CLI properties").action(() => {});
const configCommand = program
.command("config")
.description("View and edit Appcircle CLI properties")
.action(() => {});
configCommand
.command("list")
.description("List Appcircle CLI properties for all configurations")
Expand Down Expand Up @@ -48,7 +48,7 @@ export const createProgram = () => {
.action(() => {});
configCommand.action(() => {});

Commands.filter(c => !c.ignore).forEach((command) => {
Commands.filter((c) => !c.ignore).forEach((command) => {
let comandPrg = program.command(command.command).description(command.description);
command.params
.filter((p) => !p.requriedForInteractiveMode)
Expand All @@ -60,11 +60,15 @@ export const createProgram = () => {
comandPrg.action(() => actionCb);
});
program.executeSubCommand = () => false;
program.exitOverride();

program.hook("preAction", (thisCommand: any, actionCommand: ProgramCommand) => {
//console.log(thisCommand.name(), thisCommand.args , actionCommand.parent?.name())
actionCb({
parent: { name: () => actionCommand.parent?.name() || '', args: () => actionCommand.parent?.args(), opts: () => ({...actionCommand.parent?.opts()}) },
parent: {
name: () => actionCommand.parent?.name() || "",
args: () => actionCommand.parent?.args(),
opts: () => ({ ...actionCommand.parent?.opts() }),
},
name: () => actionCommand.name(),
args: () => (Array.isArray(actionCommand.args) ? actionCommand.args : actionCommand.args()),
opts: () => ({ ...thisCommand.opts(), ...actionCommand.opts() }),
Expand Down

0 comments on commit 26a9a26

Please sign in to comment.