@node-cli/parser 2.1.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 CHANGED
@@ -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 |
@@ -35,6 +36,16 @@ const { flags, parameters, showHelp } = parser({
35
36
  },
36
37
  ],
37
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
+ },
38
49
  verbose: {
39
50
  shortFlag: "V",
40
51
  description: "Enable extra logging",
@@ -65,6 +76,14 @@ const { flags, parameters, showHelp } = parser({
65
76
  description: "the destination",
66
77
  },
67
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
+ ],
68
87
  // use usage:true is equivalent to the following line
69
88
  usage: "my-cli [options] [src] [dest]",
70
89
  defaultFlags: {
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,6 +29,7 @@ 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) => {
29
35
  showHelp: (exitCode?: number) => never;
package/dist/parser.js CHANGED
@@ -1,14 +1,15 @@
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 {
14
15
  showHelp: cli.showHelp,
@@ -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\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"}
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.1.0",
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": "04fc495165a21ef51a94175dac632e733759eab4"
35
+ "gitHead": "9c4baafbf51504c8b9ec3c8434f06be73bd2b23f"
36
36
  }