Interface Command

Index

Properties

Methods

Properties

public name: string

The command name.

Methods

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

Register callback fn for the command.

Parameters

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

Returns

Command

public 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

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

Parameters

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

public 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

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

Prompts the user for a confirmation.

Parameters

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

public 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

public description(): string

Returns

string

public 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

public 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

public 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

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

Parameters

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

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

Parameters

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

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

Parameters

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

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

Parameters

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

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

Parameters

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

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

Parameters

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

public usage(usage: string): Command

Gets or sets the usage help string.

Parameters

  • usage: string

Returns

Command

public usage(): string

Returns

string

public version(version: string): Command

Sets the command version

Parameters

  • version: string

Returns

Command