massarg 1.0.6 → 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 +119 -98
- package/command.d.ts +153 -0
- package/command.d.ts.map +1 -0
- package/command.js +317 -0
- package/command.js.map +1 -0
- package/error.d.ts +34 -0
- package/error.d.ts.map +1 -0
- package/error.js +37 -0
- package/error.js.map +1 -0
- package/example.d.ts +31 -0
- package/example.d.ts.map +1 -0
- package/example.js +41 -0
- package/example.js.map +1 -0
- package/help.d.ts +729 -0
- package/help.d.ts.map +1 -0
- package/help.js +253 -0
- package/help.js.map +1 -0
- package/index.d.ts +1 -70
- package/index.d.ts.map +1 -1
- package/index.js +13 -673
- package/index.js.map +1 -1
- package/massarg.d.ts +8 -0
- package/massarg.d.ts.map +1 -0
- package/massarg.js +23 -0
- package/massarg.js.map +1 -0
- package/option.d.ts +241 -0
- package/option.d.ts.map +1 -0
- package/option.js +305 -0
- package/option.js.map +1 -0
- package/package.json +22 -14
- package/style.d.ts +45 -0
- package/style.d.ts.map +1 -0
- package/style.js +52 -0
- package/style.js.map +1 -0
- package/utils.d.ts +33 -13
- package/utils.d.ts.map +1 -1
- package/utils.js +97 -110
- package/utils.js.map +1 -1
- package/assertions.d.ts +0 -8
- package/assertions.d.ts.map +0 -1
- package/assertions.js +0 -145
- package/assertions.js.map +0 -1
- package/errors.d.ts +0 -7
- package/errors.d.ts.map +0 -1
- package/errors.js +0 -33
- package/errors.js.map +0 -1
- package/types.d.ts +0 -224
- package/types.d.ts.map +0 -1
- package/types.js +0 -3
- package/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,7 +4,16 @@ Massarg is a beautiful, flexible, powerful, and simple-to-use command/argument p
|
|
|
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 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
|
+

