@ztimson/utils 0.23.3 → 0.23.4

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.
@@ -17,6 +17,7 @@ export declare class ArgParser {
17
17
  readonly desc: string;
18
18
  readonly argList: (ArgParser | Arg)[];
19
19
  readonly examples: string[];
20
+ static readonly helpArg: Arg;
20
21
  commands: ArgParser[];
21
22
  args: Arg[];
22
23
  flags: Arg[];
package/dist/index.cjs CHANGED
@@ -5,7 +5,7 @@
5
5
  var __defNormalProp = (obj, key, value2) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value: value2 }) : obj[key] = value2;
6
6
  var __publicField = (obj, key, value2) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value2);
7
7
 
8
- class ArgParser {
8
+ const _ArgParser = class _ArgParser {
9
9
  /**
10
10
  * Create a unix-like argument parser to extract flags from the argument list. Can also create help messages.
11
11
  *
@@ -23,12 +23,12 @@ var __publicField = (obj, key, value2) => __defNormalProp(obj, typeof key !== "s
23
23
  this.desc = desc;
24
24
  this.argList = argList;
25
25
  this.examples = examples;
26
- this.commands = argList.filter((arg) => arg instanceof ArgParser);
26
+ this.commands = argList.filter((arg) => arg instanceof _ArgParser);
27
27
  this.args = argList.filter((arg) => {
28
28
  var _a;
29
- return !(arg instanceof ArgParser) && !((_a = arg.flags) == null ? void 0 : _a.length);
29
+ return !(arg instanceof _ArgParser) && !((_a = arg.flags) == null ? void 0 : _a.length);
30
30
  });
31
- this.flags = [...argList.filter((arg) => !(arg instanceof ArgParser) && arg.flags && arg.flags.length), ...this.flags];
31
+ this.flags = [...argList.filter((arg) => !(arg instanceof _ArgParser) && arg.flags && arg.flags.length), ...this.flags];
32
32
  this.defaults = argList.reduce((acc, arg) => ({ ...acc, [arg.name]: arg["extras"] ? [] : arg.default ?? null }), {});
33
33
  this.examples = [
34
34
  ...examples,
@@ -117,7 +117,9 @@ ${opts.message || this.desc}`;
117
117
 
118
118
  `;
119
119
  }
120
- }
120
+ };
121
+ __publicField(_ArgParser, "helpArg", { name: "help", desc: "Display command's help message", flags: ["-h", "--help"], default: false });
122
+ let ArgParser = _ArgParser;
121
123
  function clean(obj, undefinedOnly = false) {
122
124
  if (obj == null) throw new Error("Cannot clean a NULL value");
123
125
  if (Array.isArray(obj)) {