mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-05 06:40:35 +08:00
Merge pull request #21040 from Slessi/args-typings
Add typings for leo/args 3.0.7
This commit is contained in:
67
types/args/args-tests.ts
Normal file
67
types/args/args-tests.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import * as args from "args";
|
||||
|
||||
args
|
||||
.option("opt1", "desc")
|
||||
.option("opt2", "desc", false, (value: any): any => value)
|
||||
.options([
|
||||
{
|
||||
name: 'opt3',
|
||||
description: 'desc',
|
||||
defaultValue: 1,
|
||||
init: (value: any) => { },
|
||||
},
|
||||
{
|
||||
name: 'opt4',
|
||||
description: 'desc',
|
||||
},
|
||||
])
|
||||
.command("cm1", "desc")
|
||||
.command("cm2", "desc", (value: any): void => { }, ['a'])
|
||||
.example("ex1", "desc")
|
||||
.examples([
|
||||
{
|
||||
usage: "ex2",
|
||||
description: "desc",
|
||||
},
|
||||
]);
|
||||
|
||||
args.parse(['~/bin/node', '~/dir', 'arg', '--param'], {
|
||||
help: true,
|
||||
name: "name",
|
||||
version: true,
|
||||
usageFilter: (a: any): any => a,
|
||||
value: "value",
|
||||
mri: {
|
||||
args: ['a'],
|
||||
alias: {
|
||||
a: "b",
|
||||
c: ['d'],
|
||||
},
|
||||
boolean: ['wat'],
|
||||
default: {
|
||||
foo: 'bar',
|
||||
},
|
||||
string: ['zulu'],
|
||||
unknown: (param: string): boolean => true,
|
||||
},
|
||||
minimist: {
|
||||
string: ['string'],
|
||||
boolean: ['string'],
|
||||
alias: {
|
||||
bar: 'foo',
|
||||
foo: ['bar1', 'bar2'],
|
||||
},
|
||||
default: {
|
||||
foo: 'bar',
|
||||
},
|
||||
stopEarly: true,
|
||||
"--": false,
|
||||
unknown: (param: string): boolean => true,
|
||||
},
|
||||
mainColor: "yellow",
|
||||
subColor: "dim"
|
||||
});
|
||||
|
||||
args.showHelp();
|
||||
|
||||
const x: string = args.sub[0];
|
||||
72
types/args/index.d.ts
vendored
Normal file
72
types/args/index.d.ts
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
// Type definitions for args 3.0
|
||||
// Project: https://github.com/leo/args#readme
|
||||
// Definitions by: Slessi <https://github.com/Slessi>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare const c: args;
|
||||
export = c;
|
||||
|
||||
interface args {
|
||||
sub: string[];
|
||||
|
||||
option(name: string | [string, string], description: string, defaultValue?: any, init?: OptionInitFunction): args;
|
||||
options(list: Option[]): args;
|
||||
command(name: string, description: string, init?: (name: string, sub: string[], options: ConfigurationOptions) => void, aliases?: string[]): args;
|
||||
example(usage: string, description: string): args;
|
||||
examples(list: Example[]): args;
|
||||
parse(argv: string[], options?: ConfigurationOptions): { [key: string]: any };
|
||||
showHelp(): void;
|
||||
}
|
||||
|
||||
type OptionInitFunction = (value: any) => any;
|
||||
|
||||
interface MriOptions {
|
||||
args?: string[];
|
||||
alias?: {
|
||||
[key: string]: string | string[]
|
||||
};
|
||||
boolean?: string | string[];
|
||||
default?: {
|
||||
[key: string]: any
|
||||
};
|
||||
string?: string | string[];
|
||||
unknown?: (param: string) => boolean;
|
||||
}
|
||||
|
||||
interface MinimistOptions {
|
||||
string?: string | string[];
|
||||
boolean?: boolean | string | string[];
|
||||
alias?: {
|
||||
[key: string]: string | string[]
|
||||
};
|
||||
default?: {
|
||||
[key: string]: any
|
||||
};
|
||||
stopEarly?: boolean;
|
||||
"--"?: boolean;
|
||||
unknown?: (param: string) => boolean;
|
||||
}
|
||||
|
||||
interface ConfigurationOptions {
|
||||
help?: boolean;
|
||||
name?: string;
|
||||
version?: boolean;
|
||||
usageFilter?: (output: any) => any;
|
||||
value?: string;
|
||||
mri: MriOptions;
|
||||
minimist?: MinimistOptions;
|
||||
mainColor: string | string[];
|
||||
subColor: string | string[];
|
||||
}
|
||||
|
||||
interface Option {
|
||||
name: string | [string, string];
|
||||
description: string;
|
||||
init?: OptionInitFunction;
|
||||
defaultValue?: any;
|
||||
}
|
||||
|
||||
interface Example {
|
||||
usage: string;
|
||||
description: string;
|
||||
}
|
||||
23
types/args/tsconfig.json
Normal file
23
types/args/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"args-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/args/tslint.json
Normal file
1
types/args/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user