@oclif/core 2.0.3 → 2.0.5

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.
@@ -1,6 +1,6 @@
1
1
  import { CLIError } from '../errors';
2
2
  import { OptionFlag, Flag } from '../interfaces';
3
- import { Arg, ArgInput, BooleanFlag, CLIParseErrorOptions } from '../interfaces/parser';
3
+ import { Arg, ArgInput, CLIParseErrorOptions } from '../interfaces/parser';
4
4
  export { CLIError } from '../errors';
5
5
  export type Validation = {
6
6
  name: string;
@@ -47,9 +47,6 @@ export declare class NonExistentFlagsError extends CLIParseError {
47
47
  export declare class FlagInvalidOptionError extends CLIParseError {
48
48
  constructor(flag: OptionFlag<any>, input: string);
49
49
  }
50
- export declare class FailedFlagParseError extends CLIParseError {
51
- constructor(flag: BooleanFlag<any> | OptionFlag<any>, errMsg: string);
52
- }
53
50
  export declare class ArgInvalidOptionError extends CLIParseError {
54
51
  constructor(arg: Arg<any>, input: string);
55
52
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FailedFlagParseError = exports.FlagInvalidOptionError = exports.NonExistentFlagsError = exports.UnexpectedArgsError = exports.RequiredFlagError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
3
+ exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FlagInvalidOptionError = exports.NonExistentFlagsError = exports.UnexpectedArgsError = exports.RequiredFlagError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
4
4
  const errors_1 = require("../errors");
5
5
  const help_1 = require("./help");
6
6
  const list_1 = require("../cli-ux/list");
@@ -74,13 +74,6 @@ class FlagInvalidOptionError extends CLIParseError {
74
74
  }
75
75
  }
76
76
  exports.FlagInvalidOptionError = FlagInvalidOptionError;
77
- class FailedFlagParseError extends CLIParseError {
78
- constructor(flag, errMsg) {
79
- const message = `Parsing --${flag.name} \n\t${errMsg}`;
80
- super({ parse: {}, message });
81
- }
82
- }
83
- exports.FailedFlagParseError = FailedFlagParseError;
84
77
  class ArgInvalidOptionError extends CLIParseError {
85
78
  constructor(arg, input) {
86
79
  const message = `Expected ${input} to be one of: ${arg.options.join(', ')}`;
@@ -49,6 +49,9 @@ const readStdin = async () => {
49
49
  }, { once: true });
50
50
  });
51
51
  };
52
+ function isNegativeNumber(input) {
53
+ return /^-\d/g.test(input);
54
+ }
52
55
  class Parser {
53
56
  constructor(input) {
54
57
  this.input = input;
@@ -137,7 +140,7 @@ class Parser {
137
140
  dashdash = true;
138
141
  continue;
139
142
  }
140
- if (this.input['--'] !== false) {
143
+ if (this.input['--'] !== false && !isNegativeNumber(input)) {
141
144
  // At this point we have a value that begins with '-' or '--'
142
145
  // but doesn't match up to a flag definition. So we assume that
143
146
  // this is a misspelled flag or a non-existent flag,
@@ -193,7 +196,7 @@ class Parser {
193
196
  flags[token.flag].push(...values);
194
197
  }
195
198
  else {
196
- const value = flag.parse ? await flag.parse(input, this.context, flag) : input;
199
+ const value = await this._parseFlag(input, flag);
197
200
  if (flag.multiple) {
198
201
  flags[token.flag] = flags[token.flag] || [];
199
202
  flags[token.flag].push(value);
@@ -213,7 +216,7 @@ class Parser {
213
216
  if (flag.type === 'option') {
214
217
  if (input) {
215
218
  this._validateOptions(flag, input);
216
- flags[k] = await flag.parse(input, this.context, flag);
219
+ flags[k] = await this._parseFlag(input, flag);
217
220
  }
218
221
  }
219
222
  else if (flag.type === 'boolean') {
@@ -230,6 +233,8 @@ class Parser {
230
233
  return flags;
231
234
  }
232
235
  async _parseFlag(input, flag) {
236
+ if (!flag.parse)
237
+ return input;
233
238
  try {
234
239
  if (flag.type === 'boolean') {
235
240
  return await flag.parse(input, this.context, flag);
@@ -237,7 +242,8 @@ class Parser {
237
242
  return flag.parse ? await flag.parse(input, this.context, flag) : input;
238
243
  }
239
244
  catch (error) {
240
- throw new errors_1.FailedFlagParseError(flag, error.message);
245
+ error.message = `Parsing --${flag.name} \n\t${error.message}\nSee more help with --help`;
246
+ throw error;
241
247
  }
242
248
  }
243
249
  _validateOptions(flag, input) {
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": "2.0.3",
4
+ "version": "2.0.5",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {