UNPKG

2.73 kBTypeScriptView Raw
1import { StrictValidator } from "typanion";
2import { CommandOptionReturn, GeneralOptionFlags, WithArity } from "./utils";
3export type StringOptionNoBoolean<T, Arity extends number = 1> = GeneralOptionFlags & {
4 env?: string;
5 validator?: StrictValidator<unknown, T>;
6 tolerateBoolean?: false;
7 arity?: Arity;
8};
9export type StringOptionTolerateBoolean<T> = GeneralOptionFlags & {
10 env?: string;
11 validator?: StrictValidator<unknown, T>;
12 tolerateBoolean: boolean;
13 arity?: 0;
14};
15export type StringOption<T> = StringOptionNoBoolean<T> | StringOptionTolerateBoolean<T>;
16export type StringPositionalFlags<T> = {
17 validator?: StrictValidator<unknown, T>;
18 name?: string;
19 required?: boolean;
20};
21/**
22 * Used to annotate positional options. Such options will be strings
23 * unless they are provided a schema, which will then be used for coercion.
24 *
25 * Be careful: this function is order-dependent! Make sure to define your
26 * positional options in the same order you expect to find them on the
27 * command line.
28 */
29export declare function String(): CommandOptionReturn<string>;
30export declare function String<T = string>(opts: StringPositionalFlags<T> & {
31 required: false;
32}): CommandOptionReturn<T | undefined>;
33export declare function String<T = string>(opts: StringPositionalFlags<T>): CommandOptionReturn<T>;
34/**
35 * Used to annotate string options. Such options will be typed as strings
36 * unless they are provided a schema, which will then be used for coercion.
37 *
38 * @example
39 * --foo=hello --bar world
40 * ► {"foo": "hello", "bar": "world"}
41 */
42export declare function String<T extends {} = string, Arity extends number = 1>(descriptor: string, opts: StringOptionNoBoolean<T, Arity> & {
43 required: true;
44}): CommandOptionReturn<WithArity<T, Arity>>;
45export declare function String<T extends {} = string, Arity extends number = 1>(descriptor: string, opts?: StringOptionNoBoolean<T, Arity>): CommandOptionReturn<WithArity<T, Arity> | undefined>;
46export declare function String<T extends {} = string, Arity extends number = 1>(descriptor: string, initialValue: WithArity<string, Arity>, opts?: Omit<StringOptionNoBoolean<T, Arity>, 'required'>): CommandOptionReturn<WithArity<T, Arity>>;
47export declare function String<T = string>(descriptor: string, opts: StringOptionTolerateBoolean<T> & {
48 required: true;
49}): CommandOptionReturn<T | boolean>;
50export declare function String<T = string>(descriptor: string, opts: StringOptionTolerateBoolean<T>): CommandOptionReturn<T | boolean | undefined>;
51export declare function String<T = string>(descriptor: string, initialValue: string | boolean, opts: Omit<StringOptionTolerateBoolean<T>, 'required'>): CommandOptionReturn<T | boolean>;