|
50 | 50 | - [`Command#done([done])`](#commanddonedone) |
51 | 51 | - [`Command#emit(event)`](#commandemitevent) |
52 | 52 | - [`Command#emitOption(option, value, source[, flags])`](#commandemitoptionoption-value-source-flag) |
| 53 | + - [`Command#example(info[, prefix])`](#commandexampleinfo-prefix) |
| 54 | + - [`Command#examples([examples])`](#commandexamplesexamples) |
53 | 55 | - [`Command#error(info)`](#commanderrorinfo) |
54 | 56 | - [`Command#exit([e])`](#commandexite) |
55 | 57 | - [`Command#exiter([exit])`](#commandexiterexit) |
|
149 | 151 | - [`CommandSnapshot`](#commandsnapshot-1) |
150 | 152 | - [`DefaultInfo`](#defaultinfo) |
151 | 153 | - [`EmptyString`](#emptystring) |
| 154 | + - [`ExampleInfo`](#exampleinfo) |
| 155 | + - [`ExamplesData`](#examplesdata) |
152 | 156 | - [`ExitCode`](#exitcode) |
153 | 157 | - [`ExitProcess`](#exitprocess) |
154 | 158 | - [`Exit`](#exit) |
@@ -729,6 +733,46 @@ Display an error message and exit. |
729 | 733 |
|
730 | 734 | (`never`) Never, exits erroneously |
731 | 735 |
|
| 736 | +#### `Command#example(info[, prefix])` |
| 737 | + |
| 738 | +Add an example for the command. |
| 739 | + |
| 740 | +> 👉 **Note**: This method can be called more than once to add multiple examples. |
| 741 | +
|
| 742 | +##### Overloads |
| 743 | + |
| 744 | +- `example(info: ExampleInfo | string): this` |
| 745 | +- `example(info: string, prefix?: string | null | undefined): this` |
| 746 | + |
| 747 | +##### Parameters |
| 748 | + |
| 749 | +- `info` ([`ExampleInfo`](#exampleinfo) | `string`) |
| 750 | + — example info or text |
| 751 | +- `prefix` (`string` | `null` | `undefined`) |
| 752 | + — the example text prefix |
| 753 | + |
| 754 | +##### Returns |
| 755 | + |
| 756 | +([`this`](#commandinfo)) `this` command |
| 757 | + |
| 758 | +#### `Command#examples([examples])` |
| 759 | + |
| 760 | +Get or add examples for the command. |
| 761 | + |
| 762 | +##### Overloads |
| 763 | + |
| 764 | +- `examples(examples: ExamplesData | null | undefined): this` |
| 765 | +- `examples(): ExampleInfo[]` |
| 766 | + |
| 767 | +##### Parameters |
| 768 | + |
| 769 | +- `examples` ([`ExamplesData`](#examplesdata) | `null` | `undefined`) |
| 770 | + — example info, example text, or a list of such |
| 771 | + |
| 772 | +##### Returns |
| 773 | + |
| 774 | +([`ExampleInfo[]`](#exampleinfo) | [`this`](#commandinfo)) List of examples or `this` command |
| 775 | + |
732 | 776 | #### `Command#exit([e])` |
733 | 777 |
|
734 | 778 | Exit the process. |
@@ -2029,6 +2073,8 @@ Command metadata (TypeScript interface). |
2029 | 2073 | — list of command aliases |
2030 | 2074 | - `arguments` ([`Argument[]`](#argumentinfo)) |
2031 | 2075 | — list of command arguments |
| 2076 | +- `examples` ([`ExampleInfo[]`](#exampleinfo)) |
| 2077 | + — list of command examples |
2032 | 2078 | - `helpOption` ([`Option`](#optioninfo) | `null` | `undefined`) |
2033 | 2079 | — the help option |
2034 | 2080 | - `options` ([`Map<string, Option>`](#optioninfo)) |
@@ -2097,6 +2143,25 @@ An empty string (TypeScript type). |
2097 | 2143 | type EmptyString = '' |
2098 | 2144 | ``` |
2099 | 2145 |
|
| 2146 | +### `ExampleInfo` |
| 2147 | +
|
| 2148 | +Command example info (TypeScript interface). |
| 2149 | +
|
| 2150 | +#### Properties |
| 2151 | +
|
| 2152 | +- `prefix?` (`string`, optional) |
| 2153 | + — the example text prefix |
| 2154 | +- `text` (`string`) |
| 2155 | + — the example text |
| 2156 | +
|
| 2157 | +### `ExamplesData` |
| 2158 | +
|
| 2159 | +Union of types used to configure command examples (TypeScript type). |
| 2160 | +
|
| 2161 | +```ts |
| 2162 | +type ExamplesData = ExampleInfo | List<ExampleInfo | string> | string |
| 2163 | +``` |
| 2164 | +
|
2100 | 2165 | ### `ExitCode` |
2101 | 2166 |
|
2102 | 2167 | Union of exit status code types (TypeScript type). |
|
0 commit comments