Skip to content

Commit e82fd42

Browse files
Szpadelmattallty
authored andcommitted
feat: Add Typescript support (#63)
1 parent 64aa520 commit e82fd42

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

index.d.ts

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
declare class Caporal {
2+
INTEGER: number;
3+
INT: number;
4+
FLOAT: number;
5+
BOOL: number;
6+
BOOLEAN: number;
7+
STRING: number;
8+
LIST: number;
9+
ARRAY: number;
10+
REPEATABLE: number;
11+
REQUIRED: number;
12+
13+
version(ver: string): Caporal;
14+
version(): string;
15+
16+
name(name: string): Caporal;
17+
name(): string;
18+
19+
description(name: string): Caporal;
20+
description(): string;
21+
22+
logger(logger: Logger): Caporal;
23+
logger(): Logger;
24+
25+
bin(name: string): Caporal;
26+
bin(): string;
27+
28+
help(helpText: string): Caporal;
29+
30+
command(synospis: string, description: string): Command;
31+
32+
action(cb: ActionCallback): Caporal;
33+
34+
option(synopsis: string, description: string, validator?: ValidatorArg, defaultValue?: any, required?: boolean): Caporal;
35+
36+
argument(synopsis: string, description: string, validator?: ValidatorArg, defaultValue?: any): Command;
37+
38+
parse(argv: string[]): any;
39+
}
40+
41+
type ActionCallback = (args: { [k: string]: any },
42+
options: { [k: string]: any },
43+
logger: Logger) => void;
44+
45+
type ValidatorArg = string[]|string|RegExp|ValidatorFn|Number;
46+
type ValidatorFn = (str: string) => any;
47+
48+
declare interface Logger {
49+
debug(str: string): void;
50+
info(str: string): void;
51+
log(str: string): void;
52+
warn(str: string): void;
53+
error(str: string): void;
54+
}
55+
56+
declare interface Command {
57+
help(helpText: string): Command;
58+
59+
argument(synopsis: string, description: string, validator?: ValidatorArg, defaultValue?: any): Command;
60+
61+
command(synospis: string, description: string): Command;
62+
63+
option(synopsis: string, description: string, validator?: ValidatorArg, defaultValue?: any, required?: boolean): Command;
64+
65+
action(cb: ActionCallback): Command;
66+
67+
alias(alias: string): Command;
68+
69+
complete(cb: AutocompleteCallback): Command;
70+
}
71+
72+
type AutocompleteCallback = () => string[] | Promise<string[]>;
73+
74+
export = new Caporal();

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.7.0",
44
"description": "A full-featured framework for building command line applications (cli) with node.js",
55
"main": "index.js",
6+
"types": "index.d.ts",
67
"scripts": {
78
"lint": "./node_modules/.bin/eslint lib tests",
89
"test": "./node_modules/mocha/bin/mocha --require ./tests/utils/bootstrap.js --full-trace --recursive -R mocha-unfunk-reporter tests/",

0 commit comments

Comments
 (0)