@myapihq/cli 2.31.2 → 2.31.3
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/flags.js +16 -3
- package/dist/flags.test.js +13 -0
- package/package.json +2 -2
package/dist/flags.js
CHANGED
|
@@ -22,6 +22,9 @@ export const GLOBAL_FLAGS = {
|
|
|
22
22
|
version: 'boolean',
|
|
23
23
|
org: 'string',
|
|
24
24
|
};
|
|
25
|
+
// Value flags that name one target rather than a list, mapped to the noun used
|
|
26
|
+
// when refusing a duplicate. Comma-separating these is not a workaround.
|
|
27
|
+
const SINGLE_VALUED = new Map([['org', 'organisation']]);
|
|
25
28
|
// Short aliases are consumed as `-h` / `-v` / `-V` before the `--flag` branch,
|
|
26
29
|
// so they never appear as keys in `merged` and need no type — but they do land
|
|
27
30
|
// in `flags` (as help/version), so the dispatcher must still tolerate them.
|
|
@@ -134,10 +137,20 @@ export function parseFlags(argv, schema = {}, quiet = false) {
|
|
|
134
137
|
// mistake when the docs say "comma-separated"; silently honouring the
|
|
135
138
|
// last is the one behaviour that can't be recovered from. Refuse, and
|
|
136
139
|
// say what to do instead.
|
|
140
|
+
//
|
|
141
|
+
// The comma-separated suggestion is right for a flag that names a list of
|
|
142
|
+
// things and wrong for one that names a single target: a command writes to
|
|
143
|
+
// one organisation, so `--org a,b` would just build an id that matches no
|
|
144
|
+
// org. Say which case this is rather than offering advice that cannot work.
|
|
137
145
|
if (seenValueFlags.has(key)) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
const previous = flags[key];
|
|
147
|
+
throw new Error(SINGLE_VALUED.has(key)
|
|
148
|
+
? `--${key} was given more than once ("${String(previous)}", then "${raw}"). ` +
|
|
149
|
+
`Only the last would be used, which silently discards the first.\n` +
|
|
150
|
+
`→ A command acts on one ${SINGLE_VALUED.get(key)}. Pass --${key} once.`
|
|
151
|
+
: `--${key} was given more than once. Only the last value would be used, ` +
|
|
152
|
+
`which silently discards the others.\n` +
|
|
153
|
+
`→ If you meant to pass several values, comma-separate them: --${key} a,b,c`);
|
|
141
154
|
}
|
|
142
155
|
seenValueFlags.add(key);
|
|
143
156
|
if (type === 'number') {
|
package/dist/flags.test.js
CHANGED
|
@@ -206,6 +206,19 @@ describe('global flag lists cannot drift', () => {
|
|
|
206
206
|
// other nineteen silently kept the last value. Parse with an empty schema
|
|
207
207
|
// to stand in for a command that declares nothing of its own.
|
|
208
208
|
expect(() => parseFlags(['--org', 'ORG_A', '--org', 'ORG_B'], {}, true)).toThrow(/--org was given more than once/);
|
|
209
|
+
// The generic advice ("comma-separate them") cannot work for org: a command
|
|
210
|
+
// writes to one organisation, and --org a,b is just an id that matches none.
|
|
211
|
+
let msg = '';
|
|
212
|
+
try {
|
|
213
|
+
parseFlags(['--org', 'ORG_A', '--org', 'ORG_B'], {}, true);
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
msg = e.message;
|
|
217
|
+
}
|
|
218
|
+
expect(msg).not.toContain('comma-separate');
|
|
219
|
+
expect(msg).toContain('acts on one organisation');
|
|
220
|
+
expect(msg).toContain('ORG_A');
|
|
221
|
+
expect(msg).toContain('ORG_B');
|
|
209
222
|
});
|
|
210
223
|
it('a single --org still parses to its value under an empty schema', () => {
|
|
211
224
|
const { flags } = parseFlags(['--org', 'ORG_A'], {}, true);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myapihq/cli",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.31.
|
|
4
|
+
"version": "2.31.3",
|
|
5
5
|
"description": "MyAPI command-line interface",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"lint:skills:strict": "node scripts/copy-skills.js && node scripts/lint-skills.js --strict"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@myapihq/sdk": "^2.31.
|
|
50
|
+
"@myapihq/sdk": "^2.31.3"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/node": "^25.6.0",
|