Options
All
  • Public
  • Public/Protected
  • All
Menu

Option - is a helper class used to configure options. It's used for chained calls such as

... .alias().description().default() ...

Type parameters

  • T: Types

  • R: boolean

  • A: boolean

  • RT

Hierarchy

  • Option

Index

Constructors

constructor

Methods

alias

  • alias(...aliases: string[]): Option<T, R, A, RT>
  • Adds one or more aliases to an option. Used to create short aliases such '-a', '-b' etc. Could be called multiple times, the alias lists will be concatenated.

    Parameters

    • Rest ...aliases: string[]

      alias list

    Returns Option<T, R, A, RT>

array

  • array(): Option<T, true, true, RT>
  • Marks the option as multiple. It allows to pass the same option multiple times. So -o 1 -o 2 -o 3 will be resolved as [1, 2, 3]. Important: result will be an array even if only one value was presented (or no value at all) i.e. both [] and [1] are valid results.

    Returns Option<T, true, true, RT>

completer

  • completer(completer: OptionCompleter): Option<T, R, A, RT>
  • Sets the compliter for the option. A completer is a function to be called when shell completion is computated for an option. See 'oneOf' preset source code for usage.

    Parameters

    • completer: OptionCompleter

      completer function

    Returns Option<T, R, A, RT>

default

  • default(value: RT): Option<T, true, A, RT>
  • Sets the default value for an option. Option will be resolved to that value if no value was present. Also removes nullability from the result type like required() does.

    Parameters

    • value: RT

      default value of the option

    Returns Option<T, true, A, RT>

description

  • description(text: string): Option<T, R, A, RT>
  • Sets the description of the option that is printed with the rest of the help when '--help' flag is provided.

    Parameters

    • text: string

      description string

    Returns Option<T, R, A, RT>

label

  • label(name: string): Option<T, R, A, RT>
  • Allows to create custom type name. Useful for presets, allows to get output like: expected <MyType> but recieved <string>

    Parameters

    • name: string

      new label for the type

    Returns Option<T, R, A, RT>

process

  • process(phase: "pre", fn: Preprocessor<any, ResolveType<T>>): Option<T, R, A, RT>
  • process<FR>(phase: "post", fn: Preprocessor<ResolveType<T>, FR>): Option<T, R, A, FR>
  • Adds a pre-/post- processor. A processor is a function that takes a value and return a new one. Each processor gets the result from the previous one and passes new value to the next one. So it looks like this: argv -> proc1 -> proc2 -> result data

    Preprocessors run from raw input and before validation, while postprocessors run after validation and can produce either invalid or non-string-like values such as objects, functions etc.

    So the full data pipeline looks like this: argv -> preprocessors -> validators -> postprocessors -> result data

    Parameters

    • phase: "pre"

      determine whether it will be a preprocessor or post processor

    • fn: Preprocessor<any, ResolveType<T>>

      a processor function

    Returns Option<T, R, A, RT>

  • Type parameters

    • FR

    Parameters

    • phase: "post"
    • fn: Preprocessor<ResolveType<T>, FR>

    Returns Option<T, R, A, FR>

required

  • required(): Option<T, true, A, RT>
  • Marks the option as required. Required options must be provided. Otherwise the program will quit with non-zero code and print an error. On the other hand required options always accessible so there is no need to check if they are presented i.e. no options.foo && options.foo.toString() checks.

    Returns Option<T, true, A, RT>

validate

  • validate(errorMsg: string, validator: BooleanValidator<RT>): Option<T, R, A, RT>
  • validate(validator: Validator<RT>): Option<T, R, A, RT>
  • Adds custom validation function.

    Parameters

    • errorMsg: string

      error message to be shown if the result of validate function is falsy

    • validator: BooleanValidator<RT>

      a validate function that takes a value and return true for valid values and false otherwise

    Returns Option<T, R, A, RT>

  • Adds custom validation function.

    Parameters

    • validator: Validator<RT>

      a validate function that will throw an error if the provided value is invalid

    Returns Option<T, R, A, RT>

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • 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