@oclif/core 1.24.2 → 1.24.4

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.
@@ -677,10 +677,7 @@ async function toCached(c, plugin) {
677
677
  }
678
678
  }
679
679
  }
680
- // v2 commands have args as an object, so we need to normalize it to an array for forwards compatibility
681
- // @ts-ignore
682
- const normalized = Array.isArray(c.args) ? c.args ?? [] : Object.entries(c.args ?? {}).map(([name, arg]) => ({ ...arg, name }));
683
- const argsPromise = normalized.map(async (a) => ({
680
+ const argsPromise = (0, util_3.ensureArgArray)(c.args).map(async (a) => ({
684
681
  name: a.name,
685
682
  description: a.description,
686
683
  required: a.required,
@@ -31,7 +31,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
31
31
  v.name = k;
32
32
  return v;
33
33
  }), f => [!f.char, f.char, f.name]);
34
- const args = (cmd.args || []).filter(a => !a.hidden);
34
+ const args = (0, util_1.ensureArgArray)(cmd.args).filter(a => !a.hidden);
35
35
  const output = (0, util_1.compact)(this.sections().map(({ header, generate }) => {
36
36
  const body = generate({ cmd, flags, args }, header);
37
37
  // Generate can return a list of sections
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocOpts = void 0;
4
+ const util_1 = require("../util");
4
5
  /**
5
6
  * DocOpts - See http://docopt.org/.
6
7
  *
@@ -75,7 +76,7 @@ class DocOpts {
75
76
  toString() {
76
77
  const opts = this.cmd.id === '.' || this.cmd.id === '' ? [] : ['<%= command.id %>'];
77
78
  if (this.cmd.args) {
78
- const a = this.cmd.args?.map(arg => `[${arg.name.toUpperCase()}]`) || [];
79
+ const a = (0, util_1.ensureArgArray)(this.cmd.args).map(arg => `[${arg.name.toUpperCase()}]`) || [];
79
80
  opts.push(...a);
80
81
  }
81
82
  try {
package/lib/help/util.js CHANGED
@@ -45,7 +45,7 @@ function collateSpacedCmdIDFromArgs(argv, config) {
45
45
  if (!id)
46
46
  return false;
47
47
  const cmd = config.findCommand(id);
48
- return Boolean(cmd && (cmd.strict === false || cmd.args?.length > 0));
48
+ return Boolean(cmd && (cmd.strict === false || Object.values(cmd.args ?? {}).length > 0));
49
49
  };
50
50
  for (const arg of argv) {
51
51
  if (idPresent(finalizeId(arg)))
package/lib/util.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ArgInput } from './interfaces';
1
2
  export declare function compact<T>(a: (T | undefined)[]): T[];
2
3
  export declare function uniqBy<T>(arr: T[], fn: (cur: T) => any): T[];
3
4
  type SortTypes = string | number | undefined | boolean;
@@ -7,4 +8,14 @@ export declare function isProd(): boolean;
7
8
  export declare function maxBy<T>(arr: T[], fn: (i: T) => number): T | undefined;
8
9
  export declare function sumBy<T>(arr: T[], fn: (i: T) => number): number;
9
10
  export declare function capitalize(s: string): string;
11
+ /**
12
+ * Ensure that the args are in an array instead of an object. This is required to ensure
13
+ * forwards compatibility with the new arg format in v2.
14
+ *
15
+ * @param args The args to ensure are in an array
16
+ * @returns ArgInput
17
+ */
18
+ export declare function ensureArgArray(args?: ArgInput | {
19
+ [name: string]: any;
20
+ }): ArgInput;
10
21
  export {};
package/lib/util.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.uniqBy = exports.compact = void 0;
3
+ exports.ensureArgArray = exports.capitalize = exports.sumBy = exports.maxBy = exports.isProd = exports.castArray = exports.sortBy = exports.uniqBy = exports.compact = void 0;
4
4
  function compact(a) {
5
5
  return a.filter((a) => Boolean(a));
6
6
  }
@@ -62,3 +62,14 @@ function capitalize(s) {
62
62
  return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : '';
63
63
  }
64
64
  exports.capitalize = capitalize;
65
+ /**
66
+ * Ensure that the args are in an array instead of an object. This is required to ensure
67
+ * forwards compatibility with the new arg format in v2.
68
+ *
69
+ * @param args The args to ensure are in an array
70
+ * @returns ArgInput
71
+ */
72
+ function ensureArgArray(args) {
73
+ return Array.isArray(args) ? args ?? [] : Object.entries(args ?? {}).map(([name, arg]) => ({ ...arg, name }));
74
+ }
75
+ exports.ensureArgArray = ensureArgArray;
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": "1.24.2",
4
+ "version": "1.24.4",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -114,4 +114,4 @@
114
114
  "pretest": "yarn build --noEmit && tsc -p test --noEmit --skipLibCheck"
115
115
  },
116
116
  "types": "lib/index.d.ts"
117
- }
117
+ }