Interface ParseOptions<TBooleans, TStrings, TCollectable, TNegatable, TDefault, TAliases, TDoubleDash>

Options for parseArgs.

interface ParseOptions<TBooleans, TStrings, TCollectable, TNegatable, TDefault, TAliases, TDoubleDash> {
    --?: TDoubleDash;
    alias?: TAliases;
    boolean?: TBooleans | readonly Extract<TBooleans, string>[];
    collect?: TCollectable | readonly Extract<TCollectable, string>[];
    default?: TDefault & Id<UnionToIntersection<Record<string, unknown> & MapTypes<TStrings, unknown, undefined> & MapTypes<TBooleans, unknown, undefined> & Partial<Record<TBooleans extends string
        ? TBooleans<TBooleans>
        : string, unknown>> & Partial<Record<TStrings extends string
        ? TStrings<TStrings>
        : string, unknown>>>>;
    negatable?: TNegatable | readonly Extract<TNegatable, string>[];
    stopEarly?: boolean;
    string?: TStrings | readonly Extract<TStrings, string>[];
    unknown?: ((arg: string, key?: string, value?: unknown) => unknown);
}

Type Parameters

  • TBooleans extends BooleanType = BooleanType
  • TStrings extends StringType = StringType
  • TCollectable extends Collectable = Collectable
  • TNegatable extends Negatable = Negatable
  • TDefault extends Record<string, unknown> | undefined = Record<string, unknown> | undefined
  • TAliases extends Aliases | undefined = Aliases | undefined
  • TDoubleDash extends boolean | undefined = boolean | undefined

Properties

When true, populate the result _ with everything before the -- and the result ['--'] with everything after the --.

{false}
// $ deno run example.ts -- a arg1
import { parseArgs } from "@std/cli/parse-args";
const args = parseArgs(Deno.args, { "--": false }); // args equals { _: [ "a", "arg1" ] }
// $ deno run example.ts -- a arg1
import { parseArgs } from "@std/cli/parse-args";
const args = parseArgs(Deno.args, { "--": true }); // args equals { _: [], --: [ "a", "arg1" ] }
alias?: TAliases

An object mapping string names to strings or arrays of string argument names to use as aliases.

{{}}
boolean?: TBooleans | readonly Extract<TBooleans, string>[]

A boolean, string or array of strings to always treat as booleans. If true will treat all double hyphenated arguments without equal signs as boolean (e.g. affects --foo, not -f or --foo=bar). All boolean arguments will be set to false by default.

{false}
collect?: TCollectable | readonly Extract<TCollectable, string>[]

A string or array of strings argument names to always treat as arrays. Collectable options can be used multiple times. All values will be collected into one array. If a non-collectable option is used multiple times, the last value is used.

{[]}
default?: TDefault & Id<UnionToIntersection<Record<string, unknown> & MapTypes<TStrings, unknown, undefined> & MapTypes<TBooleans, unknown, undefined> & Partial<Record<TBooleans extends string
    ? TBooleans<TBooleans>
    : string, unknown>> & Partial<Record<TStrings extends string
    ? TStrings<TStrings>
    : string, unknown>>>>

An object mapping string argument names to default values.

{{}}
negatable?: TNegatable | readonly Extract<TNegatable, string>[]

A string or array of strings argument names which can be negated by prefixing them with --no-, like --no-config.

{[]}
stopEarly?: boolean

When true, populate the result _ with everything after the first non-option.

{false}
string?: TStrings | readonly Extract<TStrings, string>[]

A string or array of strings argument names to always treat as strings.

{[]}
unknown?: ((arg: string, key?: string, value?: unknown) => unknown)

A function which is invoked with a command line parameter not defined in the options configuration object. If the function returns false, the unknown option is not added to parsedArgs.

{unknown}