massarg 2.0.0-pre.1 → 2.0.0-pre.11
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 +42 -190
- package/command.d.ts +51 -22
- package/command.d.ts.map +1 -1
- package/command.js +169 -85
- package/command.js.map +1 -1
- package/error.d.ts +13 -11
- package/error.d.ts.map +1 -1
- package/error.js +1 -1
- package/error.js.map +1 -1
- package/example.js.map +1 -1
- package/help.d.ts +361 -63
- package/help.d.ts.map +1 -1
- package/help.js +159 -61
- package/help.js.map +1 -1
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -1
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/massarg.d.ts +14 -2
- package/massarg.d.ts.map +1 -1
- package/massarg.js +12 -0
- package/massarg.js.map +1 -1
- package/option.d.ts +140 -44
- package/option.d.ts.map +1 -1
- package/option.js +101 -66
- package/option.js.map +1 -1
- package/package.json +12 -12
- package/style.d.ts +1 -0
- package/style.d.ts.map +1 -1
- package/style.js +7 -4
- package/style.js.map +1 -1
- package/utils.d.ts +7 -5
- package/utils.d.ts.map +1 -1
- package/utils.js +20 -9
- package/utils.js.map +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# massarg
|
|
2
2
|
|
|
3
|
-
Massarg is a
|
|
3
|
+
Massarg is a modern, 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
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
|
|
9
|
-
with customizable styles, and content.
|
|
8
|
+
which can be parsed into an **automatic help command or flag** that displays all the information
|
|
9
|
+
easily, with customizable styles, and content.
|
|
10
10
|
|
|
11
11
|
You should only focus on actually writing the functionality of your CLI, and not waste it on writing
|
|
12
12
|
a way to parse the chain of commands, flags or options.
|
|
@@ -59,21 +59,32 @@ Call the default export function `massarg`, or create a new instance manually us
|
|
|
59
59
|
and then you can start chaining commands. Use `.parse()` to do the final parsing and run the
|
|
60
60
|
commands and options.
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
documentation
|
|
62
|
+
Each function and option is documented. See
|
|
63
|
+
[the full documentation](https://chenasraf.github.io/massarg) for details.
|
|
64
|
+
|
|
65
|
+
JSDoc comments are also provided.
|
|
66
|
+
|
|
67
|
+
Here is an example with some commonly used examples to get you started.
|
|
64
68
|
|
|
65
69
|
```ts
|
|
66
70
|
const parser = massarg({
|
|
67
71
|
name: 'my-cli',
|
|
68
72
|
description: "Does really amazing stuff, you wouldn't believe!",
|
|
69
73
|
}) // or: new Massarg()
|
|
74
|
+
// The main command - runs when no commands are specified. If not provided, an error is thrown for
|
|
75
|
+
// required arguments.
|
|
70
76
|
.main((options) => console.log('main command', options))
|
|
77
|
+
// A subcommand example
|
|
71
78
|
.command({
|
|
72
79
|
name: 'foo',
|
|
73
80
|
description: 'a sub command',
|
|
74
81
|
aliases: ['f'],
|
|
75
|
-
|
|
82
|
+
optionPrefix: '--',
|
|
83
|
+
aliasPrefix: '-',
|
|
84
|
+
run: (options) => console.log('foo command'), // The function to run
|
|
76
85
|
})
|
|
86
|
+
// A subcommand example, which contains its own set of options or sub commands. This is infinitely
|
|
87
|
+
// nestible.
|
|
77
88
|
.command(
|
|
78
89
|
massarg({
|
|
79
90
|
name: 'bar',
|
|
@@ -87,21 +98,28 @@ const parser = massarg({
|
|
|
87
98
|
parse: (filename) => path.resolve(process.cwd(), filename),
|
|
88
99
|
}),
|
|
89
100
|
)
|
|
101
|
+
// A CLI option - argument with a value
|
|
90
102
|
.option({
|
|
91
103
|
name: 'my-string',
|
|
92
104
|
description: 'A string argument',
|
|
93
105
|
aliases: ['s'],
|
|
94
106
|
})
|
|
107
|
+
// A CLI flg - boolean argument with no value
|
|
95
108
|
.flag({
|
|
96
109
|
name: 'flag',
|
|
97
110
|
description: 'a flag that will be related to any command (main or sub)',
|
|
98
111
|
aliases: ['f'],
|
|
112
|
+
negatble: true,
|
|
113
|
+
negateName: 'no-flag', // Override the default negation name
|
|
114
|
+
negateAliases: ['F'], // Override the default negation aliases
|
|
99
115
|
})
|
|
116
|
+
// Usage examples for your CLI. Use this to describe various common usages or quirks.
|
|
100
117
|
.example({
|
|
101
118
|
description: 'Run the sub command',
|
|
102
119
|
input: 'my-bin --flag sub',
|
|
103
120
|
output: 'Sub command: flag is true',
|
|
104
121
|
})
|
|
122
|
+
// Configuration of the automated help section
|
|
105
123
|
.help({
|
|
106
124
|
bindCommand: true,
|
|
107
125
|
footerText: `Copyright © ${new Date().getFullYear()} Me, Myself and I`,
|
|
@@ -112,193 +130,27 @@ const parser = massarg({
|
|
|
112
130
|
})
|
|
113
131
|
```
|
|
114
132
|
|
|
115
|
-
##
|
|
116
|
-
|
|
117
|
-
The main command is the one that runs when you supply no other commands.
|
|
118
|
-
|
|
119
|
-
If no command is specified, and no main command is present, the help usage is automatically printed.
|
|
120
|
-
|
|
121
|
-
### Example
|
|
122
|
-
|
|
123
|
-
#### JS/TS
|
|
124
|
-
|
|
125
|
-
```ts
|
|
126
|
-
parser.main((options) => {
|
|
127
|
-
console.log('Parsed options:', options)
|
|
128
|
-
// do stuff
|
|
129
|
-
})
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
#### Shell
|
|
133
|
-
|
|
134
|
-
```shell
|
|
135
|
-
$ ./mybin
|
|
136
|
-
# Main command runs without options
|
|
137
|
-
|
|
138
|
-
$ ./mybin --my-string "Some string"
|
|
139
|
-
# Main command runs with options { myString: "Some string" }
|
|
140
|
-
|
|
141
|
-
$ ./mybin foo
|
|
142
|
-
# Foo sub command run with options {}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
## Commands
|
|
146
|
-
|
|
147
|
-
Commands are activated when their keyword is included in the args. The first command that matches
|
|
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.
|
|
150
|
-
|
|
151
|
-
### Options
|
|
152
|
-
|
|
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. |
|
|
159
|
-
|
|
160
|
-
### Example
|
|
161
|
-
|
|
162
|
-
#### JS/TS
|
|
163
|
-
|
|
164
|
-
```ts
|
|
165
|
-
parser.command({
|
|
166
|
-
name: 'do-something',
|
|
167
|
-
description: 'This command does something',
|
|
168
|
-
aliases: ['do', 'd'],
|
|
169
|
-
run: (options) => {
|
|
170
|
-
console.log('Parsed options:', options)
|
|
171
|
-
// do stuff
|
|
172
|
-
},
|
|
173
|
-
})
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
#### Shell
|
|
177
|
-
|
|
178
|
-
```shell
|
|
179
|
-
$ ./mybin my-command
|
|
180
|
-
# Specified "my-command" runs without options
|
|
181
|
-
|
|
182
|
-
$ ./mybin my-command --my-string "Some string"
|
|
183
|
-
# Specified "my-command" runs with option { myString: "Some string" }
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
## Options
|
|
187
|
-
|
|
188
|
-
Options are variables you can accept via CLI and parse to use in your commands, e.g. `--my-bool`,
|
|
189
|
-
`--my-string string`, `--my-number 1`.
|
|
190
|
-
|
|
191
|
-
Aliases use the shorthand syntax, as such: `-s string`, `-n 1`.
|
|
192
|
-
|
|
193
|
-
### Options
|
|
194
|
-
|
|
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. |
|
|
204
|
-
|
|
205
|
-
### Example
|
|
206
|
-
|
|
207
|
-
#### JS/TS
|
|
208
|
-
|
|
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
|
-
})
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
#### Shell
|
|
221
|
-
|
|
222
|
-
```shell
|
|
223
|
-
$ ./mybin my-command
|
|
224
|
-
# Specified "my-command" runs without options
|
|
225
|
-
|
|
226
|
-
$ ./mybin my-command --my-string "Some string" --my-number 1 --my-bool
|
|
227
|
-
# Specified "my-command" runs with option { myString: "Some string", myNumber: 1, myBool: true }
|
|
228
|
-
```
|
|
133
|
+
## Documentation
|
|
229
134
|
|
|
230
|
-
|
|
135
|
+
The full documentation can be found here:
|
|
136
|
+
[Massarg Documentation](https://chenasraf.github.io/massarg)
|
|
231
137
|
|
|
232
|
-
|
|
233
|
-
|
|
138
|
+
- [Massarg](https://chenasraf.github.io/massarg/docs/api/classes/massarg.Massarg)
|
|
139
|
+
- [MassargOption](https://chenasraf.github.io/massarg/docs/api/classes/massarg.MassargOption)
|
|
140
|
+
- [MassargFlag](https://chenasraf.github.io/massarg/docs/api/classes/massarg.MassargFlag)
|
|
141
|
+
- [MassargExample](https://chenasraf.github.io/massarg/docs/api/classes/massarg.MassargExample)
|
|
234
142
|
|
|
235
|
-
|
|
236
|
-
atop as titles, if specified.
|
|
143
|
+
## Contributing
|
|
237
144
|
|
|
238
|
-
|
|
145
|
+
I am developing this package on my free time, so any support, whether code, issues, or just stars is
|
|
146
|
+
very helpful to sustaining its life. If you are feeling incredibly generous and would like to donate
|
|
147
|
+
just a small amount to help sustain this project, I would be very very thankful!
|
|
239
148
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
### Example
|
|
247
|
-
|
|
248
|
-
#### JS/TS
|
|
249
|
-
|
|
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',
|
|
255
|
-
})
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
## Help/Usage Command
|
|
259
|
-
|
|
260
|
-
You can modify some of the styles and behavior of the help text. None of the options are required,
|
|
261
|
-
you may override their defaults to modify the behavior.
|
|
262
|
-
|
|
263
|
-
### Options
|
|
264
|
-
|
|
265
|
-
| Name | Type | Default | Description |
|
|
266
|
-
| ---------------------- | -------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
267
|
-
| `binName` | `string` | running script name | The name of the binary, to be used when outputting usage information. |
|
|
268
|
-
| `printWidth` | `number` | `80` | The amount of characters to allow per line. Use `0` to disable wrapping. |
|
|
269
|
-
| `normalColors` | `string \| string[]` | `"dim"` | Colors to use on normal text (descriptions, usage example, etc.) |
|
|
270
|
-
| `highlightColors` | `string \| string[]` | `"yellow"` | Colors to use on highlighted text (command names, option names, binary name, etc) |
|
|
271
|
-
| `titleColors` | `string \| string[]` | `["bold", "white"]` | Colors to use on title text ("Options", "Usage", etc) |
|
|
272
|
-
| `subtitleColors` | `string \| string[]` | `["bold", "dim"]` | Colors to use on subtitle text (e.g. command titles for non-gloal options) |
|
|
273
|
-
| `bodyColors` | `string \| string[]` | `"white"` | Colors to use on special body text (header, footer, and default value) |
|
|
274
|
-
| `header` | `string` | | Additional content to display below the usage line, and above the rest. |
|
|
275
|
-
| `footer` | `string` | | Additional content to display below the commands and options, at the very bottom. |
|
|
276
|
-
| `commandNameSeparator` | `string` | `" \| "` | Separator for command name & its aliases. |
|
|
277
|
-
| `optionNameSeparator` | `string` | `"\|"` | Separator for option name & its aliases. |
|
|
278
|
-
| `useGlobalColumns` | `boolean` | `true` | Decides whether to align the columns of the option/command names and their descriptions globally or per table |
|
|
279
|
-
| `usageExample` | `string` | `"[command] [option]"` | Default text to use as suffix for the `binName`, which will be used in the "Usage" line of the help text |
|
|
280
|
-
| `useColors` | `boolean` | `true` | When false, no colors will be output in the help. Good for non-supporting systems. |
|
|
281
|
-
| `includeDefaults` | `boolean` | `true` | When false, the default values will not be specified after the description of each option. |
|
|
282
|
-
|
|
283
|
-
### Example
|
|
284
|
-
|
|
285
|
-
#### JS/TS
|
|
286
|
-
|
|
287
|
-
```ts
|
|
288
|
-
parser.help({
|
|
289
|
-
printWidth: 80,
|
|
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: '|',
|
|
299
|
-
useGlobalColumns: true,
|
|
300
|
-
usageExample: 'command [option]',
|
|
301
|
-
})
|
|
302
|
-
```
|
|
149
|
+
<a href="https://ko-fi.com/casraf" target="_blank">
|
|
150
|
+
<img height="36"
|
|
151
|
+
src="https://cdn.ko-fi.com/cdn/kofi1.png?v=3"
|
|
152
|
+
alt="Buy Me a Coffee at ko-fi.com" />
|
|
153
|
+
</a>
|
|
303
154
|
|
|
304
|
-
|
|
155
|
+
I welcome any issues or pull requests on GitHub. If you find a bug, or would like a new feature,
|
|
156
|
+
don't hesitate to open an appropriate issue and I will do my best to reply promptly.
|
package/command.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { HelpConfig } from './help';
|
|
3
|
-
import { MassargOption, MassargFlag,
|
|
3
|
+
import { MassargOption, MassargFlag, TypedOptionConfig, Prefixes, FlagConfig } from './option';
|
|
4
4
|
import { DeepRequired } from './utils';
|
|
5
5
|
import { MassargExample, ExampleConfig } from './example';
|
|
6
|
-
export declare const CommandConfig: <RunArgs extends z.ZodType<
|
|
6
|
+
export declare const CommandConfig: <RunArgs extends ArgsObject = ArgsObject>(args: z.ZodType<RunArgs, z.ZodTypeDef, RunArgs>) => z.ZodObject<{
|
|
7
7
|
/** Command name */
|
|
8
8
|
name: z.ZodString;
|
|
9
9
|
/** Command description, displayed in the help output */
|
|
@@ -14,21 +14,32 @@ export declare const CommandConfig: <RunArgs extends z.ZodType<any, z.ZodTypeDef
|
|
|
14
14
|
* Function used when invoking this command. It receives the parsed options and the primary
|
|
15
15
|
* instance of Massarg used to invoke this command (the top-level instance)
|
|
16
16
|
*/
|
|
17
|
-
run: z.ZodType<Runner<
|
|
17
|
+
run: z.ZodType<Runner<RunArgs>, z.ZodTypeDef, Runner<RunArgs>>;
|
|
18
|
+
/** The prefix to match before option names, e.g. `--` */
|
|
19
|
+
optionPrefix: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
20
|
+
/** The prefix to match before option aliases, e.g. `-` */
|
|
21
|
+
aliasPrefix: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
18
22
|
}, "strip", z.ZodTypeAny, {
|
|
19
|
-
description: string;
|
|
20
23
|
name: string;
|
|
21
|
-
|
|
24
|
+
description: string;
|
|
25
|
+
run: Runner<RunArgs>;
|
|
22
26
|
aliases?: string[] | undefined;
|
|
27
|
+
optionPrefix?: string | undefined;
|
|
28
|
+
aliasPrefix?: string | undefined;
|
|
23
29
|
}, {
|
|
24
|
-
description: string;
|
|
25
30
|
name: string;
|
|
26
|
-
|
|
31
|
+
description: string;
|
|
32
|
+
run: Runner<RunArgs>;
|
|
27
33
|
aliases?: string[] | undefined;
|
|
34
|
+
optionPrefix?: string | undefined;
|
|
35
|
+
aliasPrefix?: string | undefined;
|
|
28
36
|
}>;
|
|
29
|
-
export type CommandConfig<
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
export type CommandConfig<RunArgs extends ArgsObject = ArgsObject> = z.infer<ReturnType<typeof CommandConfig<RunArgs>>>;
|
|
38
|
+
/**
|
|
39
|
+
* An object with string keys and any values.
|
|
40
|
+
*/
|
|
41
|
+
export type ArgsObject = Record<string | number | symbol, any>;
|
|
42
|
+
export type Runner<Args extends ArgsObject> = (options: Args, instance: MassargCommand<Args>) => Promise<void> | void;
|
|
32
43
|
/**
|
|
33
44
|
* A command is a named function that can be invoked with a set of options.
|
|
34
45
|
*
|
|
@@ -48,7 +59,7 @@ export type Runner<Args extends ArgsObject> = <A extends ArgsObject = Args>(opti
|
|
|
48
59
|
* })
|
|
49
60
|
* ```
|
|
50
61
|
*/
|
|
51
|
-
export declare class MassargCommand<Args extends ArgsObject = ArgsObject> {
|
|
62
|
+
export declare class MassargCommand<Args extends ArgsObject = ArgsObject> implements Omit<CommandConfig<Args>, 'run'> {
|
|
52
63
|
name: string;
|
|
53
64
|
description: string;
|
|
54
65
|
aliases: string[];
|
|
@@ -59,7 +70,10 @@ export declare class MassargCommand<Args extends ArgsObject = ArgsObject> {
|
|
|
59
70
|
args: Partial<Args>;
|
|
60
71
|
private _helpConfig;
|
|
61
72
|
parent?: MassargCommand<any>;
|
|
73
|
+
optionPrefix: string;
|
|
74
|
+
aliasPrefix: string;
|
|
62
75
|
constructor(options: CommandConfig<Args>, parent?: MassargCommand<any>);
|
|
76
|
+
get optionPrefixes(): Prefixes;
|
|
63
77
|
get helpConfig(): DeepRequired<HelpConfig>;
|
|
64
78
|
/**
|
|
65
79
|
* Add a sub-command to this command.
|
|
@@ -70,8 +84,8 @@ export declare class MassargCommand<Args extends ArgsObject = ArgsObject> {
|
|
|
70
84
|
* While options are not inherited, they will be passed from any parent commands
|
|
71
85
|
* to the sub-command when invoked.
|
|
72
86
|
*/
|
|
73
|
-
command<A extends ArgsObject = Args>(config: CommandConfig<A>): MassargCommand<Args>;
|
|
74
|
-
command<A extends ArgsObject = Args>(config: MassargCommand<A>): MassargCommand<Args>;
|
|
87
|
+
command<A extends ArgsObject = Args>(config: CommandConfig<A>): MassargCommand<Args & A>;
|
|
88
|
+
command<A extends ArgsObject = Args>(config: MassargCommand<A>): MassargCommand<Args & A>;
|
|
75
89
|
/**
|
|
76
90
|
* Adds a flag to this command.
|
|
77
91
|
*
|
|
@@ -79,11 +93,12 @@ export declare class MassargCommand<Args extends ArgsObject = ArgsObject> {
|
|
|
79
93
|
* a boolean value, or to indicate that a command should be run in a different
|
|
80
94
|
* mode.
|
|
81
95
|
*
|
|
82
|
-
* A flag can be negated by
|
|
83
|
-
*
|
|
84
|
-
*
|
|
96
|
+
* A flag can be negated by using `negatable: true`. By default, the negated name is the same
|
|
97
|
+
* as the option name, prefixed by `no-`, and each of the aliases will be uppercased.
|
|
98
|
+
* For example, `--verbose` and `--no-verbose`, or `-v` and `-V`.
|
|
99
|
+
* This behavior can be overridden by the `negatedName` and `negatedAliases` options.
|
|
85
100
|
*/
|
|
86
|
-
flag(config:
|
|
101
|
+
flag(config: FlagConfig): MassargCommand<Args>;
|
|
87
102
|
flag(config: MassargFlag): MassargCommand<Args>;
|
|
88
103
|
/**
|
|
89
104
|
* Adds an option to this command.
|
|
@@ -98,8 +113,10 @@ export declare class MassargCommand<Args extends ArgsObject = ArgsObject> {
|
|
|
98
113
|
* value passed to the command. This is useful if you want to parse a string
|
|
99
114
|
* into a more complex type, or if you want to validate the value.
|
|
100
115
|
*/
|
|
101
|
-
option<T = string>(config: MassargOption<T>): MassargCommand<Args>;
|
|
102
|
-
option<T = string>(config: TypedOptionConfig<T>): MassargCommand<Args>;
|
|
116
|
+
option<T = string, A extends ArgsObject = Args>(config: MassargOption<T, A>): MassargCommand<Args>;
|
|
117
|
+
option<T = string, A extends ArgsObject = Args>(config: TypedOptionConfig<T, A>): MassargCommand<Args>;
|
|
118
|
+
private assertNotDuplicate;
|
|
119
|
+
private assertOnlyOneDefault;
|
|
103
120
|
/**
|
|
104
121
|
* Adds an example to this command.
|
|
105
122
|
*
|
|
@@ -125,7 +142,7 @@ export declare class MassargCommand<Args extends ArgsObject = ArgsObject> {
|
|
|
125
142
|
*
|
|
126
143
|
* If none is provided, help will be printed.
|
|
127
144
|
*/
|
|
128
|
-
main
|
|
145
|
+
main(run: Runner<Args>): MassargCommand<Args>;
|
|
129
146
|
/**
|
|
130
147
|
* Parse the given arguments and run the command or sub-commands along with the given options
|
|
131
148
|
* and flags.
|
|
@@ -133,11 +150,13 @@ export declare class MassargCommand<Args extends ArgsObject = ArgsObject> {
|
|
|
133
150
|
* To parse the arguments without running any commands and only get the output args,
|
|
134
151
|
* use `getArgs` instead.
|
|
135
152
|
*/
|
|
136
|
-
parse(argv
|
|
153
|
+
parse(argv?: string[], args?: Partial<Args>, parent?: MassargCommand<Args>): Promise<void> | void;
|
|
154
|
+
private printError;
|
|
137
155
|
private parseOption;
|
|
138
156
|
/** Parse the given arguments and return the output args. */
|
|
139
157
|
getArgs(argv: string[], __args?: Partial<Args>, parent?: MassargCommand<any>, parseCommands?: false): Promise<void> | void;
|
|
140
158
|
getArgs(argv: string[], __args?: Partial<Args>, parent?: MassargCommand<any>, parseCommands?: true): Args;
|
|
159
|
+
private assertRequired;
|
|
141
160
|
/**
|
|
142
161
|
* Generate the help output for this command, and return it as a string.
|
|
143
162
|
*/
|
|
@@ -147,7 +166,17 @@ export declare class MassargCommand<Args extends ArgsObject = ArgsObject> {
|
|
|
147
166
|
*/
|
|
148
167
|
printHelp(): void;
|
|
149
168
|
}
|
|
150
|
-
|
|
169
|
+
/**
|
|
170
|
+
* A command that prints help for this command, or a sub-command if specified.
|
|
171
|
+
*
|
|
172
|
+
* This command is automatically added to the top-level command if you use `bindCommand: true` in `help()`.
|
|
173
|
+
* You can also add it manually to any command.
|
|
174
|
+
*/
|
|
175
|
+
export declare class MassargHelpCommand<T extends {
|
|
176
|
+
command?: string;
|
|
177
|
+
} = {
|
|
178
|
+
command?: string;
|
|
179
|
+
}> extends MassargCommand<T> {
|
|
151
180
|
constructor(config?: Partial<Omit<CommandConfig<T>, 'run'>>);
|
|
152
181
|
}
|
|
153
182
|
//# sourceMappingURL=command.d.ts.map
|
package/command.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,CAA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