@oclif/core 4.6.0 → 4.7.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/lib/command.d.ts CHANGED
@@ -73,6 +73,7 @@ export declare abstract class Command {
73
73
  static usage: string | string[] | undefined;
74
74
  protected debug: (...args: any[]) => void;
75
75
  id: string | undefined;
76
+ parsed: boolean;
76
77
  constructor(argv: string[], config: Config);
77
78
  /**
78
79
  * instantiate and run the command
package/lib/command.js CHANGED
@@ -128,6 +128,7 @@ class Command {
128
128
  static usage;
129
129
  debug;
130
130
  id;
131
+ parsed = false;
131
132
  constructor(argv, config) {
132
133
  this.argv = argv;
133
134
  this.config = config;
@@ -189,6 +190,11 @@ class Command {
189
190
  }
190
191
  if (result && this.jsonEnabled())
191
192
  this.logJson(this.toSuccessJson(result));
193
+ if (!this.parsed && !(0, util_2.isProd)()) {
194
+ process.emitWarning(`Command ${this.id} did not parse its arguments. Did you forget to call 'this.parse'?`, {
195
+ code: 'UnparsedCommand',
196
+ });
197
+ }
192
198
  return result;
193
199
  }
194
200
  async catch(err) {
@@ -273,6 +279,7 @@ class Command {
273
279
  this.argv = [...argvToParse];
274
280
  const results = await Parser.parse(argvToParse, opts);
275
281
  this.warnIfFlagDeprecated(results.flags ?? {});
282
+ this.parsed = true;
276
283
  return results;
277
284
  }
278
285
  toErrorJson(err) {
@@ -75,6 +75,7 @@ const validateOptions = (flag, input) => {
75
75
  throw new errors_1.FlagInvalidOptionError(flag, input);
76
76
  return input;
77
77
  };
78
+ const NEGATION = '--no-';
78
79
  class Parser {
79
80
  input;
80
81
  argv;
@@ -299,9 +300,16 @@ class Parser {
299
300
  if (tokenLength) {
300
301
  // boolean
301
302
  if (fws.inputFlag.flag.type === 'boolean' && (0, util_1.last)(fws.tokens)?.input) {
303
+ const doesNotContainNegation = (i) => {
304
+ const possibleNegations = [i.inputFlag.name, ...(i.inputFlag.flag.aliases ?? [])].map((n) => `${NEGATION}${n}`);
305
+ const input = (0, util_1.last)(i.tokens)?.input;
306
+ if (!input)
307
+ return true;
308
+ return !possibleNegations.includes(input);
309
+ };
302
310
  return {
303
311
  ...fws,
304
- valueFunction: async (i) => parseFlagOrThrowError((0, util_1.last)(i.tokens)?.input !== `--no-${i.inputFlag.name}`, i.inputFlag.flag, this.context, (0, util_1.last)(i.tokens)),
312
+ valueFunction: async (i) => parseFlagOrThrowError(doesNotContainNegation(i), i.inputFlag.flag, this.context, (0, util_1.last)(i.tokens)),
305
313
  };
306
314
  }
307
315
  // multiple with custom delimiter
@@ -455,10 +463,14 @@ class Parser {
455
463
  if (this.flagAliases[name]) {
456
464
  return this.flagAliases[name].name;
457
465
  }
458
- if (arg.startsWith('--no-')) {
459
- const flag = this.booleanFlags[arg.slice(5)];
466
+ if (arg.startsWith(NEGATION)) {
467
+ const flag = this.booleanFlags[arg.slice(NEGATION.length)];
460
468
  if (flag && flag.allowNo)
461
469
  return flag.name;
470
+ const flagAlias = this.flagAliases[arg.slice(NEGATION.length)];
471
+ if (flagAlias && flagAlias.type === 'boolean' && flagAlias.allowNo) {
472
+ return flagAlias.name;
473
+ }
462
474
  }
463
475
  }
464
476
  findShortFlag([_, char]) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "4.6.0",
4
+ "version": "4.7.1",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {