Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Pargv

Hierarchy

  • EventEmitter
    • Pargv

Index

Constructors

constructor

Properties

Private _base

_base: string | boolean = false

Private _command

_command: PargvCommand

_commands

_commands: IMap<PargvCommand>

Private _completions

_completions: IPargvCompletions

Private _completionsCommand

_completionsCommand: string = "completions"

Private _completionsHandler

_completionsHandler: CompletionHandler

Private _completionsReply

_completionsReply: string = "--reply"

_env

_env: IPargvEnv

Private _errorHandler

_errorHandler: ErrorHandler

_helpCommand

_helpCommand: string

Private _helpHandler

_helpHandler: HelpHandler

_localize

_localize: LocalizeInit

Private _logHandler

_logHandler: LogHandler

Private _meta

options

options: IPargvOptions

Static defaultMaxListeners

defaultMaxListeners: number

Accessors

$

  • deprecated

    use pargv.command()

    Default Command Exposes default command for parsing anonymous arguments.

    example

    pargv.$.option('-t').parse(['one', '-t', 'test'])

    Returns PargvCommand

argv

epilogue

get

  • get get(): object
  • Gets help, completion script, completions, options...

    Returns object

    • command: function
    • completion: function
      • completion(path?: string, template?: string): string
      • Parameters

        • Optional path: string

          the path/name of executable.

        • Optional template: string

          the template string.

        Returns string

    • help: function
    • option: function
      • option(key: string): any
      • Parameters

        • key: string

          the option key to get.

        Returns any

if

listen

  • get listen(): exec

remove

  • get remove(): object
  • Removes elements and objects.

    Returns object

    • command: function
      • command(key: string): this
      • Parameters

        • key: string

          the command key/name to be removed.

        Returns this

set

  • get set(): object
  • Methods for setting values.

    Returns object

    • option: function
      • Parameters

        • key: string | IPargvOptions

          the key or PargvOptions object to be set.

        • Optional val: any

          the value for the provided key.

        Returns this

show

  • get show(): object
  • Shows help, completion script or env.

    Returns object

    • completion: function
      • completion(path?: string, template?: string): this
      • Parameters

        • Optional path: string

          the path/name of executable.

        • Optional template: string

          the template string.

        Returns this

    • help: function
      • Parameters

        • Optional command: string | PargvCommand

          optional command to show help for.

        Returns this

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 Pargv

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

alias

  • alias(config: IMap<string[]>): Pargv
  • alias(key: string, ...alias: string[]): Pargv
  • Alias Maps alias configs to default command.

    Parameters

    • config: IMap<string[]>

      object map containing aliases.

    Returns Pargv

  • Alias Maps alias to default command.

    Parameters

    • key: string

      the key to map alias keys to.

    • Rest ...alias: string[]

      keys to map as aliases.

    Returns Pargv

base

  • base(path: string | boolean): void
  • Base : Sets a base path for all external scripts that contain extentions.

    Parameters

    • path: string | boolean

      a base path for ALL external command scripts.

    Returns void

Private buildHelp

  • Build Help Common method to get help before show or return.

    Parameters

    • Optional command: string | PargvCommand

      optional command to get help for.

    Returns any

coerce

  • Coerce Coerce or transform each sub command argument or option in config object for default command.

    Parameters

    Returns Pargv

command

  • command(command: string, describe?: string): Partial<PargvCommand>
  • 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 Partial<PargvCommand>

Private compatibility

  • compatibility(key: string | IPargvOptions, warn?: boolean): any
  • Compatibility Ensures compatibility with deprecated properties.

    Parameters

    • key: string | IPargvOptions

      the key or object to map.

    • Optional warn: boolean

      when true deprecation message is logged.

    Returns any

Private compileHelp

  • Compile Help Compiles help for all commands or single defined commnand.

    Parameters

    • Optional command: string

      the optional command to build help for.

    Returns IPargvLayout

completion

  • Completion : Adds the completion command for use within your app for generating completion script.

    Parameters

    • Optional command: string

      the name of the commpletion install command.

    • Optional fn: CompletionHandler

      the optional completion handler.

    Returns Pargv

  • Parameters

    Returns Pargv

  • Parameters

    • Optional command: string
    • Optional describe: string
    • Optional template: string
    • Optional fn: CompletionHandler

    Returns Pargv

completionFor

  • completionFor(key: string, ...vals: any[]): Pargv
  • Completion At : Injects custom completion value for specified key. Key can be a known sub command argument 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 Pargv

