Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PargvCommand

Hierarchy

  • PargvCommand

Index

Constructors

constructor

Properties

_action

_action: ActionHandler

_aliases

_aliases: IMap<string>

_arguments

_arguments: string[] = []

_bools

_bools: string[] = []

_coercions

_coercions: IMap<CoerceHandler>

_completions

_completions: IMap<any[]>

Private _customUsage

_customUsage: boolean

_cwd

_cwd: string | boolean = false

_defaults

_defaults: IMap<any>

_demands

_demands: string[] = []

_describe

_describe: string

_describes

_describes: IMap<string>

_examples

_examples: [string, string][] = []

_extendAliases

_extendAliases: boolean

_extendArguments

_extendArguments: boolean

_extension

_extension: string = null

_external

_external: string = null

_maxArguments

_maxArguments: number

_maxOptions

_maxOptions: number

_minArguments

_minArguments: number

_minOptions

_minOptions: number

_name

_name: string

_options

_options: string[] = []

_pargv

_pargv: Pargv

_showHelp

_showHelp: boolean

_spawnAction

_spawnAction: SpawnActionHandler

_spawnOptions

_spawnOptions: SpawnOptions

_spreadArguments

_spreadArguments: boolean

_usage

_usage: string

_usages

_usages: IMap<string[]>

_variadic

_variadic: string

_whens

_whens: IMap<string>

Accessors

completion

  • get completion(): any
  • Completion : Adds the completion command for use within your app for generating completion script.

    Returns any

epilogue

Private error

  • get error(): any
  • Error : Handles error messages.

    Returns any

exec

  • get exec(): function

if

listen

  • get listen(): any
  • Listen : Parses arguments then executes command action if any.

    Returns any

max

  • get max(): object
  • Max : Gets methods for adding max commands or options.

    Returns object

    • commands: function
      • commands(count: number): this
      • Max Commands Sets maximum command count.

        Parameters

        • count: number

          the maximum number of commands.

        Returns this

    • options: function
      • options(count: number): this
      • Max Options Sets maximum option count.

        Parameters

        • count: number

          the maximum number of options.

        Returns this

min

  • get min(): object
  • Min : Gets methods for adding min commands or options.

    Returns object

    • commands: function
      • commands(count: number): this
      • Min Commands Sets minimum command count.

        Parameters

        • count: number

          the minimum number of commands.

        Returns this

    • options: function
      • options(count: number): this
      • Min Options Sets minimum option count.

        Parameters

        • count: number

          the minimum number of options.

        Returns this

parse

  • get parse(): function

Methods

action

  • Action Adds an action event to be called when parsing matches command.

    Parameters

    • fn: ActionHandler

      the callback function when parsed command matches.

    Returns this

alias

  • Alias Maps alias keys to option/argument key.

    Parameters

    • config: IMap<string[]>

      object map containing aliases.

    Returns PargvCommand

  • Alias Maps alias keys to option/argument key.

    Parameters

    • key: string

      the key to map alias keys to.

    • Rest ...alias: string[]

      keys to map as aliases.

    Returns PargvCommand

  • Parameters

    • key: string | IMap<string[]>
    • Rest ...alias: string[]

    Returns PargvCommand

aliasToKey

  • aliasToKey(key: string | number, def?: any): string
  • Alias To Name Maps an alias key to primary command/flag name.

    Parameters

    • key: string | number

      the key to map to name.

    • Optional def: any

      default value if alias is not found.

    Returns string

aliases

  • aliases(key: string): any[]
  • Aliases Looks up aliases for a given key.

    Parameters

    • key: string

      the primary key to find aliases for.

    Returns any[]

arg

  • Argument Adds sub command argument to command. Wrapped with [arg] if [] or <> not detected.

    Supported to type strings: string, date, array, number, integer, float, json, regexp, boolean

    Parameters

    • token: string

      the option token to parse as option.

    • Optional describe: string

      the description for the option.

    • Optional def: any

      an optional default value.

    • Optional type: string | RegExp | CoerceHandler

      a string type, RegExp to match or Coerce method.

    Returns PargvCommand

castToType

  • castToType(key: string, type: string | RegExp, val?: any, def?: any): any
  • Cast To Type Casts a value to the specified time or fallsback to default.

    Parameters

    • key: string
    • type: string | RegExp

      the type to cast to.

    • Optional val: any

      the value to be cast.

    • Optional def: any

    Returns any

