@node-cli/parser 2.2.0 → 2.2.2

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/dist/parser.js CHANGED
@@ -1,8 +1,9 @@
1
- import { meowOptionsHelper, meowParserHelper, shallowMerge } from "./utilities.js";
1
+ import { meowOptionsHelper, meowParserHelper } from "./utilities.js";
2
+ import { fastMerge } from "@node-cli/utilities";
2
3
  import meow from "meow";
3
4
  export const parser = (configuration)=>{
4
- const { meta , defaultFlags ={} , defaultParameters ={} , restrictions , ...others } = configuration;
5
- const { helpText , options } = meowOptionsHelper(others);
5
+ const { meta, defaultFlags = {}, defaultParameters = {}, restrictions, ...others } = configuration;
6
+ const { helpText, options } = meowOptionsHelper(others);
6
7
  const cli = meow(helpText, {
7
8
  ...options,
8
9
  importMeta: meta
@@ -13,8 +14,8 @@ export const parser = (configuration)=>{
13
14
  });
14
15
  return {
15
16
  showHelp: cli.showHelp,
16
- flags: shallowMerge(defaultFlags, cli.flags),
17
- parameters: shallowMerge(defaultParameters, cli.input)
17
+ flags: fastMerge(defaultFlags, cli.flags),
18
+ parameters: fastMerge(defaultParameters, cli.input)
18
19
  };
19
20
  };
20
21
 
@@ -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};\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"}
1
+ {"version":3,"sources":["../src/parser.ts"],"sourcesContent":["import { meowOptionsHelper, meowParserHelper } from \"./utilities.js\";\n\nimport { fastMerge } from \"@node-cli/utilities\";\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: fastMerge(defaultFlags, cli.flags),\n\t\tparameters: fastMerge(defaultParameters, cli.input),\n\t};\n};\n"],"names":["meowOptionsHelper","meowParserHelper","fastMerge","meow","parser","configuration","meta","defaultFlags","defaultParameters","restrictions","others","helpText","options","cli","importMeta","showHelp","flags","parameters","input"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,gBAAgB,QAAQ,iBAAiB;AAErE,SAASC,SAAS,QAAQ,sBAAsB;AAChD,OAAOC,UAAU,OAAO;AAmCxB,OAAO,MAAMC,SAAS,CAACC;IACtB,MAAM,EACLC,IAAI,EACJC,eAAe,CAAC,CAAC,EACjBC,oBAAoB,CAAC,CAAC,EACtBC,YAAY,EACZ,GAAGC,QACH,GAAGL;IACJ,MAAM,EAAEM,QAAQ,EAAEC,OAAO,EAAE,GAAGZ,kBAAkBU;IAChD,MAAMG,MAAMV,KAAKQ,UAAU;QAC1B,GAAGC,OAAO;QACVE,YAAYR;IACb;IACAL,iBAAiB;QAAEY;QAAKJ;IAAa;IAErC,OAAO;QACNM,UAAUF,IAAIE,QAAQ;QACtBC,OAAOd,UAAUK,cAAcM,IAAIG,KAAK;QACxCC,YAAYf,UAAUM,mBAAmBK,IAAIK,KAAK;IACnD;AACD,EAAE"}
@@ -1,24 +1,3 @@
1
- /**
2
- * Wrapper method for lodash `merge()` and `mergeWith()` methods.
3
- *
4
- * Without the `customizer` function, this method recursively merges own and inherited
5
- * enumerable string keyed properties of source objects into the destination object.
6
- * Source properties that resolve to undefined are skipped if a destination value exists.
7
- * Array and plain object properties are merged recursively. Other objects and value
8
- * types are overridden by assignment. Source objects are applied from left to right.
9
- * Subsequent sources overwrite property assignments of previous sources.
10
- *
11
- * With the `customizer` function, the behavior is the same except that `customizer` is
12
- * invoked to produce the merged values of the destination and source properties.
13
- * If customizer returns undefined, merging is handled by the `shallowMerge` instead.
14
- * The customizer is invoked with six arguments: `(objValue, srcValue, key, object,
15
- * source, stack)`
16
- * @param {object} objectA
17
- * @param {object} objectB
18
- * @param {function} customizer
19
- * @returns {object} !! WARNING: this method will mutate objectA
20
- */
21
- export declare const shallowMerge: (objectA: any, objectB: any, customizer?: any) => object;
22
1
  export declare const meowOptionsHelper: (parameters_: {
23
2
  flags?: any;
24
3
  parameters?: any;
package/dist/utilities.js CHANGED
@@ -1,38 +1,11 @@
1
1
  /* eslint-disable unicorn/no-process-exit */ import { Logger } from "@node-cli/logger";
2
2
  import Table from "cli-table3";
3
- import _ from "lodash";
4
3
  import kleur from "kleur";
5
4
  import path from "node:path";
5
+ import { upperFirst } from "@node-cli/utilities";
6
6
  const logger = new Logger();
7
- /**
8
- * Converts the first character of string to upper case
9
- * @param {string} string_ the string to convert
10
- * @returns {string} the converted string
11
- */ const upperFirst = (string_)=>string_[0].toUpperCase() + string_.slice(1);
12
- /**
13
- * Wrapper method for lodash `merge()` and `mergeWith()` methods.
14
- *
15
- * Without the `customizer` function, this method recursively merges own and inherited
16
- * enumerable string keyed properties of source objects into the destination object.
17
- * Source properties that resolve to undefined are skipped if a destination value exists.
18
- * Array and plain object properties are merged recursively. Other objects and value
19
- * types are overridden by assignment. Source objects are applied from left to right.
20
- * Subsequent sources overwrite property assignments of previous sources.
21
- *
22
- * With the `customizer` function, the behavior is the same except that `customizer` is
23
- * invoked to produce the merged values of the destination and source properties.
24
- * If customizer returns undefined, merging is handled by the `shallowMerge` instead.
25
- * The customizer is invoked with six arguments: `(objValue, srcValue, key, object,
26
- * source, stack)`
27
- * @param {object} objectA
28
- * @param {object} objectB
29
- * @param {function} customizer
30
- * @returns {object} !! WARNING: this method will mutate objectA
31
- */ export const shallowMerge = (objectA, objectB, customizer)=>{
32
- return typeof customizer === "function" ? _.mergeWith(objectA, objectB, customizer) : _.merge(objectA, objectB);
33
- };
34
7
  export const meowOptionsHelper = (parameters_)=>{
35
- let { usage , flags , parameters , examples } = parameters_;
8
+ let { usage, flags, parameters, examples } = parameters_;
36
9
  let helpText = "", usageText = "";
37
10
  const commandPrefix = "> ";
38
11
  const options = {
@@ -136,7 +109,7 @@ export const meowOptionsHelper = (parameters_)=>{
136
109
  };
137
110
  };
138
111
  export const meowParserHelper = (parameters)=>{
139
- const { cli , restrictions } = parameters;
112
+ const { cli, restrictions } = parameters;
140
113
  try {
141
114
  if (cli.flags.help) {
142
115
  cli.showHelp();
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["/* eslint-disable unicorn/no-process-exit */\n\nimport { Logger } from \"@node-cli/logger\";\nimport Table from \"cli-table3\";\nimport _ from \"lodash\";\nimport kleur from \"kleur\";\nimport path from \"node:path\";\nconst logger = new Logger();\n\n/**\n * Converts the first character of string to upper case\n * @param {string} string_ the string to convert\n * @returns {string} the converted string\n */\nconst upperFirst = (string_: string): string =>\n\tstring_[0].toUpperCase() + string_.slice(1);\n\n/**\n * Wrapper method for lodash `merge()` and `mergeWith()` methods.\n *\n * Without the `customizer` function, this method recursively merges own and inherited\n * enumerable string keyed properties of source objects into the destination object.\n * Source properties that resolve to undefined are skipped if a destination value exists.\n * Array and plain object properties are merged recursively. Other objects and value\n * types are overridden by assignment. Source objects are applied from left to right.\n * Subsequent sources overwrite property assignments of previous sources.\n *\n * With the `customizer` function, the behavior is the same except that `customizer` is\n * invoked to produce the merged values of the destination and source properties.\n * If customizer returns undefined, merging is handled by the `shallowMerge` instead.\n * The customizer is invoked with six arguments: `(objValue, srcValue, key, object,\n * source, stack)`\n * @param {object} objectA\n * @param {object} objectB\n * @param {function} customizer\n * @returns {object} !! WARNING: this method will mutate objectA\n */\nexport const shallowMerge = (\n\tobjectA: any,\n\tobjectB: any,\n\tcustomizer?: any\n): object => {\n\treturn typeof customizer === \"function\"\n\t\t? _.mergeWith(objectA, objectB, customizer)\n\t\t: _.merge(objectA, objectB);\n};\n\nexport const meowOptionsHelper = (parameters_: {\n\tflags?: any;\n\tparameters?: any;\n\tusage?: any;\n\texamples?: any;\n}) => {\n\tlet { usage, flags, parameters, examples } = parameters_;\n\tlet helpText = \"\",\n\t\tusageText = \"\";\n\tconst commandPrefix = \"> \";\n\tconst options: any = {\n\t\tallowUnknownFlags: false,\n\t\tautoHelp: false,\n\t\tautoVersion: false,\n\t\tdescription: false,\n\t\tflags,\n\t};\n\tconst commonTableConfiguration = {\n\t\tchars: {\n\t\t\tbottom: \"\",\n\t\t\t\"bottom-left\": \"\",\n\t\t\t\"bottom-mid\": \"\",\n\t\t\t\"bottom-right\": \"\",\n\t\t\tleft: \"\",\n\t\t\t\"left-mid\": \"\",\n\t\t\tmid: \"\",\n\t\t\t\"mid-mid\": \"\",\n\t\t\tmiddle: \"\",\n\t\t\tright: \"\",\n\t\t\t\"right-mid\": \"\",\n\t\t\ttop: \"\",\n\t\t\t\"top-left\": \"\",\n\t\t\t\"top-mid\": \"\",\n\t\t\t\"top-right\": \"\",\n\t\t},\n\t\tstyle: {\n\t\t\t\"padding-left\": 0,\n\t\t\t\"padding-right\": 2,\n\t\t},\n\t\twordWrap: true,\n\t};\n\n\tif (usage) {\n\t\tif (typeof usage === \"string\") {\n\t\t\tconst optionalParameters = usage.match(/\\[(.*?)]/g);\n\t\t\tconst requiredParameters = usage.match(/<(.*?)>/g);\n\t\t\tif (optionalParameters) {\n\t\t\t\tfor (const item of optionalParameters) {\n\t\t\t\t\tusage = usage.replace(item, `${kleur.green(item)}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (requiredParameters) {\n\t\t\t\tfor (const item of requiredParameters) {\n\t\t\t\t\tusage = usage.replace(item, `${kleur.red(item)}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tusageText = ` Usage:\\n ${commandPrefix}${usage}`;\n\t\t}\n\t\tif (typeof usage === \"boolean\") {\n\t\t\tconst processName = path.basename(process.argv[1]);\n\t\t\tusageText = ` Usage:\\n ${commandPrefix}${processName}`;\n\t\t\tif (flags) {\n\t\t\t\tusageText += kleur.green(\" [options]\");\n\t\t\t}\n\t\t}\n\t}\n\n\tif (flags) {\n\t\tconst flagsTable = new Table(commonTableConfiguration);\n\t\thelpText += \"\\n\\n Options:\\n\";\n\n\t\tfor (const item of Object.keys(flags).sort()) {\n\t\t\tconst flag = flags[item];\n\t\t\tconst aliasCell = flag.shortFlag\n\t\t\t\t? ` ${kleur.blue(`-${flag.shortFlag}, --${item}`)}`\n\t\t\t\t: ` ${kleur.blue(` --${item}`)}`;\n\t\t\tconst defaultCell =\n\t\t\t\tflag.default === undefined\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: `${kleur.grey(`(default: ${flag.default})`)}`;\n\t\t\tflagsTable.push([aliasCell, flag.description, defaultCell]);\n\t\t}\n\t\thelpText += flagsTable.toString();\n\t}\n\n\tif (parameters) {\n\t\tconst parametersTable = new Table(commonTableConfiguration);\n\t\thelpText += \"\\n\\n\";\n\n\t\tfor (const item of Object.keys(parameters).sort()) {\n\t\t\tconst parameter = parameters[item];\n\t\t\tconst headerCell = ` ${upperFirst(item)}:`;\n\t\t\tconst defaultCell =\n\t\t\t\tparameter.default === undefined\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: `${kleur.grey(`(default: ${parameter.default})`)}`;\n\t\t\tparametersTable.push([headerCell, parameter.description, defaultCell]);\n\t\t\tif (typeof usage === \"boolean\") {\n\t\t\t\tusageText += ` ${kleur.green(`[${item}]`)}`;\n\t\t\t}\n\t\t}\n\t\thelpText += parametersTable.toString();\n\t}\n\n\tif (examples) {\n\t\thelpText += \"\\n\\n Examples:\\n\";\n\t\tfor (const item of examples) {\n\t\t\thelpText += `\\n ${kleur.grey(`${item.comment}`)}\\n`;\n\t\t\thelpText += ` ${kleur.blue(`${commandPrefix}${item.command}`)}\\n`;\n\t\t}\n\t}\n\n\treturn {\n\t\thelpText: `\\n${usageText}${helpText}`,\n\t\toptions,\n\t};\n};\n\nexport const meowParserHelper = (parameters: {\n\tcli: any;\n\trestrictions?: any;\n}) => {\n\tconst { cli, restrictions } = parameters;\n\ttry {\n\t\tif (cli.flags.help) {\n\t\t\tcli.showHelp();\n\t\t\tprocess.exit(0);\n\t\t}\n\t} catch {\n\t\t// nothing to declare officer\n\t}\n\n\ttry {\n\t\tif (cli.flags.version) {\n\t\t\tcli.showVersion();\n\t\t\tprocess.exit(0);\n\t\t}\n\t} catch {\n\t\t// nothing to declare officer\n\t}\n\n\tif (restrictions && restrictions.length > 0) {\n\t\tfor (const rule of restrictions) {\n\t\t\tif (rule.test(cli.flags)) {\n\t\t\t\tlogger.error(rule.message(cli.flags));\n\t\t\t\tprocess.exit(rule.exit);\n\t\t\t}\n\t\t}\n\t}\n};\n"],"names":["Logger","Table","_","kleur","path","logger","upperFirst","string_","toUpperCase","slice","shallowMerge","objectA","objectB","customizer","mergeWith","merge","meowOptionsHelper","parameters_","usage","flags","parameters","examples","helpText","usageText","commandPrefix","options","allowUnknownFlags","autoHelp","autoVersion","description","commonTableConfiguration","chars","bottom","left","mid","middle","right","top","style","wordWrap","optionalParameters","match","requiredParameters","item","replace","green","red","processName","basename","process","argv","flagsTable","Object","keys","sort","flag","aliasCell","shortFlag","blue","defaultCell","default","undefined","grey","push","toString","parametersTable","parameter","headerCell","comment","command","meowParserHelper","cli","restrictions","help","showHelp","exit","version","showVersion","length","rule","test","error","message"],"mappings":"AAAA,0CAA0C,GAE1C,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,WAAW,aAAa;AAC/B,OAAOC,OAAO,SAAS;AACvB,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,UAAU,YAAY;AAC7B,MAAMC,SAAS,IAAIL;AAEnB;;;;CAIC,GACD,MAAMM,aAAa,CAACC,UACnBA,OAAO,CAAC,EAAE,CAACC,gBAAgBD,QAAQE,MAAM;AAE1C;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,MAAMC,eAAe,CAC3BC,SACAC,SACAC;IAEA,OAAO,OAAOA,eAAe,aAC1BX,EAAEY,UAAUH,SAASC,SAASC,cAC9BX,EAAEa,MAAMJ,SAASC;AACrB,EAAE;AAEF,OAAO,MAAMI,oBAAoB,CAACC;IAMjC,IAAI,EAAEC,MAAK,EAAEC,MAAK,EAAEC,WAAU,EAAEC,SAAQ,EAAE,GAAGJ;IAC7C,IAAIK,WAAW,IACdC,YAAY;IACb,MAAMC,gBAAgB;IACtB,MAAMC,UAAe;QACpBC,mBAAmB;QACnBC,UAAU;QACVC,aAAa;QACbC,aAAa;QACbV;IACD;IACA,MAAMW,2BAA2B;QAChCC,OAAO;YACNC,QAAQ;YACR,eAAe;YACf,cAAc;YACd,gBAAgB;YAChBC,MAAM;YACN,YAAY;YACZC,KAAK;YACL,WAAW;YACXC,QAAQ;YACRC,OAAO;YACP,aAAa;YACbC,KAAK;YACL,YAAY;YACZ,WAAW;YACX,aAAa;QACd;QACAC,OAAO;YACN,gBAAgB;YAChB,iBAAiB;QAClB;QACAC,UAAU;IACX;IAEA,IAAIrB,OAAO;QACV,IAAI,OAAOA,UAAU,UAAU;YAC9B,MAA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AAM;IACP,6BAA6B;IAC9B;IAEA,IAAI;QACH,IAAIJ,IAAIpD,MAAMyD,SAAS;YACtBL,IAAIM;YACJ5B,QAAQ0B,KAAK;QACd;IACD,EAAE,OAAM;IACP,6BAA6B;IAC9B;IAEA,IAAIH,gBAAgBA,aAAaM,SAAS,GAAG;QAC5C,KAAK,MAAMC,QAAQP,aAAc;YAChC,IAAIO,KAAKC,KAAKT,IAAIpD,QAAQ;gBACzBd,OAAO4E,MAAMF,KAAKG,QAAQX,IAAIpD;gBAC9B8B,QAAQ0B,KAAKI,KAAKJ;YACnB;QACD;IACD;AACD,EAAE"}
1
+ {"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["/* eslint-disable unicorn/no-process-exit */\n\nimport { Logger } from \"@node-cli/logger\";\nimport Table from \"cli-table3\";\nimport kleur from \"kleur\";\nimport path from \"node:path\";\nimport { upperFirst } from \"@node-cli/utilities\";\n\nconst logger = new Logger();\n\nexport const meowOptionsHelper = (parameters_: {\n\tflags?: any;\n\tparameters?: any;\n\tusage?: any;\n\texamples?: any;\n}) => {\n\tlet { usage, flags, parameters, examples } = parameters_;\n\tlet helpText = \"\",\n\t\tusageText = \"\";\n\tconst commandPrefix = \"> \";\n\tconst options: any = {\n\t\tallowUnknownFlags: false,\n\t\tautoHelp: false,\n\t\tautoVersion: false,\n\t\tdescription: false,\n\t\tflags,\n\t};\n\tconst commonTableConfiguration = {\n\t\tchars: {\n\t\t\tbottom: \"\",\n\t\t\t\"bottom-left\": \"\",\n\t\t\t\"bottom-mid\": \"\",\n\t\t\t\"bottom-right\": \"\",\n\t\t\tleft: \"\",\n\t\t\t\"left-mid\": \"\",\n\t\t\tmid: \"\",\n\t\t\t\"mid-mid\": \"\",\n\t\t\tmiddle: \"\",\n\t\t\tright: \"\",\n\t\t\t\"right-mid\": \"\",\n\t\t\ttop: \"\",\n\t\t\t\"top-left\": \"\",\n\t\t\t\"top-mid\": \"\",\n\t\t\t\"top-right\": \"\",\n\t\t},\n\t\tstyle: {\n\t\t\t\"padding-left\": 0,\n\t\t\t\"padding-right\": 2,\n\t\t},\n\t\twordWrap: true,\n\t};\n\n\tif (usage) {\n\t\tif (typeof usage === \"string\") {\n\t\t\tconst optionalParameters = usage.match(/\\[(.*?)]/g);\n\t\t\tconst requiredParameters = usage.match(/<(.*?)>/g);\n\t\t\tif (optionalParameters) {\n\t\t\t\tfor (const item of optionalParameters) {\n\t\t\t\t\tusage = usage.replace(item, `${kleur.green(item)}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (requiredParameters) {\n\t\t\t\tfor (const item of requiredParameters) {\n\t\t\t\t\tusage = usage.replace(item, `${kleur.red(item)}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tusageText = ` Usage:\\n ${commandPrefix}${usage}`;\n\t\t}\n\t\tif (typeof usage === \"boolean\") {\n\t\t\tconst processName = path.basename(process.argv[1]);\n\t\t\tusageText = ` Usage:\\n ${commandPrefix}${processName}`;\n\t\t\tif (flags) {\n\t\t\t\tusageText += kleur.green(\" [options]\");\n\t\t\t}\n\t\t}\n\t}\n\n\tif (flags) {\n\t\tconst flagsTable = new Table(commonTableConfiguration);\n\t\thelpText += \"\\n\\n Options:\\n\";\n\n\t\tfor (const item of Object.keys(flags).sort()) {\n\t\t\tconst flag = flags[item];\n\t\t\tconst aliasCell = flag.shortFlag\n\t\t\t\t? ` ${kleur.blue(`-${flag.shortFlag}, --${item}`)}`\n\t\t\t\t: ` ${kleur.blue(` --${item}`)}`;\n\t\t\tconst defaultCell =\n\t\t\t\tflag.default === undefined\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: `${kleur.grey(`(default: ${flag.default})`)}`;\n\t\t\tflagsTable.push([aliasCell, flag.description, defaultCell]);\n\t\t}\n\t\thelpText += flagsTable.toString();\n\t}\n\n\tif (parameters) {\n\t\tconst parametersTable = new Table(commonTableConfiguration);\n\t\thelpText += \"\\n\\n\";\n\n\t\tfor (const item of Object.keys(parameters).sort()) {\n\t\t\tconst parameter = parameters[item];\n\t\t\tconst headerCell = ` ${upperFirst(item)}:`;\n\t\t\tconst defaultCell =\n\t\t\t\tparameter.default === undefined\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: `${kleur.grey(`(default: ${parameter.default})`)}`;\n\t\t\tparametersTable.push([headerCell, parameter.description, defaultCell]);\n\t\t\tif (typeof usage === \"boolean\") {\n\t\t\t\tusageText += ` ${kleur.green(`[${item}]`)}`;\n\t\t\t}\n\t\t}\n\t\thelpText += parametersTable.toString();\n\t}\n\n\tif (examples) {\n\t\thelpText += \"\\n\\n Examples:\\n\";\n\t\tfor (const item of examples) {\n\t\t\thelpText += `\\n ${kleur.grey(`${item.comment}`)}\\n`;\n\t\t\thelpText += ` ${kleur.blue(`${commandPrefix}${item.command}`)}\\n`;\n\t\t}\n\t}\n\n\treturn {\n\t\thelpText: `\\n${usageText}${helpText}`,\n\t\toptions,\n\t};\n};\n\nexport const meowParserHelper = (parameters: {\n\tcli: any;\n\trestrictions?: any;\n}) => {\n\tconst { cli, restrictions } = parameters;\n\ttry {\n\t\tif (cli.flags.help) {\n\t\t\tcli.showHelp();\n\t\t\tprocess.exit(0);\n\t\t}\n\t} catch {\n\t\t// nothing to declare officer\n\t}\n\n\ttry {\n\t\tif (cli.flags.version) {\n\t\t\tcli.showVersion();\n\t\t\tprocess.exit(0);\n\t\t}\n\t} catch {\n\t\t// nothing to declare officer\n\t}\n\n\tif (restrictions && restrictions.length > 0) {\n\t\tfor (const rule of restrictions) {\n\t\t\tif (rule.test(cli.flags)) {\n\t\t\t\tlogger.error(rule.message(cli.flags));\n\t\t\t\tprocess.exit(rule.exit);\n\t\t\t}\n\t\t}\n\t}\n};\n"],"names":["Logger","Table","kleur","path","upperFirst","logger","meowOptionsHelper","parameters_","usage","flags","parameters","examples","helpText","usageText","commandPrefix","options","allowUnknownFlags","autoHelp","autoVersion","description","commonTableConfiguration","chars","bottom","left","mid","middle","right","top","style","wordWrap","optionalParameters","match","requiredParameters","item","replace","green","red","processName","basename","process","argv","flagsTable","Object","keys","sort","flag","aliasCell","shortFlag","blue","defaultCell","default","undefined","grey","push","toString","parametersTable","parameter","headerCell","comment","command","meowParserHelper","cli","restrictions","help","showHelp","exit","version","showVersion","length","rule","test","error","message"],"mappings":"AAAA,0CAA0C,GAE1C,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,WAAW,aAAa;AAC/B,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,UAAU,YAAY;AAC7B,SAASC,UAAU,QAAQ,sBAAsB;AAEjD,MAAMC,SAAS,IAAIL;AAEnB,OAAO,MAAMM,oBAAoB,CAACC;IAMjC,IAAI,EAAEC,KAAK,EAAEC,KAAK,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAGJ;IAC7C,IAAIK,WAAW,IACdC,YAAY;IACb,MAAMC,gBAAgB;IACtB,MAAMC,UAAe;QACpBC,mBAAmB;QACnBC,UAAU;QACVC,aAAa;QACbC,aAAa;QACbV;IACD;IACA,MAAMW,2BAA2B;QAChCC,OAAO;YACNC,QAAQ;YACR,eAAe;YACf,cAAc;YACd,gBAAgB;YAChBC,MAAM;YACN,YAAY;YACZC,KAAK;YACL,WAAW;YACXC,QAAQ;YACRC,OAAO;YACP,aAAa;YACbC,KAAK;YACL,YAAY;YACZ,WAAW;YACX,aAAa;QACd;QACAC,OAAO;YACN,gBAAgB;YAChB,iBAAiB;QAClB;QACAC,UAAU;IACX;IAEA,IAAIrB,OAAO;QACV,IAAI,OAAOA,UAAU,UAAU;YAC9B,MAAMsB,qBAAqBtB,MAAMuB,KAAK,CAAC;YACvC,MAAMC,qBAAqBxB,MAAMuB,KAAK,CAAC;YACvC,IAAID,oBAAoB;gBACvB,KAAK,MAAMG,QAAQH,mBAAoB;oBACtCtB,QAAQA,MAAM0B,OAAO,CAACD,MAAM,CAAC,EAAE/B,MAAMiC,KAAK,CAACF,MAAM,CAAC;gBACnD;YACD;YACA,IAAID,oBAAoB;gBACvB,KAAK,MAAMC,QAAQD,mBAAoB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ACtBL,IAAIM,WAAW;YACf5B,QAAQ0B,IAAI,CAAC;QACd;IACD,EAAE,OAAM;IACP,6BAA6B;IAC9B;IAEA,IAAIH,gBAAgBA,aAAaM,MAAM,GAAG,GAAG;QAC5C,KAAK,MAAMC,QAAQP,aAAc;YAChC,IAAIO,KAAKC,IAAI,CAACT,IAAIpD,KAAK,GAAG;gBACzBJ,OAAOkE,KAAK,CAACF,KAAKG,OAAO,CAACX,IAAIpD,KAAK;gBACnC8B,QAAQ0B,IAAI,CAACI,KAAKJ,IAAI;YACvB;QACD;IACD;AACD,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-cli/parser",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "license": "MIT",
5
5
  "author": "Arno Versini",
6
6
  "description": "A simple CLI parser helper",
@@ -12,10 +12,10 @@
12
12
  ],
13
13
  "node": ">=16",
14
14
  "dependencies": {
15
- "@node-cli/logger": ">=1.0.0",
15
+ "@node-cli/logger": ">=1.2.0",
16
+ "@node-cli/utilities": ">=1.0.0",
16
17
  "cli-table3": "0.6.3",
17
18
  "kleur": "4.1.5",
18
- "lodash": "4.17.21",
19
19
  "meow": "12.0.1"
20
20
  },
21
21
  "scripts": {
@@ -32,5 +32,5 @@
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "gitHead": "9c4baafbf51504c8b9ec3c8434f06be73bd2b23f"
35
+ "gitHead": "b50d3ef336c6ba247ea5eea568ec5cf6b7da9fd3"
36
36
  }