jackspeak
    Preparing search index...

    Class Jack<C>

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

    Type Parameters

    Index

    Constructors

    Accessors

    • get definitions(): C

      Resulting definitions, suitable to be passed to Node's util.parseArgs, but also including description and short fields, if set.

      Returns C

    • get shorts(): Record<string, string>

      map of { <short>: <long> } strings for each short name defined

      Returns Record<string, string>

    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 } = {}

      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 } = {}

      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, readonly number[] | undefined>
          },
      >

    • Add one or more multiple number fields.

      Type Parameters

      Parameters

      • fields: F

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

    • Add one or more string option fields.

      Type Parameters

      Parameters

      • fields: F

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

    • 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, readonly string[] | undefined>
          },
      >

    • 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]: {
              default?: ConfigValue;
              delim?: string;
              description?: string;
              hint?: string;
              multiple?: boolean;
              short?: string;
              type: ConfigType;
              validate?: ((v: unknown) => boolean) | ((v: unknown) => v is ConfigValue);
              validOptions?: readonly number[] | readonly string[];
          };
      }

    • 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>