completionResult

  • Completion Result Method called maually or by script stored in your bash profile.

    Parameters

    • line: string | string[] | IPargvParsedResult

      the Pargv parsed result, array of values or string (current line).

    • Optional fn: CompletionHandler

      the callback on done compiling completions.

    Returns string[]

default

  • default(config: IMap<any>): Pargv
  • default(key: string, val: any): Pargv
  • Default Sets a default value for specified sub command argument or option in default command.

    Parameters

    • config: IMap<any>

      an object containing configs for property defaults.

    Returns Pargv

  • Default Sets a default value for specified sub command argument or option in default command.

    Parameters

    • key: string

      the key to set default value for.

    • val: any

      the value to set for the provided key.

    Returns Pargv

demand

  • demand(...keys: string[]): Pargv
  • Demand The sub command argument or option keys to be demanded for default command.

    Parameters

    • Rest ...keys: string[]

    Returns Pargv

describe

  • describe(config: IMap<string>): Pargv
  • describe(key: string, describe?: string): Pargv
  • Describe Adds description for default command sub command argument or option.

    Parameters

    • config: IMap<string>

      object containing describes by property.

    Returns Pargv

  • Describe Adds description for default command sub command argument or option.

    Parameters

    • key: string

      the option key to add description to.

    • Optional describe: string

      the associated description.

    Returns Pargv

description

  • description(val?: string): Pargv
  • Description Adds description to help header.

    Parameters

    • Optional val: string

      the description string.

    Returns Pargv

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

epilog

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

    Parameters

    • val: string

      the trailing epilogue to be displayed.

    Returns this

error

  • error(...args: any[]): void
  • Error : Handles error messages.

    Parameters

    • Rest ...args: any[]

      args to be formatted and logged.

    Returns void

Private errorHandler

  • errorHandler(err: Error): void
  • Error Handler The default error handler.

    Parameters

    • err: Error

      the PargvError instance.

    Returns void

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

example

  • example(example: string | [string, string][], describe?: string): Pargv
  • Example : Saves an example string/tuple of example string & description for default command.

    Parameters

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

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

    • Optional describe: string

      the description for the example.

    Returns Pargv

exec

  • Exec Parses arguments then executes command action if any.

    Parameters

    • Rest ...argv: any[]

      optional arguments otherwise defaults to process.argv.

    Returns IPargvParsedResult

extendAliases

  • extendAliases(extend?: boolean): Pargv
  • 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 Pargv

Private formatLogMessage

  • formatLogMessage(...args: any[]): string
  • Logger Formats messages for logging.

    Parameters

    • Rest ...args: any[]

      log arguments.

    Returns string

getCommand

  • Command : Finds a command by name.

    Parameters

    • key: string

      the name of the command to find.

    Returns PargvCommand

getCompletion

  • getCompletion(path?: string, template?: string): string
  • Get Completion : Gets the completion script.

    Parameters

    • Optional path: string

      the path/name of executable.

    • Optional template: string

      the template string.

    Returns string

getHelp

  • Help : Gets help text.

    Parameters

    • Optional command: string | PargvCommand

      optional command to show help for.

    Returns any

getMaxListeners

  • getMaxListeners(): number
  • Returns number

getOption

  • getOption(key: string): any
  • Option : Gets an option value by the specified key.

    Parameters

    • key: string

      the option key to get.

    Returns any

help

  • help(enabled?: boolean): Pargv
  • Help Enables or disables help for default command.

    Parameters

    • Optional enabled: boolean

      true or false to toggle help.

    Returns Pargv

Private helpHandler

  • helpHandler(command?: string): string
  • Help Handler The default help handler.

    Parameters

    • Optional command: string

      optional command to get help for.

    Returns string

Private init

  • Init Common method to initialize Pargv also used in .reset().

    Parameters

    Returns this

layout

license

  • license(val?: string): Pargv
  • License Adds license to help header.

    Parameters

    • Optional val: string

      the license type.

    Returns Pargv

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

log

  • log(...args: any[]): this
  • Log Displays log messages after formatting, supports metadata.

    Parameters

    • Rest ...args: any[]

      the arguments to log.

    Returns this

Private logHandler

  • logHandler(message: string): void
  • Log Handler : Handles internal log messages.

    Parameters

    • message: string

      the message to be logged.

    Returns void

maxOptions

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

    Parameters

    • count: number

      the number of options allowed.

    Returns this

meta

  • Meta Enables adding metadata to your header.

    example

    .meta('version', '1.1.0')

    Parameters

    Returns Pargv

  • Meta Enables adding metadata to your header.

    example

    .meta('version', '1.1.0')

    Parameters

    • key: string

      the key to be added.

    • Optional val: any

      the value for key, if undefined will try to lookup from package.json.

    Returns Pargv

