@thi.ng/args 3.1.6 → 3.2.1

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.
Files changed (2) hide show
  1. package/cli.js +10 -9
  2. package/package.json +2 -2
package/cli.js CHANGED
@@ -32,21 +32,22 @@ const cliApp = async (config) => {
32
32
  } else {
33
33
  cmdID = argv[start];
34
34
  cmd = config.commands[cmdID];
35
- if (!cmd) {
36
- usageOpts.prefix += __descriptions(config.commands, usageOpts);
37
- __usageAndExit(config, usageOpts);
38
- } else {
35
+ if (cmd) {
39
36
  usageOpts.prefix += __descriptions(
40
37
  { [cmdID]: cmd },
41
38
  usageOpts,
42
39
  "\nCurrent command:\n"
43
40
  );
41
+ } else {
42
+ usageOpts.prefix += __descriptions(config.commands, usageOpts);
43
+ __usageAndExit(config.opts, usageOpts);
44
44
  }
45
45
  start++;
46
46
  }
47
+ const mergedOpts = { ...config.opts, ...cmd.opts };
47
48
  let parsed;
48
49
  try {
49
- parsed = parse({ ...config.opts, ...cmd.opts }, argv, {
50
+ parsed = parse(mergedOpts, argv, {
50
51
  usageOpts,
51
52
  start
52
53
  });
@@ -67,7 +68,7 @@ const cliApp = async (config) => {
67
68
  }
68
69
  if (err) {
69
70
  __printError(err, theme);
70
- __usageAndExit(config, usageOpts);
71
+ __usageAndExit(mergedOpts, usageOpts);
71
72
  }
72
73
  }
73
74
  const ctx = await config.ctx(
@@ -86,12 +87,12 @@ const cliApp = async (config) => {
86
87
  process.exit(1);
87
88
  }
88
89
  };
89
- const __usageAndExit = (config, usageOpts) => {
90
- process.stderr.write(usage(config.opts, usageOpts));
90
+ const __usageAndExit = (opts, usageOpts) => {
91
+ process.stderr.write(usage(opts, usageOpts));
91
92
  process.exit(1);
92
93
  };
93
94
  const __descriptions = (commands, { color, lineWidth = 80 } = {}, prefix = "\nAvailable commands:\n") => {
94
- const names = Object.keys(commands);
95
+ const names = Object.keys(commands).sort();
95
96
  const maxLength = Math.max(...names.map((x) => x.length));
96
97
  const theme = __colorTheme(color);
97
98
  return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/args",
3
- "version": "3.1.6",
3
+ "version": "3.2.1",
4
4
  "description": "Declarative, functional CLI argument/options parser, app framework, arg value coercions, multi/sub-commands, usage generation, error handling etc.",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -110,5 +110,5 @@
110
110
  "tag": "cli",
111
111
  "year": 2018
112
112
  },
113
- "gitHead": "d977f819bcafdcb2b24c45f8d01a167fe29fc85a\n"
113
+ "gitHead": "3803db897b51a69c7c37416308c48efa7f354feb\n"
114
114
  }