@thi.ng/args 2.7.2 → 2.8.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-07-11T22:07:07Z
3
+ - **Last updated**: 2025-07-13T21:35:34Z
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,13 @@ 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.8.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/args@2.8.0) (2025-07-12)
15
+
16
+ #### 🚀 Features
17
+
18
+ - update `Command`, support min/max input ranges ([471543e](https://github.com/thi-ng/umbrella/commit/471543e))
19
+ - update cliApp() input checks & error messages
20
+
14
21
  ### [2.7.1](https://github.com/thi-ng/umbrella/tree/@thi.ng/args@2.7.1) (2025-07-11)
15
22
 
16
23
  #### 🩹 Bug fixes
package/README.md CHANGED
@@ -72,7 +72,7 @@ For Node.js REPL:
72
72
  const args = await import("@thi.ng/args");
73
73
  ```
74
74
 
75
- Package sizes (brotli'd, pre-treeshake): ESM: 2.99 KB
75
+ Package sizes (brotli'd, pre-treeshake): ESM: 3.06 KB
76
76
 
77
77
  ## Dependencies
78
78
 
package/api.d.ts CHANGED
@@ -238,9 +238,10 @@ export interface Command<OPTS extends BASE, BASE extends object, CTX extends Com
238
238
  opts: Args<Omit<OPTS, keyof BASE>>;
239
239
  /**
240
240
  * Number of required rest input value (after all parsed options). Leave
241
- * unset to allow any number.
241
+ * unset to allow any number. If given as tuple, the values are interpreted
242
+ * as acceptable `[min,max]` range.
242
243
  */
243
- inputs?: number;
244
+ inputs?: number | [number, number];
244
245
  /**
245
246
  * Actual command function/implementation.
246
247
  */
package/cli.js CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  __padRightAnsi,
11
11
  __wrapWithIndent
12
12
  } from "./utils.js";
13
+ import { isArray } from "@thi.ng/checks/is-array";
13
14
  const cliApp = async (config) => {
14
15
  const argv = config.argv || process.argv;
15
16
  const isColor = !process.env.NO_COLOR;
@@ -46,9 +47,21 @@ const cliApp = async (config) => {
46
47
  process.exit(1);
47
48
  }
48
49
  if (!parsed) process.exit(0);
49
- if (cmd.inputs !== void 0 && cmd.inputs !== parsed.rest.length) {
50
- __printError(`expected ${cmd.inputs || 0} input(s)`, theme);
51
- __usageAndExit(config, usageOpts);
50
+ if (cmd.inputs !== void 0) {
51
+ const num = parsed.rest.length;
52
+ let err;
53
+ if (isArray(cmd.inputs)) {
54
+ const [min, max] = cmd.inputs;
55
+ if (num < min || num > max) {
56
+ err = max < Infinity ? `expected ${min}-${max} inputs` : `expected at least ${min} inputs`;
57
+ }
58
+ } else if (num !== cmd.inputs) {
59
+ err = `expected ${cmd.inputs} input(s)`;
60
+ }
61
+ if (err) {
62
+ __printError(err, theme);
63
+ __usageAndExit(config, usageOpts);
64
+ }
52
65
  }
53
66
  const ctx = await config.ctx(
54
67
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/args",
3
- "version": "2.7.2",
3
+ "version": "2.8.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": "186d38b07f4ba940a8127cbe2379a38036eff387\n"
113
+ "gitHead": "a81765bd79046980463c56a8bd187f9aaa88dd65\n"
114
114
  }