minOptions

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

    Parameters

    • count: number

      the number of options required.

    Returns this

name

  • Name Adds name of CLI to help header.

    Parameters

    • Optional val: string

      the value to use as app name.

    • Optional styles: AnsiStyles | AnsiStyles[]

      an ansi color/style or array of styles. (DEPRECATED)

    • Optional font: string

      a Figlet font. (DEPRECATED)

    Returns Pargv

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    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

    • Optional fn: boolean | HelpHandler

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

    Returns this

onLog

  • On Log Add custom on log handler.

    Parameters

    • Optional fn: LogHandler

      the log handler function.

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

option

  • option(token: string, describe?: string, def?: any, type?: string | RegExp | CoerceHandler): Pargv
  • Option Adds option to default 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 Pargv

parse

  • Parse Parses the provided arguments inspecting for commands and options.

    Parameters

    • Rest ...argv: any[]

      the process.argv or custom args array.

    Returns IPargvParsedResult

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeCommand

  • removeCommand(key: string): this
  • Remove Removes a command from the collection.

    Parameters

    • key: string

      the command key/name to be removed.

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

reset

  • Reset Clears all defined commands as well as custom handlers and metadata.

    Parameters

    • Optional all: boolean

      when true resets metadata, base, help handler if set.

    Returns Pargv

  • Reset Clears all commands and optionally resets custom handlers and metadata.

    Parameters

    • Optional options: IPargvOptions

      Pargv options to reset with.

    • Optional all: boolean

      when true resets metadata, base, help handler if set.

    Returns Pargv

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

setOption

  • Option : Sets an option or group of options.

    Parameters

    • key: string | IPargvOptions

      the key or PargvOptions object to be set.

    • Optional val: any

      the value for the provided key.

    Returns this

showCompletion

  • showCompletion(path?: string, template?: string): this
  • Completion Shows the completion script in terminal.

    Parameters

    • Optional path: string

      the path/name of executable.

    • Optional template: string

      the template string.

    Returns this

showHelp

  • Help Shows help in terminal.

    Parameters

    • Optional command: string | PargvCommand

      optional command to show help for.

    Returns this

spawn

  • spawn(prog: string, args?: any[], options?: SpawnOptions, exit?: boolean): ChildProcess
  • spawn(prog: string, args?: any[], options?: SpawnOptions, exit?: boolean): ChildProcess
  • Spawn Spawns a new child process, used by spawnHandler internally.

    Parameters

    • prog: string

      the program to be spawned.

    • Optional args: any[]

      the arguments to pass to the child process.

    • Optional options: SpawnOptions
    • Optional exit: boolean

      whether should exit on close.

    Returns ChildProcess

  • Spawn Spawns a new child process, used by spawnHandler internally.

    Parameters

    • prog: string

      the program to be spawned.

    • Optional args: any[]

      the arguments to pass to the child process.

    • Optional options: SpawnOptions

      the spawn options.

    • Optional exit: boolean

      whether should exit on close.

    Returns ChildProcess

spawnHandler

  • Spawn : Spawns and executes and external command.

    Parameters

    • parsed: IPargvParsedResult

      the parsed command result.

    • cmd: Partial<PargvCommand>

      a PargvCommand instance.

    • Optional stdio: any

      optional stdio for child process.

    • Optional exit: boolean

      indicates if should exit after process.

    Returns ChildProcess

stats

  • Stats Iterates array of arguments comparing to defined configuration. To get stats from default command use 'default' as key name.

    Parameters

    • command: string

      the command key to get stats for.

    • Rest ...args: any[]

      args to gets stats for.

    Returns IPargvStats

Private toNormalized

  • toNormalized(...args: any[]): any[]
  • Normalize Args Converts -abc to -a -b -c Converts --name=bob to --name bob

    Parameters

    • Rest ...args: any[]

      the arguments to normalize.

    Returns any[]

usage

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

    Parameters

    • val: string

      the value to display for command usage.

    Returns this

version

  • version(val?: string): Pargv
  • Version Adds version to help header.

    Parameters

    • Optional val: string

      the value to use as version name.

    Returns Pargv

when

  • When When a specified key in config object demand dependent key for default command.

    Parameters

    Returns Pargv

  • When When a specified key demand dependent key for default command.

    Parameters

    • key: string

      require this key.

    • Optional converse: string

      when true the coverse when is also created.

    Returns Pargv

  • When When a specified key demand dependent key for default command.

    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 Pargv

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc