@oclif/core 3.14.0 → 3.15.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.
@@ -16,6 +16,16 @@ const formatter_1 = require("./formatter");
16
16
  // written on any platform, that may use \r\n or \n, will be
17
17
  // split on any platform, not just the os specific EOL at runtime.
18
18
  const POSSIBLE_LINE_FEED = /\r\n|\n/;
19
+ /**
20
+ * Determines the sort order of flags. Will default to alphabetical if not set or set to an invalid value.
21
+ */
22
+ function determineSortOrder(flagSortOrder) {
23
+ if (flagSortOrder === 'alphabetical')
24
+ return 'alphabetical';
25
+ if (flagSortOrder === 'none')
26
+ return 'none';
27
+ return 'alphabetical';
28
+ }
19
29
  class CommandHelp extends formatter_1.HelpFormatter {
20
30
  command;
21
31
  config;
@@ -197,12 +207,15 @@ class CommandHelp extends formatter_1.HelpFormatter {
197
207
  }
198
208
  generate() {
199
209
  const cmd = this.command;
200
- const flags = (0, util_1.sortBy)(Object.entries(cmd.flags || {})
210
+ const unsortedFlags = Object.entries(cmd.flags || {})
201
211
  .filter(([, v]) => !v.hidden)
202
212
  .map(([k, v]) => {
203
213
  v.name = k;
204
214
  return v;
205
- }), (f) => [!f.char, f.char, f.name]);
215
+ });
216
+ const flags = determineSortOrder(this.opts.flagSortOrder) === 'alphabetical'
217
+ ? (0, util_1.sortBy)(unsortedFlags, (f) => [!f.char, f.char, f.name])
218
+ : unsortedFlags;
206
219
  const args = Object.values((0, ensure_arg_object_1.ensureArgObject)(cmd.args)).filter((a) => !a.hidden);
207
220
  const output = (0, util_1.compact)(this.sections().map(({ generate, header }) => {
208
221
  const body = generate({ args, cmd, flags }, header);
@@ -4,6 +4,13 @@ export interface HelpOptions {
4
4
  * Use docopts as the usage. Defaults to true.
5
5
  */
6
6
  docopts?: boolean;
7
+ /**
8
+ * Order in which to sort flags in help output. Defaults to `alphabetical`.
9
+ *
10
+ * `alphabetical`: Sort flags alphabetically. All flags with short characters will come first.
11
+ * `none`: Do not sort flags. They will appear in the order in which they were defined on the command.
12
+ */
13
+ flagSortOrder?: 'alphabetical' | 'none';
7
14
  /**
8
15
  * If true, hide command aliases from the root help output. Defaults to false.
9
16
  */
@@ -49,9 +49,3 @@ export declare class FailedFlagValidationError extends CLIParseError {
49
49
  failed: Validation[];
50
50
  });
51
51
  }
52
- export declare class FailedFlagParsingError extends CLIParseError {
53
- constructor({ flag, message }: {
54
- flag: string;
55
- message: string;
56
- });
57
- }
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FailedFlagParsingError = exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FlagInvalidOptionError = exports.NonExistentFlagsError = exports.UnexpectedArgsError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
6
+ exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FlagInvalidOptionError = exports.NonExistentFlagsError = exports.UnexpectedArgsError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const cache_1 = __importDefault(require("../cache"));
9
9
  const list_1 = require("../cli-ux/list");
@@ -95,13 +95,3 @@ class FailedFlagValidationError extends CLIParseError {
95
95
  }
96
96
  }
97
97
  exports.FailedFlagValidationError = FailedFlagValidationError;
98
- class FailedFlagParsingError extends CLIParseError {
99
- constructor({ flag, message }) {
100
- super({
101
- exit: cache_1.default.getInstance().get('exitCodes')?.failedFlagParsing,
102
- message: `Parsing --${flag} \n\t${message}`,
103
- parse: {},
104
- });
105
- }
106
- }
107
- exports.FailedFlagParsingError = FailedFlagParsingError;
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Parser = exports.readStdin = void 0;
4
7
  /* eslint-disable no-await-in-loop */
5
8
  const node_readline_1 = require("node:readline");
9
+ const cache_1 = __importDefault(require("../cache"));
6
10
  const util_1 = require("../util/util");
7
11
  const errors_1 = require("./errors");
8
12
  let debug;
@@ -264,7 +268,10 @@ class Parser {
264
268
  return await flag.parse(input, ctx, flag);
265
269
  }
266
270
  catch (error) {
267
- throw new errors_1.FailedFlagParsingError({ flag: flag.name, message: error.message });
271
+ error.message = `Parsing --${flag.name} \n\t${error.message}\nSee more help with --help`;
272
+ if (cache_1.default.getInstance().get('exitCodes')?.failedFlagParsing)
273
+ error.oclif = { exit: cache_1.default.getInstance().get('exitCodes')?.failedFlagParsing };
274
+ throw error;
268
275
  }
269
276
  };
270
277
  /* Could add a valueFunction (if there is a value/env/default) and could metadata.
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": "3.14.0",
4
+ "version": "3.15.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -35,19 +35,19 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@commitlint/config-conventional": "^17.8.1",
38
- "@oclif/plugin-help": "^5.2.20",
39
- "@oclif/plugin-plugins": "^3.3.0",
38
+ "@oclif/plugin-help": "^6",
39
+ "@oclif/plugin-plugins": "^4",
40
40
  "@oclif/prettier-config": "^0.2.1",
41
41
  "@oclif/test": "^3.0.3",
42
42
  "@types/ansi-styles": "^3.2.1",
43
- "@types/benchmark": "^2.1.2",
44
- "@types/chai": "^4.3.10",
43
+ "@types/benchmark": "^2.1.5",
44
+ "@types/chai": "^4.3.11",
45
45
  "@types/chai-as-promised": "^7.1.8",
46
46
  "@types/clean-stack": "^2.1.1",
47
- "@types/cli-progress": "^3.11.0",
47
+ "@types/cli-progress": "^3.11.5",
48
48
  "@types/color": "^3.0.5",
49
49
  "@types/debug": "^4.1.10",
50
- "@types/ejs": "^3.1.3",
50
+ "@types/ejs": "^3.1.5",
51
51
  "@types/indent-string": "^4.0.1",
52
52
  "@types/js-yaml": "^3.12.7",
53
53
  "@types/mocha": "^10.0.2",