@node-cli/parser 1.0.2 → 2.1.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 +13 -2
- package/dist/parser.d.ts +2 -0
- package/dist/parser.js +3 -2
- package/dist/parser.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
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
|
|
|
13
13
|
| Argument | Type |
|
|
14
14
|
| ------------------------- | ----------------- |
|
|
15
15
|
| options | Object |
|
|
16
|
+
| options.meta | import.meta |
|
|
16
17
|
| options.examples | Array of Object |
|
|
17
18
|
| options.flags | Object |
|
|
18
19
|
| options.parameters | Object |
|
|
@@ -24,7 +25,9 @@
|
|
|
24
25
|
|
|
25
26
|
```js
|
|
26
27
|
import { parser } from "@node-cli/parser";
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
const { flags, parameters, showHelp } = parser({
|
|
30
|
+
meta: import.meta, // this is required for --version to work correctly
|
|
28
31
|
examples: [
|
|
29
32
|
{
|
|
30
33
|
command: 'my-cli --verbose --command "chmod +x" bin',
|
|
@@ -68,8 +71,16 @@ const { flags, parameters } = parser({
|
|
|
68
71
|
verbose: false,
|
|
69
72
|
},
|
|
70
73
|
});
|
|
74
|
+
|
|
75
|
+
// `flags` will be an object with what the user provided
|
|
76
|
+
// `parameters` will be an object with what the user provided
|
|
77
|
+
// `showHelp` is a method that can be invoked to display help instructions
|
|
71
78
|
```
|
|
72
79
|
|
|
73
80
|
## Note
|
|
74
81
|
|
|
75
82
|
If options `--version` or `--help` are used, they will automatically print version or help, respectively, and exit with 0 (`process.exit(0)`).
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT © Arno Versini
|
package/dist/parser.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ type Parameters = {
|
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
15
|
export type ParserConfiguration = {
|
|
16
|
+
meta: any;
|
|
16
17
|
flags?: Flags;
|
|
17
18
|
parameters?: Parameters;
|
|
18
19
|
usage?: boolean | string;
|
|
@@ -25,6 +26,7 @@ export type ParserConfiguration = {
|
|
|
25
26
|
defaultParameters?: any;
|
|
26
27
|
};
|
|
27
28
|
export declare const parser: (configuration: ParserConfiguration) => {
|
|
29
|
+
showHelp: (exitCode?: number) => never;
|
|
28
30
|
flags: object;
|
|
29
31
|
parameters: object;
|
|
30
32
|
};
|
package/dist/parser.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { meowOptionsHelper, meowParserHelper, shallowMerge } from "./utilities.js";
|
|
2
2
|
import meow from "meow";
|
|
3
3
|
export const parser = (configuration)=>{
|
|
4
|
-
const { defaultFlags ={} , defaultParameters ={} , ...others } = configuration;
|
|
4
|
+
const { meta , defaultFlags ={} , defaultParameters ={} , ...others } = configuration;
|
|
5
5
|
const { helpText , options } = meowOptionsHelper(others);
|
|
6
6
|
const cli = meow(helpText, {
|
|
7
7
|
...options,
|
|
8
|
-
importMeta:
|
|
8
|
+
importMeta: meta
|
|
9
9
|
});
|
|
10
10
|
meowParserHelper({
|
|
11
11
|
cli
|
|
12
12
|
});
|
|
13
13
|
return {
|
|
14
|
+
showHelp: cli.showHelp,
|
|
14
15
|
flags: shallowMerge(defaultFlags, cli.flags),
|
|
15
16
|
parameters: shallowMerge(defaultParameters, cli.input)
|
|
16
17
|
};
|
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\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\tdefaultFlags = {},\n\t\tdefaultParameters = {},\n\t\t...others\n\t} = configuration;\n\tconst { helpText, options } = meowOptionsHelper(others);\n\tconst cli = meow(helpText, {
|
|
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\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","others","helpText","options","cli","importMeta","showHelp","flags","parameters","input"],"mappings":"AAAA,SACCA,iBAAiB,EACjBC,gBAAgB,EAChBC,YAAY,QACN,iBAAiB;AAExB,OAAOC,UAAU,OAAO;AA4BxB,OAAO,MAAMC,SAAS,CAACC;IACtB,MAAM,EACLC,KAAI,EACJC,cAAe,CAAC,EAAC,EACjBC,mBAAoB,CAAC,EAAC,EACtB,GAAGC,QACH,GAAGJ;IACJ,MAAM,EAAEK,SAAQ,EAAEC,QAAO,EAAE,GAAGX,kBAAkBS;IAChD,MAAMG,MAAMT,KAAKO,UAAU;QAC1B,GAAGC,OAAO;QACVE,YAAYP;IACb;IACAL,iBAAiB;QAAEW;IAAI;IAEvB,OAAO;QACNE,UAAUF,IAAIE;QACdC,OAAOb,aAAaK,cAAcK,IAAIG;QACtCC,YAAYd,aAAaM,mBAAmBI,IAAIK;IACjD;AACD,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/parser",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "A simple CLI parser helper",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"build:js": "swc --source-maps --out-dir dist src",
|
|
25
25
|
"build:types": "tsc",
|
|
26
26
|
"clean": "rimraf dist types coverage",
|
|
27
|
-
"lint": "eslint \"src/*.ts\"",
|
|
27
|
+
"lint": "prettier --write \"src/*.ts\" && eslint --fix \"src/*.ts\"",
|
|
28
28
|
"test": "cross-env-shell NODE_OPTIONS=--experimental-vm-modules jest",
|
|
29
29
|
"test:coverage": "npm run test -- --coverage",
|
|
30
30
|
"watch": "swc --watch --out-dir dist src"
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "04fc495165a21ef51a94175dac632e733759eab4"
|
|
36
36
|
}
|