@node-cli/parser 2.0.0 → 2.2.0
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 +30 -2
- package/dist/parser.d.ts +7 -0
- package/dist/parser.js +4 -2
- package/dist/parser.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# API
|
|
8
8
|
|
|
9
|
-
**parser(options) ⇒ { flags, parameters }**
|
|
9
|
+
**parser(options) ⇒ { flags, parameters, showHelp }**
|
|
10
10
|
|
|
11
11
|
## Arguments
|
|
12
12
|
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
| options.examples | Array of Object |
|
|
18
18
|
| options.flags | Object |
|
|
19
19
|
| options.parameters | Object |
|
|
20
|
+
| options.restrictions | Array of Object |
|
|
20
21
|
| options.usage | String or Boolean |
|
|
21
22
|
| options.defaultFlags | Object |
|
|
22
23
|
| options.defaultParameters | Object |
|
|
@@ -25,7 +26,8 @@
|
|
|
25
26
|
|
|
26
27
|
```js
|
|
27
28
|
import { parser } from "@node-cli/parser";
|
|
28
|
-
|
|
29
|
+
|
|
30
|
+
const { flags, parameters, showHelp } = parser({
|
|
29
31
|
meta: import.meta, // this is required for --version to work correctly
|
|
30
32
|
examples: [
|
|
31
33
|
{
|
|
@@ -34,6 +36,16 @@ const { flags, parameters } = parser({
|
|
|
34
36
|
},
|
|
35
37
|
],
|
|
36
38
|
flags: {
|
|
39
|
+
encrypt: {
|
|
40
|
+
shortFlag: "e",
|
|
41
|
+
description: "Encrypt the file",
|
|
42
|
+
type: "boolean",
|
|
43
|
+
},
|
|
44
|
+
decrypt: {
|
|
45
|
+
shortFlag: "d",
|
|
46
|
+
description: "Decrypt the file",
|
|
47
|
+
type: "boolean",
|
|
48
|
+
},
|
|
37
49
|
verbose: {
|
|
38
50
|
shortFlag: "V",
|
|
39
51
|
description: "Enable extra logging",
|
|
@@ -64,14 +76,30 @@ const { flags, parameters } = parser({
|
|
|
64
76
|
description: "the destination",
|
|
65
77
|
},
|
|
66
78
|
},
|
|
79
|
+
restrictions: [
|
|
80
|
+
{
|
|
81
|
+
exit: 1,
|
|
82
|
+
message: () =>
|
|
83
|
+
log.error("Error: --encrypt or --decrypt option must be provided."),
|
|
84
|
+
test: (x) => x.encrypt === false && x.decrypt === false,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
67
87
|
// use usage:true is equivalent to the following line
|
|
68
88
|
usage: "my-cli [options] [src] [dest]",
|
|
69
89
|
defaultFlags: {
|
|
70
90
|
verbose: false,
|
|
71
91
|
},
|
|
72
92
|
});
|
|
93
|
+
|
|
94
|
+
// `flags` will be an object with what the user provided
|
|
95
|
+
// `parameters` will be an object with what the user provided
|
|
96
|
+
// `showHelp` is a method that can be invoked to display help instructions
|
|
73
97
|
```
|
|
74
98
|
|
|
75
99
|
## Note
|
|
76
100
|
|
|
77
101
|
If options `--version` or `--help` are used, they will automatically print version or help, respectively, and exit with 0 (`process.exit(0)`).
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT © Arno Versini
|
package/dist/parser.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ type Parameters = {
|
|
|
12
12
|
description: string;
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
+
type Restriction = {
|
|
16
|
+
exit: number;
|
|
17
|
+
message: string | (() => void);
|
|
18
|
+
test: (value: any) => boolean;
|
|
19
|
+
};
|
|
15
20
|
export type ParserConfiguration = {
|
|
16
21
|
meta: any;
|
|
17
22
|
flags?: Flags;
|
|
@@ -24,8 +29,10 @@ export type ParserConfiguration = {
|
|
|
24
29
|
}[];
|
|
25
30
|
defaultFlags?: any;
|
|
26
31
|
defaultParameters?: any;
|
|
32
|
+
restrictions?: Restriction[];
|
|
27
33
|
};
|
|
28
34
|
export declare const parser: (configuration: ParserConfiguration) => {
|
|
35
|
+
showHelp: (exitCode?: number) => never;
|
|
29
36
|
flags: object;
|
|
30
37
|
parameters: object;
|
|
31
38
|
};
|
package/dist/parser.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { meowOptionsHelper, meowParserHelper, shallowMerge } from "./utilities.js";
|
|
2
2
|
import meow from "meow";
|
|
3
3
|
export const parser = (configuration)=>{
|
|
4
|
-
const { meta , defaultFlags ={} , defaultParameters ={} , ...others } = configuration;
|
|
4
|
+
const { meta , defaultFlags ={} , defaultParameters ={} , restrictions , ...others } = configuration;
|
|
5
5
|
const { helpText , options } = meowOptionsHelper(others);
|
|
6
6
|
const cli = meow(helpText, {
|
|
7
7
|
...options,
|
|
8
8
|
importMeta: meta
|
|
9
9
|
});
|
|
10
10
|
meowParserHelper({
|
|
11
|
-
cli
|
|
11
|
+
cli,
|
|
12
|
+
restrictions
|
|
12
13
|
});
|
|
13
14
|
return {
|
|
15
|
+
showHelp: cli.showHelp,
|
|
14
16
|
flags: shallowMerge(defaultFlags, cli.flags),
|
|
15
17
|
parameters: shallowMerge(defaultParameters, cli.input)
|
|
16
18
|
};
|
package/dist/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/parser.ts"],"sourcesContent":["import {\n\tmeowOptionsHelper,\n\tmeowParserHelper,\n\tshallowMerge,\n} from \"./utilities.js\";\n\nimport meow from \"meow\";\n\ntype Flags = {\n\t[key: string]: {\n\t\tshortFlag?: string;\n\t\tdefault?: string | number | boolean;\n\t\tdescription: string;\n\t\ttype: string;\n\t};\n};\ntype Parameters = {\n\t[key: string]: {\n\t\tdefault?: string | number | boolean;\n\t\tdescription: string;\n\t};\n};\nexport type ParserConfiguration = {\n\tmeta: any;\n\tflags?: Flags;\n\tparameters?: Parameters;\n\tusage?: boolean | string;\n\texamples?:\n\t\t| string\n\t\t| { command?: string; description?: string; comment?: string }[];\n\tdefaultFlags?: any;\n\tdefaultParameters?: any;\n};\n\nexport const parser = (configuration: ParserConfiguration) => {\n\tconst {\n\t\tmeta,\n\t\tdefaultFlags = {},\n\t\tdefaultParameters = {},\n\t\t...others\n\t} = configuration;\n\tconst { helpText, options } = meowOptionsHelper(others);\n\tconst cli = meow(helpText, {\n\t\t...options,\n\t\timportMeta: meta,\n\t});\n\tmeowParserHelper({ cli });\n\n\treturn {\n\t\tflags: shallowMerge(defaultFlags, cli.flags),\n\t\tparameters: shallowMerge(defaultParameters, cli.input),\n\t};\n};\n"],"names":["meowOptionsHelper","meowParserHelper","shallowMerge","meow","parser","configuration","meta","defaultFlags","defaultParameters","others","helpText","options","cli","importMeta","flags","parameters","input"],"mappings":"AAAA,SACCA,iBAAiB,EACjBC,gBAAgB,EAChBC,YAAY,QACN,iBAAiB;AAExB,OAAOC,UAAU,OAAO;
|
|
1
|
+
{"version":3,"sources":["../src/parser.ts"],"sourcesContent":["import {\n\tmeowOptionsHelper,\n\tmeowParserHelper,\n\tshallowMerge,\n} from \"./utilities.js\";\n\nimport meow from \"meow\";\n\ntype Flags = {\n\t[key: string]: {\n\t\tshortFlag?: string;\n\t\tdefault?: string | number | boolean;\n\t\tdescription: string;\n\t\ttype: string;\n\t};\n};\ntype Parameters = {\n\t[key: string]: {\n\t\tdefault?: string | number | boolean;\n\t\tdescription: string;\n\t};\n};\ntype Restriction = {\n\texit: number;\n\tmessage: string | (() => void);\n\ttest: (value: any) => boolean;\n};\n\nexport type ParserConfiguration = {\n\tmeta: any;\n\tflags?: Flags;\n\tparameters?: Parameters;\n\tusage?: boolean | string;\n\texamples?:\n\t\t| string\n\t\t| { command?: string; description?: string; comment?: string }[];\n\tdefaultFlags?: any;\n\tdefaultParameters?: any;\n\trestrictions?: Restriction[];\n};\n\nexport const parser = (configuration: ParserConfiguration) => {\n\tconst {\n\t\tmeta,\n\t\tdefaultFlags = {},\n\t\tdefaultParameters = {},\n\t\trestrictions,\n\t\t...others\n\t} = configuration;\n\tconst { helpText, options } = meowOptionsHelper(others);\n\tconst cli = meow(helpText, {\n\t\t...options,\n\t\timportMeta: meta,\n\t});\n\tmeowParserHelper({ cli, restrictions });\n\n\treturn {\n\t\tshowHelp: cli.showHelp,\n\t\tflags: shallowMerge(defaultFlags, cli.flags),\n\t\tparameters: shallowMerge(defaultParameters, cli.input),\n\t};\n};\n"],"names":["meowOptionsHelper","meowParserHelper","shallowMerge","meow","parser","configuration","meta","defaultFlags","defaultParameters","restrictions","others","helpText","options","cli","importMeta","showHelp","flags","parameters","input"],"mappings":"AAAA,SACCA,iBAAiB,EACjBC,gBAAgB,EAChBC,YAAY,QACN,iBAAiB;AAExB,OAAOC,UAAU,OAAO;AAmCxB,OAAO,MAAMC,SAAS,CAACC;IACtB,MAAM,EACLC,KAAI,EACJC,cAAe,CAAC,EAAC,EACjBC,mBAAoB,CAAC,EAAC,EACtBC,aAAY,EACZ,GAAGC,QACH,GAAGL;IACJ,MAAM,EAAEM,SAAQ,EAAEC,QAAO,EAAE,GAAGZ,kBAAkBU;IAChD,MAAMG,MAAMV,KAAKQ,UAAU;QAC1B,GAAGC,OAAO;QACVE,YAAYR;IACb;IACAL,iBAAiB;QAAEY;QAAKJ;IAAa;IAErC,OAAO;QACNM,UAAUF,IAAIE;QACdC,OAAOd,aAAaK,cAAcM,IAAIG;QACtCC,YAAYf,aAAaM,mBAAmBK,IAAIK;IACjD;AACD,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/parser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "A simple CLI parser helper",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "9c4baafbf51504c8b9ec3c8434f06be73bd2b23f"
|
|
36
36
|
}
|