@thi.ng/args 2.7.2 → 2.8.0
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 +8 -1
- package/api.d.ts +3 -2
- package/cli.js +16 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2025-07-
|
|
3
|
+
- **Last updated**: 2025-07-12T13:21:04Z
|
|
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/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
|
|
50
|
-
|
|
51
|
-
|
|
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.
|
|
3
|
+
"version": "2.8.0",
|
|
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": "
|
|
113
|
+
"gitHead": "a157f18f16200faad01e15da553c9eea3fa37014\n"
|
|
114
114
|
}
|