Skip to content

Commit

Permalink
fix: fix help command
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 25, 2022
1 parent 7b9501e commit 5b2c8e6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/apm-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ Run \`apm help <command>\` to see the more details about a specific command.\
return options
}

function showHelp(options: CliOptions, cmd: Command & { help: () => string }) {
function showHelp(options: CliOptions, cmd?: Command & { help: () => string }) {
if (options == null) {
return
}

let help = typeof options.help !== "function" ? cmd.help() /* mri */ : options.help() /* yargs */
let help = typeof options.help !== "function" ? cmd?.help() /* mri */ : options.help() /* yargs */
if (help.indexOf("Options:") >= 0) {
help += "\n Prefix an option with `no-` to set it to false such as --no-color to disable"
help += "\n colored output."
Expand Down Expand Up @@ -327,7 +327,14 @@ export function run(args: string[], callback: RunCallback) {
} else if (command) {
if (command === "help") {
if ((Command = commands[options.commandArgs]?.())) {
showHelp(new Command().parseOptions?.(options.commandArgs))
const cmd = new Command()
if (typeof cmd.help === "function") {
// converted to mri
showHelp(cmd.parseOptions?.(args), cmd)
} else {
// yargs
showHelp(cmd.parseOptions?.(options.commandArgs), cmd)
}
} else {
showHelp(options)
}
Expand Down

0 comments on commit 5b2c8e6

Please sign in to comment.