Private clean

  • clean(key: string): void
  • Clean : Filters arrays deletes keys from objects.

    Parameters

    • key: string

      the key name to be cleaned.

    Returns void

coerce

  • Coerce Coerce or transform the defined option/argument when matched.

    Parameters

    Returns PargvCommand

  • Coerce Coerce or transform the defined option when matched.

    Parameters

    • key: string | IMap<IPargvCoerceConfig>

      the option key to be coerced.

    • Optional type: string | RegExp | CoerceHandler

      the string type, RegExp or coerce callback function.

    • Optional def: any

      an optional value when coercion fails.

    Returns PargvCommand

command

  • Command A string containing Parv tokens to be parsed.

    Parameters

    • command: string

      the command token string to parse.

    • Optional describe: string

      a description describing the command.

    Returns PargvCommand

completionFor

  • completionFor(key: string, ...vals: any[]): this
  • Completion At : Injects custom completion value for specified key. Key can be a know command, option or * for anonymous.

    Parameters

    • key: string

      the key to inject completion values for.

    • Rest ...vals: any[]

      the completion values for the provided key.

    Returns this

cwd

  • cwd(path: string | boolean): this
  • CWD : Sets the working directory prepended to external commands/programs. Ignored when action is present. TODO: Not sure I like this need to play with it more.

    Parameters

    • path: string | boolean

      the base path when command is external program.

    Returns this

default

  • Default Sets a default value for a sub command arg or option.

    Parameters

    • config: IMap<any>

      an object containing configs for property defaults.

    Returns PargvCommand

  • Default Sets a default value for sub command arg or option.

    Parameters

    • key: string

      the key to set default value for.

    • val: any

      the value to set for the provided key.

    Returns PargvCommand

  • Parameters

    • key: string | IMap<any>
    • Optional val: any

    Returns PargvCommand

demand

  • demand(...keys: string[]): this
  • Demand The commands or option/argument keys to demand.

    Parameters

    • Rest ...keys: string[]

      additional keys to demand.

    Returns this

describe

  • Describe Adds description for an option/argument.

    Parameters

    • config: IMap<string>

      object containing describes by property.

    Returns PargvCommand

  • Describe Adds description for an option/argument.

    Parameters

    • key: string

      the option key to add description to.

    • Optional describe: string

      the associated description.

    Returns PargvCommand

  • Parameters

    • key: string | IMap<string>
    • Optional describe: string

    Returns PargvCommand

epilog

  • epilog(val: string): this
  • Epilog Displays trailing message.

    Parameters

    • val: string

      the trailing epilogue to be displayed.

    Returns this

example

  • example(example: string | [string, string][], describe?: string): this
  • Example : Saves an example string for the command or tuple consisting of example string and description.

    Parameters

    • example: string | [string, string][]

      string or an array of tuples [example, description].

    • Optional describe: string

      the description for the example.

    Returns this

Private expandOption

  • Expand Option This breaks out the parsed option in to several arrays/objects. This prevents some recursion rather than storing the object itself in turn requiring more loops.

    Parameters

    Returns void

extendAliases

  • extendAliases(extend?: boolean): this
  • Extend Aliases When true option aliases are extended on result object --option, -o results in { option: value, o: value }.

    Parameters

    • Optional extend: boolean

      when true aliases are exteneded on Pargv result object.

    Returns this

extendArguments

  • extendArguments(extend?: boolean): this
  • Extend Commands When true known commands are extended to result object { some_command: value }.

    Parameters

    • Optional extend: boolean

      when true commands are exteneded on Pargv result object.

    Returns this

extendCommands

  • extendCommands(extend?: boolean): this
  • deprecated

    use .extendArguments() instead.

    Extend Commands When true known commands are extended to result object { some_command: value }.

    Parameters

    • Optional extend: boolean

      when true commands are exteneded on Pargv result object.

    Returns this

help

  • Help Enables or disables help for this command.

    Parameters

    • Optional enabled: boolean

      true or false to toggle help.

    Returns PargvCommand

isAnon

  • isAnon(key: string): void

isBool

  • isBool(key: string): boolean
  • Is Bool Looks up flag option check if is of type boolean.

    Parameters

    • key: string

      the option key to check.

    Returns boolean

isCommand

  • isCommand(key: string | number): boolean
  • Is Command Checks if a command exists by index or name.

    Parameters

    • key: string | number

      the command string or index.

    Returns boolean

