Function createOptionGetter

  • Creates an OptionGetter function to dynamically retrieve the value of a command option. The getter function accepts an optional OptionGetterOptions object, which can be used to prompt the user when no value is provided and/or validate the value.

    Type Parameters

    Parameters

    • getOptions: OptionGetterFactoryOptions<TConfig, TValue>

      The options to create the getter.

    Returns OptionGetter<TValue>

    The getter function for the provided option.

    const fooGetter = createOptionGetter({
    name: 'foo',
    option: {
    type: 'string',
    default: 'default foo',
    },
    value: 'foo value',
    client: new Client(),
    });
    const val = fooGetter({ prompt: { message: 'Enter foo' } }); // 'foo value'

    Throws an error if the option is required and no value is provided or the value is invalid.