@ztimson/utils 0.23.3 → 0.23.5

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/index.mjs CHANGED
@@ -24,7 +24,10 @@ class ArgParser {
24
24
  var _a;
25
25
  return !(arg instanceof ArgParser) && !((_a = arg.flags) == null ? void 0 : _a.length);
26
26
  });
27
- this.flags = [...argList.filter((arg) => !(arg instanceof ArgParser) && arg.flags && arg.flags.length), ...this.flags];
27
+ this.flags = [
28
+ ...argList.filter((arg) => !(arg instanceof ArgParser) && arg.flags && arg.flags.length),
29
+ { name: "help", desc: "Display command's help message", flags: ["-h", "--help"], default: false }
30
+ ];
28
31
  this.defaults = argList.reduce((acc, arg) => ({ ...acc, [arg.name]: arg["extras"] ? [] : arg.default ?? null }), {});
29
32
  this.examples = [
30
33
  ...examples,
@@ -101,14 +104,14 @@ class ArgParser {
101
104
  let msg = `
102
105
 
103
106
  ${opts.message || this.desc}`;
104
- msg += "\n\nUsage: " + this.examples.map((ex) => `run ${this.name} ${ex}`).join("\n ");
105
- if (this.args.length) msg += "\n\n " + this.args.map((arg) => `${arg.name.toUpperCase()}${spacer(arg.name)}${arg.desc}`).join("\n ");
106
- msg += "\n\nOptions:\n " + this.flags.map((flag) => {
107
+ msg += "\n\nUsage: " + this.examples.map((ex) => `${this.name} ${ex}`).join("\n ");
108
+ if (this.args.length) msg += "\n\n " + this.args.map((arg) => `${arg.name.toUpperCase()}${spacer(arg.name)}${arg.desc}`).join("\n ");
109
+ msg += "\n\nOptions:\n " + this.flags.map((flag) => {
107
110
  var _a;
108
111
  const flags = ((_a = flag.flags) == null ? void 0 : _a.join(", ")) || "";
109
112
  return `${flags}${spacer(flags)}${flag.desc}`;
110
- }).join("\n ");
111
- if (this.commands.length) msg += "\n\nCommands:\n " + this.commands.map((command) => `${command.name}${spacer(command.name)}${command.desc}`).join("\n ");
113
+ }).join("\n ");
114
+ if (this.commands.length) msg += "\n\nCommands:\n " + this.commands.map((command) => `${command.name}${spacer(command.name)}${command.desc}`).join("\n ");
112
115
  return `${msg}
113
116
 
114
117
  `;