massarg 1.0.7-pre.1 → 2.0.0-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,70 +1,19 @@
1
- # Massarg
1
+ # massarg
2
2
 
3
- Massarg is a simple-to-use, beautiful, flexible, and powerful command/argument parser for JS
3
+ Massarg is a beautiful, flexible, powerful, and simple-to-use command/argument parser for JS
4
4
  applications, allowing you to create complex but easy applications that consume command-line
5
5
  arguments and commands.
6
6
 
7
- Yes, there are a lot of arg parsers. But hear us out.
8
-
9
- <details>
10
- <summary>Table of contents</summary>
11
-
12
- - [Massarg](#massarg)
13
- - [Features](#features)
14
- - [Usage](#usage)
15
- - [Quick Start](#quick-start)
16
- - [Installing](#installing)
17
- - [Importing](#importing)
18
- - [Using](#using)
19
- - [Main command](#main-command)
20
- - [Example](#example)
21
- - [JS/TS](#jsts)
22
- - [Shell](#shell)
23
- - [Commands](#commands)
24
- - [Options](#options)
25
- - [Example](#example-1)
26
- - [JS/TS](#jsts-1)
27
- - [Shell](#shell-1)
28
- - [Options](#options-1)
29
- - [Options](#options-2)
30
- - [Example](#example-2)
31
- - [JS/TS](#jsts-2)
32
- - [Shell](#shell-2)
33
- - [Example Lines](#example-lines)
34
- - [Options](#options-3)
35
- - [Example](#example-3)
36
- - [JS/TS](#jsts-3)
37
- - [Help/Usage Command](#helpusage-command)
38
- - [Options](#options-4)
39
- - [Example](#example-4)
40
- - [JS/TS](#jsts-4)
41
- - [Shell output](#shell-output)
42
- - [Contributing](#contributing)
43
- <!-- - [Example](#example) -->
44
- <!-- - [JS/TS](#jsts) -->
45
- <!-- - [Shell](#shell) -->
46
- - [Commands](#commands)
47
- - [Options](#options)
48
- - [Example](#example-1)
49
- - [JS/TS](#jsts-1)
50
- - [Shell](#shell-1)
51
- - [Options](#options-1)
52
- - [Options](#options-2)
53
- - [Example](#example-2)
54
- - [JS/TS](#jsts-2)
55
- - [Shell](#shell-2)
56
- - [Example Lines](#example-lines)
57
- - [Options](#options-3)
58
- - [Example](#example-3)
59
- - [JS/TS](#jsts-3)
60
- - [Help/Usage Command](#helpusage-command)
61
- - [Options](#options-4)
62
- - [Example](#example-4)
63
- - [JS/TS](#jsts-4)
64
- - [Shell output](#shell-output)
65
- - [Contributing](#contributing)
66
-
67
- </details>
7
+ It allows you to both parse argument options and flags, as well as hierarchal subcommands, both of
8
+ which can be parsed into an automatic help command or flag that displays all the information easily,
9
+ with customizable styles, and content.
10
+
11
+ You should only focus on actually writing the functionality of your CLI, and not waste it on writing
12
+ a way to parse the chain of commands, flags or options.
13
+
14
+ And it should look good too, right?
15
+
16
+ ![colored shell output](https://user-images.githubusercontent.com/167217/126086652-433a523f-2f0a-427c-b58a-18b2131489f4.png)
68
17
 
69
18
  ## Features
70
19
 
@@ -87,23 +36,24 @@ Yes, there are a lot of arg parsers. But hear us out.
87
36
 
88
37
  ## Quick Start
89
38
 
90
- ### Installing
39
+ ### Install
91
40
 
92
41
  ```shell
42
+ # pnpm
43
+ pnpm install massarg
93
44
  # npm
94
- npm install --save massarg
45
+ npm install massarg
95
46
  # yarn
96
47
  yarn add massarg
97
48
  ```
98
49
 
99
- ### Importing
50
+ ### Import
100
51
 
101
- ```typescript
102
- import massarg from "massarg" // import init function (returns massarg instance)
103
- import { Massarg } from "massarg" // import class
52
+ ```ts
53
+ import massarg from 'massarg'
104
54
  ```
105
55
 
106
- ### Using
56
+ ### Usage
107
57
 
108
58
  Call the default export function `massarg`, or create a new instance manually using `new Massarg()`,
109
59
  and then you can start chaining commands. Use `.parse()` to do the final parsing and run the
@@ -112,30 +62,53 @@ commands and options.
112
62
  Here is an example with some commonly used examples to get you started. Keep reading for a complete
113
63
  documentation of every option.
114
64
 
115
- ```typescript
116
- massarg() // or: new Massarg()
117
- .main((options) => console.log("main command", options))
65
+ ```ts
66
+ const parser = massarg({
67
+ name: 'my-cli',
68
+ description: "Does really amazing stuff, you wouldn't believe!",
69
+ }) // or: new Massarg()
70
+ .main((options) => console.log('main command', options))
118
71
  .command({
119
- name: "sub",
120
- description: "a sub command",
121
- aliases: ["s"],
122
- run: (options) => console.log("sub command", options),
72
+ name: 'foo',
73
+ description: 'a sub command',
74
+ aliases: ['f'],
75
+ run: (options) => console.log('foo command'),
123
76
  })
77
+ .command(
78
+ massarg({
79
+ name: 'bar',
80
+ description: 'another sub command',
81
+ aliases: ['s'],
82
+ run: (options) => console.log('bar command', options),
83
+ }).option({
84
+ name: 'file',
85
+ description: 'Filename to use',
86
+ aliases: ['f'],
87
+ parse: (filename) => path.resolve(process.cwd(), filename),
88
+ }),
89
+ )
124
90
  .option({
125
- name: "flag",
126
- description: "a flag that will be related to any command (main or sub)",
127
- aliases: ["f"],
128
- boolean: true,
91
+ name: 'my-string',
92
+ description: 'A string argument',
93
+ aliases: ['s'],
129
94
  })
130
- .option({
131
- name: "command-specific-flag",
132
- description: "a flag that will be related to only the 'sub' command",
133
- commands: ["sub"],
134
- parse: (v) => parseInt(v),
95
+ .flag({
96
+ name: 'flag',
97
+ description: 'a flag that will be related to any command (main or sub)',
98
+ aliases: ['f'],
99
+ })
100
+ .example({
101
+ description: 'Run the sub command',
102
+ input: 'my-bin --flag sub',
103
+ output: 'Sub command: flag is true',
135
104
  })
136
105
  .help({
137
- binName: "my-cli-app",
138
- footer: "Copyright © 2021 Me, Myself and I",
106
+ bindCommand: true,
107
+ footerText: `Copyright © ${new Date().getFullYear()} Me, Myself and I`,
108
+ titleStyle: {
109
+ bold: true,
110
+ color: 'brightWhite',
111
+ },
139
112
  })
140
113
  ```
141
114
 
@@ -143,13 +116,15 @@ massarg() // or: new Massarg()
143
116
 
144
117
  The main command is the one that runs when you supply no other commands.
145
118
 
119
+ If no command is specified, and no main command is present, the help usage is automatically printed.
120
+
146
121
  ### Example
147
122
 
148
123
  #### JS/TS
149
124
 
150
- ```typescript
151
- massarg().main((options) => {
152
- console.log("Parsed options:", options)
125
+ ```ts
126
+ parser.main((options) => {
127
+ console.log('Parsed options:', options)
153
128
  // do stuff
154
129
  })
155
130
  ```
@@ -161,38 +136,38 @@ $ ./mybin
161
136
  # Main command runs without options
162
137
 
163
138
  $ ./mybin --my-string "Some string"
164
- # Main command runs with option { myString: "Some string" }
139
+ # Main command runs with options { myString: "Some string" }
140
+
141
+ $ ./mybin foo
142
+ # Foo sub command run with options {}
165
143
  ```
166
144
 
167
145
  ## Commands
168
146
 
169
147
  Commands are activated when their keyword is included in the args. The first command that matches
170
- will be executed, skipping the rest. Options will still be parsed.
171
-
172
- Any arguments that are not taken by options or commands, are automatically passed to
173
- `options.extra`, which you can access when running a command or when using the return value from
174
- `parseArgs()`.
148
+ will be executed, skipping the rest. Options before will be parsed on the main parser, while
149
+ anything after the command will be parsed for that subcommand only.
175
150
 
176
151
  ### Options
177
152
 
178
- | Name (required*) | Type | Example | Description |
179
- | ---------------- | --------------------------- | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
180
- | `name`* | `string` | `"my-command"` | The name of the command, which will be used in the CLI to trigger it |
181
- | `aliases` | `string[]` | `["m", "mc"]` | Alternate names for the command, available for use in addition to `name` |
182
- | `description` | `string` | `"Description of the command"` | Description for the command, only displayed with `--help` or `printHelp()` |
183
- | `run`* | `function(options) => void` | `(options) => console.log("my-command", options)` | Main function that runs this command. The supplied argument is the options passed via the CLI and parsed by massarg. |
153
+ | Name | Type | Required | Example | Description |
154
+ | ------------- | ----------------------------------- | -------- | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
155
+ | `name` | `string` | ✅ | `"my-command"` | The name of the command, which will be used in the CLI to trigger it |
156
+ | `aliases` | `string[]` | | `["m", "mc"]` | Alternate names for the command, available for use in addition to `name` |
157
+ | `description` | `string` | | `"Description of the command"` | Description for the command, only displayed with `--help` or `printHelp()` |
158
+ | `run` | `function(options, parser) => void` | ✅ | `(options) => console.log("my-command", options)` | Main function that runs this command. The supplied argument is the options passed via the CLI and parsed by massarg. |
184
159
 
185
160
  ### Example
186
161
 
187
162
  #### JS/TS
188
163
 
189
- ```typescript
190
- massarg().command({
191
- name: "do-something",
192
- description: "This command does something",
193
- aliases: ["do", "d"],
164
+ ```ts
165
+ parser.command({
166
+ name: 'do-something',
167
+ description: 'This command does something',
168
+ aliases: ['do', 'd'],
194
169
  run: (options) => {
195
- console.log("Parsed options:", options)
170
+ console.log('Parsed options:', options)
196
171
  // do stuff
197
172
  },
198
173
  })
@@ -211,57 +186,35 @@ $ ./mybin my-command --my-string "Some string"
211
186
  ## Options
212
187
 
213
188
  Options are variables you can accept via CLI and parse to use in your commands, e.g. `--my-bool`,
214
- `--no-my-bool`, `--my-string string`, `--my-number 1`
189
+ `--my-string string`, `--my-number 1`.
215
190
 
216
- Any arguments that are not taken by options or commands, are automatically passed to
217
- `options.extra`, which you can access when running a command or when using the return value from
218
- `parseArgs()`.
191
+ Aliases use the shorthand syntax, as such: `-s string`, `-n 1`.
219
192
 
220
193
  ### Options
221
194
 
222
- | Name (required*) | Type | Example | Description |
223
- | ------------------------------ | --------------------------------- | ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
224
- | `name`* | `string` | `"my-number"` | The name of the option, which will be used in the CLI to apply it. |
225
- | `aliases` | `string[]` | `["n"]` | Alternate names for the option, available for use in addition to `name`. |
226
- | `description` | `string` | `"Description of the command"` | Description for the command, only displayed with `--help` or `printHelp()`. |
227
- | `parse` (default: `String`) | `function(value, options) => any` | `(value, options) => parseInt(value)` | Function that parses this option. The supplied arguments are the string value from the arg, and other options passed via the CLI and parsed by massarg before this one. Not all options will be available. |
228
- | `isDefault` (default: `false`) | `boolean` | | When `true`, any args placed without name will be applied to this option. When more than one arg is supplied this way, only the last given will be used (unless the option is an array type). |
229
- | `boolean` (default: `false`) | `boolean` | | When set to `true`, this option will be treated as a boolean: will accept no value as `true`, or other truthy\* values as `true`, and the rest as `false`. They also have special flags that define negation.\*\* |
230
- | `array` (default: `false`) | `boolean` | | When set to true, you will be able to take multiple values when using the same option more than once. They will all be parsed properly and put into an array. |
231
- | `required` (default: `false`) | `boolean` | | When an option is required, parsing will throw a `RequiredError` if it was not given a proper value. If it is attached to a specific (or several) commands, it will only throw if the relevant command was used. |
232
-
233
- \* In boolean args, truthy values are considered true if they fit one of the following values: `1`,
234
- `true`, `yes`, `on`. Anything else is considered falsy.
235
-
236
- \*\* Boolean args will also have special negation flags that allow passing a `false` value by using
237
- a variation of the name or alias as a flag and still without supplying a value. The following will
238
- work for true, given `name: 'bool', aliases: ['b']`: `--bool`, `-b`, and the following will work for
239
- `false`: `--no-bool`, `-!b`. `--bool` and `-b` may still be supplied a truthy/falsy value separately
240
- in order to determine their value. Note it might cause unpredicted behavior when combining with
241
- options that have default values that are passed directly afterwards.
195
+ | Name | Type | Required | Default | Example | Description |
196
+ | ------------- | --------------------------------- | -------- | ------------------ | ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
197
+ | `name` | `string` | ✅ | | `"my-number"` | The name of the option, which will be used in the CLI to apply it |
198
+ | `aliases` | `string[]` | | | `["n"]` | Alternate names for the option, available for use in addition to `name` |
199
+ | `description` | `string` | | | `"Description of the command"` | Description for the command, only displayed with `--help` or `printHelp()` |
200
+ | `parse` | `function(value, options) => any` | | `(s) => String(s)` | `(value, options) => parseInt(value)` | Function that parses this option. The supplied arguments are the string value from the arg, and other options passed via the CLI and parsed by massarg before this one. Not all options will be available. |
201
+ | `isDefault` | `boolean` | | `false` | | When `true`, any args placed without name will be applied to this option. When more than one arg is supplied this way, only the last given will be used (unless the option is an array type). |
202
+ | `array` | `boolean` | | `false` | | When set to true, you will be able to take multiple values when using the same option more than once. They will all be parsed properly and put into an array. |
203
+ | `required` | `boolean` | | `false` | | When an option is required, parsing will throw a `RequiredError` if it was not given a proper value. If it is attached to a specific (or several) commands, it will only throw if the relevant command was used. |
242
204
 
243
205
  ### Example
244
206
 
245
207
  #### JS/TS
246
208
 
247
- ```typescript
248
- massarg()
249
- .option({
250
- name: "bool",
251
- aliases: ["b"],
252
- defaultValue: false,
253
- commands: ["my-command"],
254
- description: "This is a boolean arg. Supply it without value or with 1 to set as true, or set value 0 for false",
255
- parse: Boolean,
256
- })
257
- .option({
258
- name: "number",
259
- aliases: ["n"],
260
- description: "This is a number arg, if you include this option, you must supply it with a numeric value.",
261
- defaultValue: 0,
262
- commands: "do",
263
- parse: (v) => parseInt(v),
264
- })
209
+ ```ts
210
+ parser.option({
211
+ name: 'number',
212
+ aliases: ['n'],
213
+ description:
214
+ 'This is a number arg, if you include this option, you must supply it with a numeric value.',
215
+ defaultValue: 0,
216
+ parse: (v) => parseInt(v),
217
+ })
265
218
  ```
266
219
 
267
220
  #### Shell
@@ -284,21 +237,21 @@ atop as titles, if specified.
284
237
 
285
238
  ### Options
286
239
 
287
- | Name (required*) | Type | Default | Example | Description |
288
- | ---------------- | -------- | ------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
289
- | `input`* | `string` | | `"my-cmd --number 10"` | The input line, an example of user input that will be displayed as "shell" commands. The prefix is customizable through the `help()` options. |
290
- | `output` | `string` | | `"you entered my-cmd with the number 10, which is larger than 5"` | The output line, an example of the command's output that will be displayed as "shell" output. The prefix is customizable through the `help()` options. |
291
- | `description` | `string` | | `"Run the my-cmd command with a number parameter"` | An explanation of the input/output that will be display as a title above the input if specified. |
240
+ | Name | Type | Required | Default | Example | Description |
241
+ | ------------- | -------- | -------- | ------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
242
+ | `input` | `string` | ✅ | | `"my-cmd --number 10"` | The input line, an example of user input that will be displayed as "shell" commands. The prefix is customizable through the `help()` options. |
243
+ | `output` | `string` | ✅ | | `"you entered my-cmd with the number 10, which is larger than 5"` | The output line, an example of the command's output that will be displayed as "shell" output. The prefix is customizable through the `help()` options. |
244
+ | `description` | `string` | | | `"Run the my-cmd command with a number parameter"` | An explanation of the input/output that will be display as a title above the input if specified. |
292
245
 
293
246
  ### Example
294
247
 
295
248
  #### JS/TS
296
249
 
297
- ```typescript
298
- massarg().example({
299
- input: "my-cmd --number 10",
300
- output: "you entered my-cmd with the number 10, which is larger than 5",
301
- description: "Run the my-cmd command with a number parameter",
250
+ ```ts
251
+ parser.example({
252
+ input: 'my-cmd --number 10',
253
+ output: 'you entered my-cmd with the number 10, which is larger than 5',
254
+ description: 'Run the my-cmd command with a number parameter',
302
255
  })
303
256
  ```
304
257
 
@@ -331,57 +284,21 @@ you may override their defaults to modify the behavior.
331
284
 
332
285
  #### JS/TS
333
286
 
334
- ```typescript
335
- massarg().help({
287
+ ```ts
288
+ parser.help({
336
289
  printWidth: 80,
337
- binName: "my-app",
338
- normalColors: "dim",
339
- highlightColors: "yellow",
340
- titleColors: "white",
341
- subtitleColors: ["bold", "dim"],
342
- header: "Header text",
343
- footer: "Footer text",
344
- commandNameSeparator: " | ",
345
- optionNameSeparator: "|",
290
+ binName: 'my-app',
291
+ normalColors: 'dim',
292
+ highlightColors: 'yellow',
293
+ titleColors: 'white',
294
+ subtitleColors: ['bold', 'dim'],
295
+ header: 'Header text',
296
+ footer: 'Footer text',
297
+ commandNameSeparator: ' | ',
298
+ optionNameSeparator: '|',
346
299
  useGlobalColumns: true,
347
- usageExample: "command [option]",
300
+ usageExample: 'command [option]',
348
301
  })
349
302
  ```
350
303
 
351
304
  #### Shell output
352
-
353
- ![colored shell output](https://user-images.githubusercontent.com/167217/126086652-433a523f-2f0a-427c-b58a-18b2131489f4.png)
354
-
355
- ## Contributing
356
-
357
- I am developing this package on my free time, so any support, whether code, issues, or just stars
358
- is very helpful to sustaining its life. If you would like to donate a bit to help keep the project
359
- alive, I would be very thankful!
360
-
361
- <a href='https://ko-fi.com/casraf' target='_blank'>
362
- <img height='36' style='border:0px;height:36px;'
363
- src='https://cdn.ko-fi.com/cdn/kofi1.png?v=3'
364
- alt='Buy Me a Coffee at ko-fi.com' />
365
- </a>
366
-
367
- I welcome any issues or pull requests on GitHub. If you find a bug, or would like a new feature,
368
- don't hesitate to open an appropriate issue and I will do my best to reply promptly.
369
-
370
- If you are a developer and want to contribute code, here are some starting tips:
371
-
372
- 1. Fork this repository
373
- 2. Run `yarn install`
374
- 3. Run `yarn develop` to start file watch mode
375
- 4. Make any changes you would like
376
- 5. Create tests for your changes
377
- 6. Update the relevant documentation (readme, code comments, type comments)
378
- 7. Create a PR on upstream
379
-
380
- Some tips on getting around the code:
381
-
382
- - Use `yarn dev` for development - it runs TypeScript compile in watch mode, allowing you to make
383
- changes and immediately be able to try them using `yarn cmd`.
384
- - Use `yarn build` to build the output
385
- - Use `yarn test` to run tests
386
- - While `yarn develop` is running, you may run `yarn sample` (try running with `-h` flag) to see
387
- a sample script using massarg, that logs the parsed options with the correct parsers and runners.
package/command.d.ts ADDED
@@ -0,0 +1,153 @@
1
+ import { z } from 'zod';
2
+ import { HelpConfig } from './help';
3
+ import { MassargOption, MassargFlag, OptionConfig, TypedOptionConfig } from './option';
4
+ import { DeepRequired } from './utils';
5
+ import { MassargExample, ExampleConfig } from './example';
6
+ export declare const CommandConfig: <RunArgs extends z.ZodType<any, z.ZodTypeDef, any>>(args: RunArgs) => z.ZodObject<{
7
+ /** Command name */
8
+ name: z.ZodString;
9
+ /** Command description, displayed in the help output */
10
+ description: z.ZodString;
11
+ /** Command aliases */
12
+ aliases: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
13
+ /**
14
+ * Function used when invoking this command. It receives the parsed options and the primary
15
+ * instance of Massarg used to invoke this command (the top-level instance)
16
+ */
17
+ run: z.ZodType<Runner<z.TypeOf<RunArgs>>, z.ZodTypeDef, Runner<z.TypeOf<RunArgs>>>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ description: string;
20
+ name: string;
21
+ run: Runner<z.TypeOf<RunArgs>>;
22
+ aliases?: string[] | undefined;
23
+ }, {
24
+ description: string;
25
+ name: string;
26
+ run: Runner<z.TypeOf<RunArgs>>;
27
+ aliases?: string[] | undefined;
28
+ }>;
29
+ export type CommandConfig<T = unknown> = z.infer<ReturnType<typeof CommandConfig<z.ZodType<T>>>>;
30
+ export type ArgsObject = Record<string, unknown>;
31
+ export type Runner<Args extends ArgsObject> = <A extends ArgsObject = Args>(options: A, instance: MassargCommand<A>) => Promise<void> | void;
32
+ /**
33
+ * A command is a named function that can be invoked with a set of options.
34
+ *
35
+ * Commands can have sub-commands, which can have their own sub-commands, and so on.
36
+ *
37
+ * Options are not inherited by sub-commands, but their parsed values are passed down when
38
+ * invoking a sub-command. This works recursively.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * massarg(options).command({
43
+ * name: 'foo',
44
+ * description: 'foo command',
45
+ * run: (options, instance) => {
46
+ * console.log(options, instance)
47
+ * },
48
+ * })
49
+ * ```
50
+ */
51
+ export declare class MassargCommand<Args extends ArgsObject = ArgsObject> {
52
+ name: string;
53
+ description: string;
54
+ aliases: string[];
55
+ private _run?;
56
+ commands: MassargCommand<any>[];
57
+ options: MassargOption[];
58
+ examples: MassargExample[];
59
+ args: Partial<Args>;
60
+ private _helpConfig;
61
+ parent?: MassargCommand<any>;
62
+ constructor(options: CommandConfig<Args>, parent?: MassargCommand<any>);
63
+ get helpConfig(): DeepRequired<HelpConfig>;
64
+ /**
65
+ * Add a sub-command to this command.
66
+ *
67
+ * The sub-command will inherit all help configuration from the parent commands,
68
+ * all the way up to the top-level command.
69
+ *
70
+ * While options are not inherited, they will be passed from any parent commands
71
+ * to the sub-command when invoked.
72
+ */
73
+ command<A extends ArgsObject = Args>(config: CommandConfig<A>): MassargCommand<Args>;
74
+ command<A extends ArgsObject = Args>(config: MassargCommand<A>): MassargCommand<Args>;
75
+ /**
76
+ * Adds a flag to this command.
77
+ *
78
+ * A flag is an option that is either present or not. It can be used to toggle
79
+ * a boolean value, or to indicate that a command should be run in a different
80
+ * mode.
81
+ *
82
+ * A flag can be negated by prefixing it with `no-`. For example, `--no-verbose`,
83
+ * or by prefixing the alias with `^` instead of `-`. This is configurable via the command's
84
+ * configuration.
85
+ */
86
+ flag(config: Omit<OptionConfig<boolean>, 'parse' | 'isDefault'>): MassargCommand<Args>;
87
+ flag(config: MassargFlag): MassargCommand<Args>;
88
+ /**
89
+ * Adds an option to this command.
90
+ *
91
+ * An option is a named value that can be passed to a command. It can be
92
+ * required or optional, and can be of any type.
93
+ *
94
+ * You can specify a default value for an option, which will be used if the
95
+ * option is not passed to the command.
96
+ *
97
+ * You can also specify a parse function, which will be used to parse the
98
+ * value passed to the command. This is useful if you want to parse a string
99
+ * into a more complex type, or if you want to validate the value.
100
+ */
101
+ option<T = string>(config: MassargOption<T>): MassargCommand<Args>;
102
+ option<T = string>(config: TypedOptionConfig<T>): MassargCommand<Args>;
103
+ /**
104
+ * Adds an example to this command.
105
+ *
106
+ * An example is a description of how to use the command, with an example input and output.
107
+ *
108
+ * At least one of `description`, `input` or `output` must be provided, but neither alone is
109
+ * required.
110
+ */
111
+ example(config: ExampleConfig): MassargCommand<Args>;
112
+ /**
113
+ * Configure the help output for this (and all child) commands.
114
+ *
115
+ * You can automatically bind the help command to this command, and/or bind the help option
116
+ * to this command.
117
+ *
118
+ * If you don't opt-in to this behavior with `bindCommand` or `bindOption`, you can still
119
+ * access the help output via `this.helpString()` and `this.printHelp()`.
120
+ */
121
+ help(config: HelpConfig): MassargCommand<Args>;
122
+ /**
123
+ * Configure the main function for this command. This command will run when no sub-commands
124
+ * are provided.
125
+ *
126
+ * If none is provided, help will be printed.
127
+ */
128
+ main<A extends ArgsObject = Args>(run: Runner<A>): MassargCommand<Args>;
129
+ /**
130
+ * Parse the given arguments and run the command or sub-commands along with the given options
131
+ * and flags.
132
+ *
133
+ * To parse the arguments without running any commands and only get the output args,
134
+ * use `getArgs` instead.
135
+ */
136
+ parse(argv: string[], args?: Partial<Args>, parent?: MassargCommand<Args>): Promise<void> | void;
137
+ private parseOption;
138
+ /** Parse the given arguments and return the output args. */
139
+ getArgs(argv: string[], __args?: Partial<Args>, parent?: MassargCommand<any>, parseCommands?: false): Promise<void> | void;
140
+ getArgs(argv: string[], __args?: Partial<Args>, parent?: MassargCommand<any>, parseCommands?: true): Args;
141
+ /**
142
+ * Generate the help output for this command, and return it as a string.
143
+ */
144
+ helpString(): string;
145
+ /**
146
+ * Print the help output for this command.
147
+ */
148
+ printHelp(): void;
149
+ }
150
+ export declare class MassargHelpCommand<T extends ArgsObject = ArgsObject> extends MassargCommand<T> {
151
+ constructor(config?: Partial<Omit<CommandConfig<T>, 'run'>>);
152
+ }
153
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAqB,UAAU,EAAiB,MAAM,QAAQ,CAAA;AACrE,OAAO,EACL,aAAa,EACb,WAAW,EACX,YAAY,EACZ,iBAAiB,EAElB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,YAAY,EAAwB,MAAM,SAAS,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAEzD,eAAO,MAAM,aAAa;IAEtB,mBAAmB;;IAEnB,wDAAwD;;IAExD,sBAAsB;;IAEtB;;;OAGG;;;;;;;;;;;;EAKH,CAAA;AAEJ,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAEhG,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEhD,MAAM,MAAM,MAAM,CAAC,IAAI,SAAS,UAAU,IAAI,CAAC,CAAC,SAAS,UAAU,GAAG,IAAI,EACxE,OAAO,EAAE,CAAC,EACV,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,KACxB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAEzB;;;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