Class Jack<C>

Class returned by the jack function and all configuration definition methods. This is what gets chained together.

Type Parameters

Constructors

Methods

  • Custom printer for util.inspect

    Parameters

    • _: number
    • options: InspectOptions

    Returns string

  • Generic field definition method. Similar to flag/flagList/number/etc, but you must specify the type (and optionally multiple and delim) fields on each one, or Jack won't know how to define them.

    Type Parameters

    Parameters

    • fields: F

    Returns Jack<C & F>

  • Add a long-form description to the usage output at this position.

    Parameters

    • text: string
    • __namedParameters: {
          pre?: boolean;
      } = {}
      • Optionalpre?: boolean

    Returns Jack<C>

  • Add one or more flag fields.

    Type Parameters

    Parameters

    • fields: F

    Returns Jack<C & F & {
        [longOption in string | number | symbol]: ConfigOption<"boolean", false, undefined>
    }>

  • Add one or more multiple flag fields.

    Type Parameters

    Parameters

    • fields: F

    Returns Jack<C & F & {
        [longOption in string | number | symbol]: ConfigOption<"boolean", true, undefined>
    }>

  • Add a heading to the usage output banner

    Parameters

    • text: string
    • Optionallevel:
          | 2
          | 1
          | 3
          | 4
          | 5
          | 6
    • __namedParameters: {
          pre?: boolean;
      } = {}
      • Optionalpre?: boolean

    Returns Jack<C>

  • Add one or more number fields.

    Type Parameters

    Parameters

    • fields: F

    Returns Jack<C & F & {
        [longOption in string | number | symbol]: ConfigOption<"number", false, undefined | readonly number[]>
    }>

  • Add one or more multiple number fields.

    Type Parameters

    Parameters

    • fields: F

    Returns Jack<C & F & {
        [longOption in string | number | symbol]: ConfigOption<"number", true, undefined | readonly number[]>
    }>

  • Add one or more string option fields.

    Type Parameters

    Parameters

    • fields: F

    Returns Jack<C & F & {
        [longOption in string | number | symbol]: ConfigOption<"string", false, undefined | readonly string[]>
    }>

  • Add one or more multiple string option fields.

    Type Parameters

    Parameters

    • fields: F

    Returns Jack<C & F & {
        [longOption in string | number | symbol]: ConfigOption<"string", true, undefined | readonly string[]>
    }>

  • Parse a string of arguments, and return the resulting { values, positionals } object.

    If an JackOptions#envPrefix is set, then it will read default values from the environment, and write the resulting values back to the environment as well.

    Environment values always take precedence over any other value, except an explicit CLI setting.

    Parameters

    • args: string[] = process.argv

    Returns Parsed<C>

  • Only parse the command line arguments passed in. Does not strip off the node script.js bits, so it must be just the arguments you wish to have parsed. Does not read from or write to the environment, or set defaults.

    Parameters

    • args: string[]

    Returns Parsed<C>

  • Set the default value (which will still be overridden by env or cli) as if from a parsed config file. The optional source param, if provided, will be included in error messages if a value is invalid or unknown.

    Parameters

    Returns Jack<C>

  • Return the configuration options as a plain object

    Returns {
        [k: string]: T;
    }

    • [k: string]: T
  • Return the usage banner for the given configuration

    Returns string

  • Return the usage banner markdown for the given configuration

    Returns string

  • Validate that any arbitrary object is a valid configuration values object. Useful when loading config files or other sources.

    Parameters

    • o: unknown

    Returns asserts o is OptionsResults<C>