fynjs API
    Preparing search index...

    Interface OptionSpec

    Option Spec

    interface OptionSpec {
        alias?: string | string[];
        argDefault?: string | string[];
        args?: string;
        counting?: number;
        customTypes?: Record<string, CustomTypeFunc | RegExp | string>;
        desc?: string | (() => string);
        name?: string;
        required?: boolean;
    }

    Hierarchy

    • BaseSpec
      • OptionSpec
    Index
    alias?: string | string[]

    Aliases for the option or command. Can be a single string or an array of strings.

    argDefault?: string | string[]

    Default argument values for the option or command.

    After parsing, the parser applies this accordingly:

    • For options: if the user didn't specify the option, the parser will automatically add the option with the default value.
    • For commands: if the user specifies the command without any arguments.

    The source will be "default".

    args?: string

    Specifies arguments for the command or option.

    • Format: "<name type>" or "[name type]". Types: number, string, boolean, and float.
      • <> denotes a required argument, while [] denotes an optional argument.
        • All required arguments must precede optional arguments.
      • The default type is string and can be omitted, e.g., "<name>". A blank space omits name, e.g., "< string>". Both can be omitted, e.g., <>.
      • Examples: "<arg string>", "[arg number]", or "<arg1 boolean> <arg2 string>".
    • Array arguments: specify with ..N or ..
      • Fixed size array: "<arg string..3>" or "<..3>" means 3 arguments are required.
      • Variadic size array: "<..>" for 0 to many; "<..1,>" or "<..1,Inf>" for 1 to many, indicating at least 1 is required.
        • Only the last argument can be variadic.
    counting?: number

    Enable counting how many times an option was specified in the command line. The value is the maximum number of times the option can be specified.

    customTypes?: Record<string, CustomTypeFunc | RegExp | string>

    Specifies handlers for custom types.

    The handler can be one of:

    • A function: the return value will be taken as the argument value.
    • A RegExp: if matched, the first entry from the matched result will be used as the argument value.
    • A string: the string will be used as the argument value.

    Example:

    {
    myCustomType: (value) => value.toLowerCase()
    }
    desc?: string | (() => string)

    Description of the option or command. Can be a string or a function that returns a string.

    name?: string

    name of the option or command

    required?: boolean

    Indicates whether the command/option is required. If true, the command/option must be specified.