|
|
8
17
|
|
|
9
18
|
## Features
|
|
10
19
|
|
|
@@ -27,23 +36,24 @@ Yes, there are a lot of arg parsers. But hear us out.
|
|
|
27
36
|
|
|
28
37
|
## Quick Start
|
|
29
38
|
|
|
30
|
-
###
|
|
39
|
+
### Install
|
|
31
40
|
|
|
32
41
|
```shell
|
|
42
|
+
# pnpm
|
|
43
|
+
pnpm install massarg
|
|
33
44
|
# npm
|
|
34
|
-
npm install
|
|
45
|
+
npm install massarg
|
|
35
46
|
# yarn
|
|
36
47
|
yarn add massarg
|
|
37
48
|
```
|
|
38
49
|
|
|
39
|
-
###
|
|
50
|
+
### Import
|
|
40
51
|
|
|
41
|
-
```
|
|
42
|
-
import massarg from
|
|
43
|
-
import { Massarg } from "massarg" // import class
|
|
52
|
+
```ts
|
|
53
|
+
import massarg from 'massarg'
|
|
44
54
|
```
|
|
45
55
|
|
|
46
|
-
###
|
|
56
|
+
### Usage
|
|
47
57
|
|
|
48
58
|
Call the default export function `massarg`, or create a new instance manually using `new Massarg()`,
|
|
49
59
|
and then you can start chaining commands. Use `.parse()` to do the final parsing and run the
|
|
@@ -52,30 +62,53 @@ commands and options.
|
|
|
52
62
|
Here is an example with some commonly used examples to get you started. Keep reading for a complete
|
|
53
63
|
documentation of every option.
|
|
54
64
|
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
|
|
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))
|
|
58
71
|
.command({
|
|
59
|
-
name:
|
|
60
|
-
description:
|
|
61
|
-
aliases: [
|
|
62
|
-
run: (options) => console.log(
|
|
72
|
+
name: 'foo',
|
|
73
|
+
description: 'a sub command',
|
|
74
|
+
aliases: ['f'],
|
|
75
|
+
run: (options) => console.log('foo command'),
|
|
63
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
|
+
)
|
|
64
90
|
.option({
|
|
65
|
-
name:
|
|
66
|
-
description:
|
|
67
|
-
aliases: [
|
|
68
|
-
boolean: true,
|
|
91
|
+
name: 'my-string',
|
|
92
|
+
description: 'A string argument',
|
|
93
|
+
aliases: ['s'],
|
|
69
94
|
})
|
|
70
|
-
.
|
|
71
|
-
name:
|
|
72
|
-
description:
|
|
73
|
-
|
|
74
|
-
|
|
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',
|
|
75
104
|
})
|
|
76
105
|
.help({
|
|
77
|
-
|
|
78
|
-
|
|
106
|
+
bindCommand: true,
|
|
107
|
+
footerText: `Copyright © ${new Date().getFullYear()} Me, Myself and I`,
|
|
108
|
+
titleStyle: {
|
|
109
|
+
bold: true,
|
|
110
|
+
color: 'brightWhite',
|
|
111
|
+
},
|
|
79
112
|
})
|
|
80
113
|
```
|
|
81
114
|
|
|
@@ -83,13 +116,15 @@ massarg() // or: new Massarg()
|
|
|
83
116
|
|
|
84
117
|
The main command is the one that runs when you supply no other commands.
|
|
85
118
|
|
|
119
|
+
If no command is specified, and no main command is present, the help usage is automatically printed.
|
|
120
|
+
|
|
86
121
|
### Example
|
|
87
122
|
|
|
88
123
|
#### JS/TS
|
|
89
124
|
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
console.log(
|
|
125
|
+
```ts
|
|
126
|
+
parser.main((options) => {
|
|
127
|
+
console.log('Parsed options:', options)
|
|
93
128
|
// do stuff
|
|
94
129
|
})
|
|
95
130
|
```
|
|
@@ -101,38 +136,38 @@ $ ./mybin
|
|
|
101
136
|
# Main command runs without options
|
|
102
137
|
|
|
103
138
|
$ ./mybin --my-string "Some string"
|
|
104
|
-
# Main command runs with
|
|
139
|
+
# Main command runs with options { myString: "Some string" }
|
|
140
|
+
|
|
141
|
+
$ ./mybin foo
|
|
142
|
+
# Foo sub command run with options {}
|
|
105
143
|
```
|
|
106
144
|
|
|
107
145
|
## Commands
|
|
108
146
|
|
|
109
147
|
Commands are activated when their keyword is included in the args. The first command that matches
|
|
110
|
-
will be executed, skipping the rest. Options will
|
|
111
|
-
|
|
112
|
-
Any arguments that are not taken by options or commands, are automatically passed to
|
|
113
|
-
`options.extra`, which you can access when running a command or when using the return value from
|
|
114
|
-
`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.
|
|
115
150
|
|
|
116
151
|
### Options
|
|
117
152
|
|
|
118
|
-
| Name | Type
|
|
119
|
-
| ------------- |
|
|
120
|
-
| `name` | `string`
|
|
121
|
-
| `aliases` | `string[]`
|
|
122
|
-
| `description` | `string`
|
|
123
|
-
| `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. |
|
|
124
159
|
|
|
125
160
|
### Example
|
|
126
161
|
|
|
127
162
|
#### JS/TS
|
|
128
163
|
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
name:
|
|
132
|
-
description:
|
|
133
|
-
aliases: [
|
|
164
|
+
```ts
|
|
165
|
+
parser.command({
|
|
166
|
+
name: 'do-something',
|
|
167
|
+
description: 'This command does something',
|
|
168
|
+
aliases: ['do', 'd'],
|
|
134
169
|
run: (options) => {
|
|
135
|
-
console.log(
|
|
170
|
+
console.log('Parsed options:', options)
|
|
136
171
|
// do stuff
|
|
137
172
|
},
|
|
138
173
|
})
|
|
@@ -151,47 +186,35 @@ $ ./mybin my-command --my-string "Some string"
|
|
|
151
186
|
## Options
|
|
152
187
|
|
|
153
188
|
Options are variables you can accept via CLI and parse to use in your commands, e.g. `--my-bool`,
|
|
154
|
-
`--my-string string`, `--my-number 1
|
|
189
|
+
`--my-string string`, `--my-number 1`.
|
|
155
190
|
|
|
156
|
-
|
|
157
|
-
`options.extra`, which you can access when running a command or when using the return value from
|
|
158
|
-
`parseArgs()`.
|
|
191
|
+
Aliases use the shorthand syntax, as such: `-s string`, `-n 1`.
|
|
159
192
|
|
|
160
193
|
### Options
|
|
161
194
|
|
|
162
|
-
| Name | Type | Required | Default
|
|
163
|
-
| ------------- | --------------------------------- | -------- |
|
|
164
|
-
| `name` | `string` | ✅ |
|
|
165
|
-
| `aliases` | `string[]` | |
|
|
166
|
-
| `description` | `string` | |
|
|
167
|
-
| `parse` | `function(value, options) => any` | | `String` | `(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. |
|
|
168
|
-
| `isDefault` | `boolean` | | `false`
|
|
169
|
-
| `
|
|
170
|
-
| `
|
|
171
|
-
| `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. |
|
|
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. |
|
|
172
204
|
|
|
173
205
|
### Example
|
|
174
206
|
|
|
175
207
|
#### JS/TS
|
|
176
208
|
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
})
|
|
187
|
-
.option({
|
|
188
|
-
name: "number",
|
|
189
|
-
aliases: ["n"],
|
|
190
|
-
description: "This is a number arg, if you include this option, you must supply it with a numeric value.",
|
|
191
|
-
defaultValue: 0,
|
|
192
|
-
commands: "do",
|
|
193
|
-
parse: (v) => parseInt(v),
|
|
194
|
-
})
|
|
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
|
+
})
|
|
195
218
|
```
|
|
196
219
|
|
|
197
220
|
#### Shell
|
|
@@ -224,11 +247,11 @@ atop as titles, if specified.
|
|
|
224
247
|
|
|
225
248
|
#### JS/TS
|
|
226
249
|
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
input:
|
|
230
|
-
output:
|
|
231
|
-
description:
|
|
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',
|
|
232
255
|
})
|
|
233
256
|
```
|
|
234
257
|
|
|
@@ -261,23 +284,21 @@ you may override their defaults to modify the behavior.
|
|
|
261
284
|
|
|
262
285
|
#### JS/TS
|
|
263
286
|
|
|
264
|
-
```
|
|
265
|
-
|
|
287
|
+
```ts
|
|
288
|
+
parser.help({
|
|
266
289
|
printWidth: 80,
|
|
267
|
-
binName:
|
|
268
|
-
normalColors:
|
|
269
|
-
highlightColors:
|
|
270
|
-
titleColors:
|
|
271
|
-
subtitleColors: [
|
|
272
|
-
header:
|
|
273
|
-
footer:
|
|
274
|
-
commandNameSeparator:
|
|
275
|
-
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: '|',
|
|
276
299
|
useGlobalColumns: true,
|
|
277
|
-
usageExample:
|
|
300
|
+
usageExample: 'command [option]',
|
|
278
301
|
})
|
|
279
302
|
```
|
|
280
303
|
|
|
281
304
|
#### Shell output
|
|
282
|
-
|
|
283
|
-

|
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
|
package/command.d.ts.map
ADDED
|
@@ -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;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,cAAc,CAAC,IAAI,SAAS,UAAU,GAAG,UAAU;IAC9D,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,EAAE,CAAA;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