cac
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • EventEmitter
    • CAC

Index

Constructors

constructor

  • new CAC(name?: string): CAC
  • Parameters

    • Default value name: string = ""

      The program name to display in help and version message

    Returns CAC

Properties

args

args: ParsedArgv["args"]

Parsed CLI arguments

commands

commands: Command[]

globalCommand

globalCommand: GlobalCommand

Optional matchedCommand

matchedCommand: Command

Optional matchedCommandName

matchedCommandName: undefined | string

name

name: string

The program name to display in help and version message

options

options: ParsedArgv["options"]

Parsed CLI options, camelCased

rawArgs

rawArgs: string[]

Raw CLI arguments

showHelpOnExit

showHelpOnExit: boolean

showVersionOnExit

showVersionOnExit: boolean

Static defaultMaxListeners

defaultMaxListeners: number

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

command

  • Add a sub-command

    Parameters

    • rawName: string
    • Optional description: undefined | string
    • Optional config: CommandConfig

    Returns Command

emit

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

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

    Returns boolean

eventNames

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

example

  • Add a global example.

    This example added here will not be used by sub-commands.

    Parameters

    Returns this

getMaxListeners

  • getMaxListeners(): number
  • Returns number

help

  • Show help message when -h, --help flags appear.

    Parameters

    Returns this

listenerCount

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

    • type: string | symbol

    Returns number

listeners

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

    • event: string | symbol

    Returns Function[]

Private mri

  • Parameters

    • argv: string[]
    • Optional command: Command

    Returns ParsedArgv

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

option

  • option(rawName: string, description: string, config?: OptionConfig): this
  • Add a global CLI option.

    Which is also applied to sub-commands.

    Parameters

    • rawName: string
    • description: string
    • Optional config: OptionConfig

    Returns this

outputHelp

  • outputHelp(): void
  • Output the corresponding help message When a sub-command is matched, output the help message for the command Otherwise output the global one.

    Returns void

outputVersion

  • outputVersion(): void
  • Output the version number.

    Returns void

parse

  • parse(argv?: string[], __namedParameters?: { run: boolean }): ParsedArgv
  • Parse argv

    Parameters

    • Default value argv: string[] = processArgs
    • Default value __namedParameters: { run: boolean } = {}
      • run: boolean

        Whether to run the action for matched command

    Returns ParsedArgv

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

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

    • event: string | symbol

    Returns Function[]

removeAllListeners

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

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

runMatchedCommand

  • runMatchedCommand(): any
  • Returns any

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

Private setParsedInfo

  • setParsedInfo(__namedParameters: { args: ReadonlyArray<string>; options: {} }, matchedCommand?: Command, matchedCommandName?: undefined | string): this
  • Parameters

    • __namedParameters: { args: ReadonlyArray<string>; options: {} }
      • args: ReadonlyArray<string>
      • options: {}
        • [k: string]: any
    • Optional matchedCommand: Command
    • Optional matchedCommandName: undefined | string

    Returns this

unsetMatchedCommand

  • unsetMatchedCommand(): void
  • Returns void

usage

  • usage(text: string): this
  • Add a global usage text.

    This is not used by sub-commands.

    Parameters

    • text: string

    Returns this

version

  • version(version: string, customFlags?: string): this
  • Show version number when -v, --version flags appear.

    Parameters

    • version: string
    • Default value customFlags: string = "-v, --version"

    Returns this

Static listenerCount

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

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Legend

  • Class
  • Constructor
  • Property
  • Method
  • Variable
  • Function
  • Type alias
  • Interface
  • Inherited method
  • Private method

Generated using TypeDoc