UNPKG

4.23 kBTypeScriptView Raw
1/**
2 * Generates a usage guide suitable for a command-line app.
3 * @param sections One or more Section objects
4 * @alias module:command-line-usage
5 */
6declare function commandLineUsage(sections: commandLineUsage.Section | commandLineUsage.Section[]): string;
7export = commandLineUsage;
8
9declare namespace commandLineUsage {
10 /** Section object. */
11 type Section = Content | OptionList;
12
13 /** A Content section comprises a header and one or more lines of content. */
14 interface Content {
15 /** The section header, always bold and underlined. */
16 header?: string | undefined;
17 /**
18 * Overloaded property, accepting data in one of four formats.
19 * 1. A single string (one line of text).
20 * 2. An array of strings (multiple lines of text).
21 * 3. An array of objects (recordset-style data). In this case, the data will be rendered in table format. The property names of each object are not important, so long as they are
22 * consistent throughout the array.
23 * 4. An object with two properties - data and options. In this case, the data and options will be passed directly to the underlying table layout module for rendering.
24 */
25 content?: string | string[] | any[] | { data: any; options: any } | undefined;
26 /** Set to true to avoid indentation and wrapping. Useful for banners. */
27 raw?: boolean | undefined;
28 }
29
30 /** Describes a command-line option. Additionally, if generating a usage guide with command-line-usage you could optionally add description and typeLabel properties to each definition. */
31 interface OptionDefinition {
32 name: string;
33 /**
34 * The type value is a setter function (you receive the output from this), enabling you to be specific about the type and value received.
35 *
36 * The most common values used are String (the default), Number and Boolean but you can use a custom function.
37 */
38 type?: any;
39 /** getopt-style short option names. Can be any single character (unicode included) except a digit or hyphen. */
40 alias?: string | undefined;
41 /** Set this flag if the option takes a list of values. You will receive an array of values, each passed through the type function (if specified). */
42 multiple?: boolean | undefined;
43 /** Identical to multiple but with greedy parsing disabled. */
44 lazyMultiple?: boolean | undefined;
45 /** Any values unaccounted for by an option definition will be set on the defaultOption. This flag is typically set on the most commonly-used option to make for more concise usage. */
46 defaultOption?: boolean | undefined;
47 /** An initial value for the option. */
48 defaultValue?: any;
49 /**
50 * When your app has a large amount of options it makes sense to organise them in groups.
51 *
52 * There are two automatic groups: _all (contains all options) and _none (contains options without a group specified in their definition).
53 */
54 group?: string | string[] | undefined;
55 /** A string describing the option. */
56 description?: string | undefined;
57 /** A string to replace the default type string (e.g. <string>). It's often more useful to set a more descriptive type label, like <ms>, <files>, <command>, etc.. */
58 typeLabel?: string | undefined;
59 }
60
61 /** A OptionList section adds a table displaying details of the available options. */
62 interface OptionList {
63 header?: string | undefined;
64 /** An array of option definition objects. */
65 optionList?: OptionDefinition[] | undefined;
66 /** If specified, only options from this particular group will be printed. */
67 group?: string | string[] | undefined;
68 /** The names of one of more option definitions to hide from the option list. */
69 hide?: string | string[] | undefined;
70 /** If true, the option alias will be displayed after the name, i.e. --verbose, -v instead of -v, --verbose). */
71 reverseNameOrder?: boolean | undefined;
72 /** An options object suitable for passing into table-layout. */
73 tableOptions?: any;
74 }
75}