isOption

  • isOption(key: string): boolean
  • Has Option Inspects if key is known option.

    Parameters

    • key: string

    Returns boolean

isRequired

  • isRequired(key: string | number): boolean
  • Is Required Checks if command or option is required.

    Parameters

    • key: string | number

      the command, index or option key.

    Returns boolean

maxArguments

  • maxArguments(count: number): this
  • Max Commands Specifies the maxium commands allowed.

    Parameters

    • count: number

      the number of command arguments allowed.

    Returns this

maxOptions

  • maxOptions(count: number): this
  • Max Options Specifies the maxium options allowed.

    Parameters

    • count: number

      the number of options allowed.

    Returns this

minArguments

  • minArguments(count: number): this
  • Min Commands Specifies the minimum commands required.

    Parameters

    • count: number

      the number of command arguments required.

    Returns this

minOptions

  • minOptions(count: number): this
  • Min Options Specifies the minimum options required.

    Parameters

    • count: number

      the number of options required.

    Returns this

onError

  • On Error Add custom on error handler.

    Parameters

    Returns this

onHelp

  • On Help Method for adding custom help handler, disabling. If custom handler return compiled help to be displayed or false to handle manually.

    Parameters

    • fn: boolean | HelpHandler

      boolean to enable/disable, or function for custom help.

    Returns this

onLog

  • On Log Add custom on log handler.

    Parameters

    Returns this

option

  • Option Adds option to command.

    Supported types: string, date, array, number, integer, float, json, regexp, boolean

    Parameters

    • token: string

      the option token to parse as option.

    • Optional describe: string

      the description for the option.

    • Optional def: any

      an optional default value.

    • Optional type: string | RegExp | CoerceHandler

      a string type, RegExp to match or Coerce method.

    Returns PargvCommand

Private parseCommand

  • parseCommand(token?: string): void
  • Parse Command Parses a command token.

    Parameters

    • Optional token: string

      the command token string to parse.

    Returns void

Private parseToken

  • Parse Token Parses a usage token.

    Parameters

    • token: string

      the token string to be parsed.

    • Optional next: any

      the next element in usage command.

    Returns IPargvCommandOption

Private rebuildUsage

  • rebuildUsage(): any
  • Rebuild Usage Rebuilds the auto generated usage string.

    Returns any

spawnAction

  • Spawn Action : When defined externally spawned commands will call this action.

    Parameters

    Returns this

spreadArguments

  • spreadArguments(spread?: boolean): this
  • Spread Commands When true found commands are spread in .action(cmd1, cmd2, ...).

    Parameters

    • Optional spread: boolean

      when true spreads command args in callback action.

    Returns this

spreadCommands

  • spreadCommands(spread?: boolean): this
  • deprecated

    use .spreadArguments() instead.

    Spread Commands When true found commands are spread in .action(cmd1, cmd2, ...).

    Parameters

    • Optional spread: boolean

      when true spreads command args in callback action.

    Returns this

stats

  • Stats Iterates arguments mapping to known options and commands finding required, anonymous and missing args.

    Parameters

    • arr: any[]

      the args to get stats for.

    • Optional skip: boolean

      when true deamnds and whens are not built.

    Returns IPargvStats

stripToAlias

  • stripToAlias(key: string | number): string
  • Strip To Alias Strips tokens then returns alias or original key.

    Parameters

    • key: string | number

      the key to retrieve alias for.

    Returns string

Private toggleHelp

  • toggleHelp(enabled?: boolean): boolean
  • Toggle Help Enables or disables help while toggling the help option.

    Parameters

    • Optional enabled: boolean

      whether or not help is enabled.

    Returns boolean

usage

  • usage(val: string): this
  • Usage Usage is generated automatically, this method allows override of the internal generated usage.

    Parameters

    • val: string

      the value to display for command usage.

    Returns this

when

  • When When a specified key demand dependent key.

    Parameters

    Returns PargvCommand

  • When When a specified key demand dependent key.

    Parameters

    • key: string

      require this key.

    • Optional demand: string

      this key is present.

    Returns PargvCommand

  • When When a specified key demand dependent key.

    Parameters

    • key: string

      require this key.

    • Optional demand: string

      this key is present.

    • Optional converse: boolean

      when true the coverse when is also created.

    Returns PargvCommand

  • Parameters

    Returns PargvCommand

Generated using TypeDoc