Dynamic module commander

Index

Interfaces

Functions

Functions

action(fn: (...args: any[]) => any): Command

Register callback fn for the command.

Parameters

  • fn: (...args: any[]) => any

Returns

Command

choose(options: Array<string>, callback: (idx: number) => any)

Prompt for password with str, mask char and callback fn(val). The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.

Parameters

  • options: Array<string>
  • callback: (idx: number) => any

choose(options: Array<any>, callback: (idx: number) => any)

Parameters

  • options: Array<any>
  • callback: (idx: number) => any

command(name: string): Command

Add command with the specified name. Returns a new instance of Command.

The .action() callback is invoked when the command name is specified via ARGV, and the remaining arguments are applied to the function for access.

When the name is "*" an un-matched command will be passed as the first arg, followed by the rest of ARGV remaining.

Parameters

  • name: string

    the name of the command. Pass "*" to trap un-matched commands.

Returns

Command

confirm(label: string, callback: (flag: boolean) => any)

Prompts the user for a confirmation.

Parameters

  • label: string
  • callback: (flag: boolean) => any

description(description: string): Command

Gets or sets the command description.

Parameters

  • description: string

    the new description for the command. When ommited this returns the current description, otherwise returns the current Command.

Returns

Command

description(): string

Returns

string

option(flags: string, description: string, coerceFn?: (value: string) => any, defaultValue?: any): Command

Define option with flags, description and optional coercion function and default value. The flags string should contain both the short and long flags separated by comma, a pipe or space. The following are all valid all will output this way when --help is used.

"-p, --pepper" "-p|--pepper" "-p --pepper"

Parameters

  • flags: string

    the option flags.

  • description: string

    the option description. The description is printed when "--help" is used.

  • coerceFn?: (value: string) => any optional

    (optional) specifies a callback function to coerce the option arg.

  • defaultValue?: any optional

    (optional) specifies a default value.

Returns

Command

parse(argv: Array<string>): Command

Parse the arguments array and invokes the commands passing the parsed options.

Parameters

  • argv: Array<string>

    the arguments array.

Returns

Command

password(label: string, mask: string, callback: (value: string) => any)

Prompt for password with a label, a optional mask char and callback function. The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.

Parameters

  • label: string
  • mask: string
  • callback: (value: string) => any

password(label: string, callback: (value: string) => any)

Parameters

  • label: string
  • callback: (value: string) => any

prompt(label: string, callback: (value: string) => any)

Parameters

  • label: string
  • callback: (value: string) => any

promptForDate(label: string, callback: (value: Date) => any)

Parameters

  • label: string
  • callback: (value: Date) => any

promptForNumber(label: string, callback: (value: number) => any)

Parameters

  • label: string
  • callback: (value: number) => any

promptMultiLine(label: string, callback: (value: string) => any)

Parameters

  • label: string
  • callback: (value: string) => any

promptSingleLine(label: string, callback: (value: string) => any)

Parameters

  • label: string
  • callback: (value: string) => any

usage(usage: string): Command

Gets or sets the usage help string.

Parameters

  • usage: string

Returns

Command

usage(): string

Returns

string

version(version: string): Command

Sets the command version

Parameters

  • version: string

Returns

Command