@thi.ng/args 2.5.0 → 2.6.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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2025-06-27T13:16:16Z
3
+ - **Last updated**: 2025-07-02T09:55:21Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -11,6 +11,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
11
11
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
12
12
  and/or version bumps of transitive dependencies.
13
13
 
14
+ ## [2.6.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/args@2.6.0) (2025-06-28)
15
+
16
+ #### 🚀 Features
17
+
18
+ - emit colorized error messages in cliApp() ([36f66b6](https://github.com/thi-ng/umbrella/commit/36f66b6))
19
+
14
20
  ## [2.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/args@2.5.0) (2025-06-27)
15
21
 
16
22
  #### 🚀 Features
package/README.md CHANGED
@@ -71,7 +71,7 @@ For Node.js REPL:
71
71
  const args = await import("@thi.ng/args");
72
72
  ```
73
73
 
74
- Package sizes (brotli'd, pre-treeshake): ESM: 2.80 KB
74
+ Package sizes (brotli'd, pre-treeshake): ESM: 2.91 KB
75
75
 
76
76
  ## Dependencies
77
77
 
package/cli.js CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  const cliApp = async (config) => {
13
13
  const argv = config.argv || process.argv;
14
14
  const isColor = !process.env.NO_COLOR;
15
+ const format = isColor ? PRESET_ANSI16 : PRESET_NONE;
15
16
  const usageOpts = {
16
17
  prefix: "",
17
18
  color: isColor,
@@ -28,23 +29,28 @@ const cliApp = async (config) => {
28
29
  } else {
29
30
  cmdID = argv[start];
30
31
  cmd = config.commands[cmdID];
31
- usageOpts.prefix += __descriptions(config.commands, usageOpts);
32
- if (!cmd) __usageAndExit(config, usageOpts);
32
+ if (!cmd) {
33
+ usageOpts.prefix += __descriptions(config.commands, usageOpts);
34
+ __usageAndExit(config, usageOpts);
35
+ }
33
36
  start++;
34
37
  }
35
38
  let parsed;
36
39
  try {
37
40
  parsed = parse({ ...config.opts, ...cmd.opts }, argv, {
38
- showUsage: true,
41
+ showUsage: false,
39
42
  usageOpts,
40
43
  start
41
44
  });
42
- } catch (_) {
45
+ } catch (e) {
46
+ __printError(e.message, format);
47
+ }
48
+ if (!parsed) {
49
+ __usageAndExit(config, usageOpts);
50
+ process.exit(1);
43
51
  }
44
- if (!parsed) process.exit(1);
45
52
  if (cmd.inputs !== void 0 && cmd.inputs !== parsed.rest.length) {
46
- process.stderr.write(`expected ${cmd.inputs || 0} input(s)
47
- `);
53
+ __printError(`expected ${cmd.inputs || 0} input(s)`, format);
48
54
  __usageAndExit(config, usageOpts);
49
55
  }
50
56
  const ctx = await config.ctx(
@@ -59,7 +65,7 @@ const cliApp = async (config) => {
59
65
  await cmd.fn(ctx);
60
66
  if (config.post) await config.post(ctx, cmd);
61
67
  } catch (e) {
62
- process.stderr.write(e.message + "\n\n");
68
+ __printError(e.message, format);
63
69
  process.exit(1);
64
70
  }
65
71
  };
@@ -86,6 +92,7 @@ const __descriptions = (commands, { color, lineWidth = 80 } = {}) => {
86
92
  "\n"
87
93
  ].join("\n");
88
94
  };
95
+ const __printError = (msg, fmt) => process.stderr.write(fmt.red(msg) + "\n\n");
89
96
  export {
90
97
  cliApp
91
98
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/args",
3
- "version": "2.5.0",
3
+ "version": "2.6.1",
4
4
  "description": "Declarative, functional CLI argument/options parser, value coercions, sub-commands 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": "71294b20c04b6ee35db08d30b43b292b07af0d1b\n"
113
+ "gitHead": "eb3ac07d044559d88b4871fed080929556de1b7c\n"
114
114
  }