UNPKG

2.04 kBTypeScriptView Raw
1// Type definitions for sade 1.7
2// Project: https://github.com/lukeed/sade#readme
3// Definitions by: Epimodev <https://github.com/Epimodev>
4// Piotr Błażejewicz <https://github.com/peterblazejewicz>
5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
7import * as mri from 'mri';
8
9/**
10 * Sade is a small but powerful tool for building command-line interface (CLI) applications for Node.js that are fast, responsive, and helpful!
11 * It enables default commands, git-like subcommands, option flags with aliases, default option values with type-casting,
12 * required-vs-optional argument handling, command validation, and automated help text generation!
13 */
14declare namespace sade {
15 type Handler = (...args: any[]) => any;
16
17 interface CommandOptions {
18 /**
19 * Optionally define one or more aliases for the current Command.
20 * When declared, the `opts.alias` value is passed directly to the [`prog.alias`](#progaliasnames) method.
21 */
22 alias?: string | string[] | undefined;
23 default?: boolean | undefined;
24 }
25
26 interface ParseOptions extends mri.Options {
27 lazy?: boolean | undefined;
28 }
29
30 interface LazyOutput {
31 name: string;
32 handler: Handler;
33 args: string[];
34 }
35
36 interface Sade {
37 /**
38 * Define one or more aliases for the current Command.
39 */
40 alias(...names: string[]): Sade;
41 command(str: string, desc?: string, opts?: Readonly<CommandOptions>): Sade;
42 describe(str: string | ReadonlyArray<string>): Sade;
43 option(str: string, desc: string, val?: string | number | boolean): Sade;
44 action(handler: Handler): Sade;
45 example(str: string): Sade;
46 version(str: string): Sade;
47 help(str: string): void;
48
49 parse(arr: string[], opts: { lazy: true } & ParseOptions): LazyOutput;
50 parse(arr: string[], opts?: ParseOptions): void;
51 }
52}
53
54declare function sade(str: string, isOne?: boolean): sade.Sade;
55
56export = sade;