@flowscripter/dynamic-cli-framework
    Preparing search index...

    Interface ComplexOption

    A container option argument for defining SubCommand nested argument hierarchies.

    interface ComplexOption {
        configurationKey?: string;
        defaultValue?: Values | Values[];
        description?: string;
        isArray?: boolean;
        isCaseInsensitive?: boolean;
        isOptional?: boolean;
        maxValueInclusive?: number;
        minValueInclusive?: number;
        name: string;
        properties: readonly (ComplexOption | Option)[];
        shortAlias?: string;
        type: COMPLEX;
        validate?: (
            value: ValueType | Values | Values[],
            context: ValidationContext,
        ) => string | undefined;
    }

    Hierarchy

    • Omit<Option, "type" | "defaultValue" | "allowableValues">
      • ComplexOption
    Index
    configurationKey?: string

    Optional configuration key to use for the argument. Must consist of alphanumeric non-whitespace uppercase ASCII or _ characters. Must not start with a digit.

    If not specified a default configuration key is determined as follows: The SubCommandArgument.name is capitalized and any - characters are replaced with _ characters. If the result starts with a digit, it is prefixed with _. Some examples:

    • name: FooBar => configuration key: FOOBAR
    • name: Hello-World- => configuration key: HELLO_WORLD_
    • name: 3 => configuration key: _3

    NOTE: Regardless of whether a configurationKey is specified, or the default is relied upon, it will only be used if the parent Command has specified Command.enableConfiguration as true.

    defaultValue?: Values | Values[]

    Default value for the argument if not specified.

    description?: string

    Optional description of the argument.

    isArray?: boolean

    If this is true the option can be specified multiple times and all values will be returned in an array matching the order provided.

    NOTE: If isOptional is false, at least one instance of the option must be specified.

    isCaseInsensitive?: boolean

    Optional (default is false) for ValueTypeName.STRING when comparing a value against allowableValues.

    isOptional?: boolean

    If this is true the option does not need to be specified nor have a default value.

    maxValueInclusive?: number

    Optional for ValueTypeName.INTEGER or ValueTypeName.NUMBER when validating a value.

    minValueInclusive?: number

    Optional for ValueTypeName.INTEGER or ValueTypeName.NUMBER when validating a value.

    name: string

    Name of the argument.

    Must consist of alphanumeric non-whitespace ASCII or _ and - characters. Cannot start with -.

    properties: readonly (ComplexOption | Option)[]

    List of child Option properties.

    Each property is validated in declaration order, including its own Argument.validate function if one is defined. Property validators run before the validator of this complex option. A property's defaultValue is used when it is absent, and an absent property with isOptional is skipped.

    shortAlias?: string

    Optional short alias for the option.

    Must consist of a single alphanumeric non-whitespace ASCII character.

    type: COMPLEX

    Type of the argument value.

    validate?: (
        value: ValueType | Values | Values[],
        context: ValidationContext,
    ) => string | undefined

    Optional custom validation function invoked after all built-in validation has passed. Receives the validated and type-converted value and a ValidationContext giving access to all other provided values of the command. A validator that only needs the value may declare just the first parameter.

    Return undefined if the value is valid, or a string describing the validation error. The error string is associated with InvalidArgumentReason.CUSTOM_VALIDATION.

    Validators declared on properties nested inside ComplexOption.properties are also invoked, at any depth:

    • Validation is bottom-up and depth-first, in properties declaration order. A property's validator is invoked after the validators of its own child properties, and only if they all passed. A parent therefore always receives a fully converted and child-validated value.
    • Validation stops at the first failure, so later validators are not invoked.
    • For an argument with isArray, the validator is invoked once with the whole converted array. For an array of ComplexOption values, the child property validators are invoked for each element.
    • An absent nested property with a defaultValue is validated using the default value. An absent nested property with isOptional and no default is skipped and its validator is not invoked.
    • A nested failure is reported with the full property path as the invalid argument name, e.g. opt.sub[2].field.

    Example: ensure array values are unique:

    validate: (value) => {
    const arr = value as string[];
    return new Set(arr).size !== arr.length
    ? "values must be unique"
    : undefined;
    }