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

Hierarchy

  • internal
    • 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: ReadonlyArray

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: object

Parsed CLI options, camelCased

Type declaration

  • [k: string]: any

rawArgs

rawArgs: string[]

Raw CLI arguments

rawOptions

rawOptions: object

Raw CLI options, i.e. not camelcased

Type declaration

  • [k: string]: any

Private showHelpOnExit

showHelpOnExit: boolean

Private showVersionOnExit

showVersionOnExit: boolean

Methods

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

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 MriResult

off

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

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

          • Rest ...args: any[]

          Returns void

    Returns this

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

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(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.

    This will also call process.exit(0) to quit the process.

    Returns void

outputVersion

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

    This will also call process.exit(0) to quit the process.

    Returns void

parse

  • parse(argv?: string[], __namedParameters?: object): ParsedArgv
  • Parse argv

    Parameters

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

        Whether to run the action for matched command

    Returns ParsedArgv

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

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: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...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: object, matchedCommand?: Command, matchedCommandName?: undefined | string): this
  • Parameters

    • __namedParameters: object
      • args: ReadonlyArray<string>
      • options: object
        • [k: string]: any
      • rawOptions: object
        • [k: string]: any
    • Optional matchedCommand: Command
    • Optional matchedCommandName: undefined | string

    Returns this

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

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc