/** Combines recursively all intersection types and returns a new single type. */ type Id = TRecord extends Record ? TRecord extends infer InferredRecord ? { [Key in keyof InferredRecord]: Id; } : never : TRecord; /** Converts a union type `A | B | C` into an intersection type `A & B & C`. */ type UnionToIntersection = (TValue extends unknown ? (args: TValue) => unknown : never) extends (args: infer R) => unknown ? R extends Record ? R : never : never; type BooleanType = boolean | string | undefined; type StringType = string | undefined; type ArgType = StringType | BooleanType; type Collectable = string | undefined; type Negatable = string | undefined; type UseTypes = undefined extends ((false extends TBooleans ? undefined : TBooleans) & TCollectable & TStrings) ? false : true; /** * Creates a record with all available flags with the corresponding type and * default type. */ type Values | undefined, TAliases extends Aliases | undefined> = UseTypes extends true ? Record & AddAliases & RecursiveRequired> & CollectUnknownValues, DedotRecord>, TAliases> : Record; type Aliases = Partial, TAliasNames | ReadonlyArray>>; type AddAliases = { [TArgName in keyof TArgs as AliasNames]: TArgs[TArgName]; }; type AliasNames = TArgName extends keyof TAliases ? string extends TAliases[TArgName] ? TArgName : TAliases[TArgName] extends string ? TArgName | TAliases[TArgName] : TAliases[TArgName] extends Array ? TArgName | TAliases[TArgName][number] : TArgName : TArgName; /** * Spreads all default values of Record `TDefaults` into Record `TArgs` * and makes default values required. * * **Example:** * `SpreadValues<{ foo?: boolean, bar?: number }, { foo: number }>` * * **Result:** `{ foo: boolean | number, bar?: number }` */ type SpreadDefaults = TDefaults extends undefined ? TArgs : TArgs extends Record ? Omit & { [Default in keyof TDefaults]: Default extends keyof TArgs ? (TArgs[Default] & TDefaults[Default] | TDefaults[Default]) extends Record ? NonNullable> : TDefaults[Default] | NonNullable : unknown; } : never; /** * Defines the Record for the `default` option to add * auto-suggestion support for IDE's. */ type Defaults = Id & MapTypes & MapTypes & MapDefaults & MapDefaults>>; type MapDefaults = Partial>; type RecursiveRequired = TRecord extends Record ? { [Key in keyof TRecord]-?: RecursiveRequired; } : TRecord; /** Same as `MapTypes` but also supports collectable options. */ type CollectValues = UnionToIntersection extends string ? (Exclude extends never ? Record : MapTypes, TType, TNegatable>) & (Extract extends never ? Record : RecursiveRequired, Array, TNegatable>>) : MapTypes>; /** Same as `Record` but also supports dotted and negatable options. */ type MapTypes = undefined extends TArgNames ? Record : TArgNames extends `${infer Name}.${infer Rest}` ? { [Key in Name]?: MapTypes; } : TArgNames extends string ? Partial> : Record; type CollectUnknownValues = UnionToIntersection : DedotRecord, string>, Extract>, Array> & Record, string>, Extract>, Array | false>>>; /** Converts `{ "foo.bar.baz": unknown }` into `{ foo: { bar: { baz: unknown } } }`. */ type DedotRecord = Record extends TRecord ? TRecord : TRecord extends Record ? UnionToIntersection : never; }>> : TRecord; type Dedot = TKey extends `${infer Name}.${infer Rest}` ? { [Key in Name]: Dedot; } : { [Key in TKey]: TValue; }; type ValueOf = TValue[keyof TValue]; /** The value returned from `parse`. */ export type Args = Record, TDoubleDash extends boolean | undefined = undefined> = Id; } & (boolean extends TDoubleDash ? DoubleDash : true extends TDoubleDash ? Required : Record)>; type DoubleDash = { /** Contains all the arguments that appear after the double dash: "--". */ "--"?: Array; }; /** The options for the `parse` call. */ export interface ParseOptions | undefined = Record | undefined, TAliases extends Aliases | undefined = Aliases | undefined, TDoubleDash extends boolean | undefined = boolean | undefined> { /** * When `true`, populate the result `_` with everything before the `--` and * the result `['--']` with everything after the `--`. * * @default {false} * * @example * ```ts * // $ deno run example.ts -- a arg1 * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts"; * console.dir(parse(Deno.args, { "--": false })); * // output: { _: [ "a", "arg1" ] } * console.dir(parse(Deno.args, { "--": true })); * // output: { _: [], --: [ "a", "arg1" ] } * ``` */ "--"?: TDoubleDash; /** * An object mapping string names to strings or arrays of string argument * names to use as aliases. */ alias?: TAliases; /** * 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. */ boolean?: TBooleans | ReadonlyArray>; /** An object mapping string argument names to default values. */ default?: TDefault & Defaults; /** * When `true`, populate the result `_` with everything after the first * non-option. */ stopEarly?: boolean; /** A string or array of strings argument names to always treat as strings. */ string?: TStrings | ReadonlyArray>; /** * 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. */ collect?: TCollectable | ReadonlyArray>; /** * A string or array of strings argument names which can be negated * by prefixing them with `--no-`, like `--no-config`. */ negatable?: TNegatable | ReadonlyArray>; /** * 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?: (arg: string, key?: string, value?: unknown) => unknown; } /** 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. * * By default, any arguments starting with `-` or `--` are considered boolean * flags. If the argument name is followed by an equal sign (`=`) it is * considered a key-value pair. Any arguments which could not be parsed are * available in the `_` property of the returned object. * * By default, the flags module tries to determine the type of all arguments * automatically and the return type of the `parse` method will have an index * signature with `any` as value (`{ [x: string]: any }`). * * If the `string`, `boolean` or `collect` option is set, the return value of * the `parse` method will be fully typed and the index signature of the return * type will change to `{ [x: string]: unknown }`. * * Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`. * * Numeric-looking arguments will be returned as numbers unless `options.string` * or `options.boolean` is set for that argument name. * * @example * ```ts * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts"; * const parsedArgs = parse(Deno.args); * ``` * * @example * ```ts * import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts"; * const parsedArgs = parse(["--foo", "--bar=baz", "./quux.txt"]); * // parsedArgs: { foo: true, bar: "baz", _: ["./quux.txt"] } * ``` */ export declare function parse, TDoubleDash extends boolean | undefined = undefined, TBooleans extends BooleanType = undefined, TStrings extends StringType = undefined, TCollectable extends Collectable = undefined, TNegatable extends Negatable = undefined, TDefaults extends Record | undefined = undefined, TAliases extends Aliases | undefined = undefined, TAliasArgNames extends string = string, TAliasNames extends string = string>(args: string[], { "--": doubleDash, alias, boolean, default: defaults, stopEarly, string, collect, negatable, unknown, }?: ParseOptions): Args; export {};