Skip to main content

@std/flags@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score82%
Published2 years ago (0.215.0)
default
Deprecated

(will be removed in 1.0.0) Import from https://deno.land/std/cli/parse_args.ts instead.

Command line arguments parser based on minimist.

Examples

Example 1

import { parse } from "@std/flags";

console.dir(parse(Deno.args));

Functions

f
parse<
TArgs extends Values<
TBooleans,
TStrings,
TCollectable,
TNegatable,
TDefaults,
TAliases
>
,
TDoubleDash extends boolean | undefined = undefined,
TBooleans extends BooleanType = undefined,
TStrings extends StringType = undefined,
TCollectable extends Collectable = undefined,
TNegatable extends Negatable = undefined,
TDefaults extends Record<string, unknown> | undefined = undefined,
TAliases extends Aliases<TAliasArgNames, TAliasNames> | undefined = undefined,
TAliasArgNames extends string = string,
TAliasNames extends string = string
>
(
args: string[],
unnamed 1?: ParseOptions<
TBooleans,
TStrings,
TCollectable,
TNegatable,
TDefaults,
TAliases,
TDoubleDash
>
): Args<TArgs, TDoubleDash>

Take a set of command line arguments, optionally with a set of options, and return an object representing the flags found in the passed arguments.

Interfaces

I

The options for the parse call.

  • --: TDoubleDash

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

  • alias: TAliases

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

  • boolean: TBooleans | ReadonlyArray<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.

  • collect: TCollectable | ReadonlyArray<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. All Collectable arguments will be set to [] by default.

  • default: TDefault & Defaults<TBooleans, TStrings>

    An object mapping string argument names to default values.

  • negatable: TNegatable | ReadonlyArray<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.

  • string: TStrings | ReadonlyArray<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.

Type Aliases

T
Args<
TArgs extends Record<string, unknown> = Record<string, any>,
TDoubleDash extends boolean | undefined = undefined
>
= Id<
TArgs
& { _: Array<string | number>; }
& (boolean extends TDoubleDash ? DoubleDash : true extends TDoubleDash ? Required<DoubleDash> : Record<never, never>)
>

The value returned from parse.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/flags

Import symbol

import * as flags from "@std/flags";
or

Import directly with a jsr specifier

import * as flags from "jsr:@std/flags";