@oclif/core 2.8.1 → 2.8.3-beta.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
@@ -65,9 +65,13 @@ export declare abstract class Command {
65
65
  */
66
66
  static examples: Command.Example[];
67
67
  static hasDynamicHelp: boolean;
68
+ protected static '_--': boolean;
68
69
  protected static _enableJsonFlag: boolean;
69
70
  static get enableJsonFlag(): boolean;
70
71
  static set enableJsonFlag(value: boolean);
72
+ static get '--'(): boolean;
73
+ static set '--'(value: boolean);
74
+ get passThroughEnabled(): boolean;
71
75
  /**
72
76
  * instantiate and run the command
73
77
  *
@@ -101,6 +105,11 @@ export declare abstract class Command {
101
105
  } & PrettyPrintableError): never;
102
106
  log(message?: string, ...args: any[]): void;
103
107
  logToStderr(message?: string, ...args: any[]): void;
108
+ /**
109
+ * Determine if the command is being run with the --json flag in a command that supports it.
110
+ *
111
+ * @returns {boolean} true if the command supports json and the --json flag is present
112
+ */
104
113
  jsonEnabled(): boolean;
105
114
  /**
106
115
  * actual command run code goes here
package/lib/command.js CHANGED
@@ -47,6 +47,15 @@ class Command {
47
47
  delete this.flags?.json;
48
48
  }
49
49
  }
50
+ static get '--'() {
51
+ return Command['_--'];
52
+ }
53
+ static set '--'(value) {
54
+ Command['_--'] = value;
55
+ }
56
+ get passThroughEnabled() {
57
+ return Command['_--'];
58
+ }
50
59
  /**
51
60
  * instantiate and run the command
52
61
  *
@@ -141,8 +150,22 @@ class Command {
141
150
  stream_1.stderr.write((0, util_1.format)(message, ...args) + '\n');
142
151
  }
143
152
  }
153
+ /**
154
+ * Determine if the command is being run with the --json flag in a command that supports it.
155
+ *
156
+ * @returns {boolean} true if the command supports json and the --json flag is present
157
+ */
144
158
  jsonEnabled() {
145
- return this.ctor.enableJsonFlag && this.argv.includes('--json');
159
+ // if the command doesn't support json, return false
160
+ if (!this.ctor.enableJsonFlag)
161
+ return false;
162
+ // if the command parameter pass through is enabled, return true if the --json flag is before the '--' separator
163
+ if (this.passThroughEnabled) {
164
+ const ptIndex = this.argv.indexOf('--');
165
+ const jsonIndex = this.argv.indexOf('--json');
166
+ return jsonIndex > -1 && (ptIndex === -1 || jsonIndex < ptIndex);
167
+ }
168
+ return this.argv.includes('--json');
146
169
  }
147
170
  async init() {
148
171
  this.debug('init version: %s argv: %o', this.ctor._base, this.argv);
@@ -243,4 +266,5 @@ Command.strict = true;
243
266
  /** An order-dependent object of arguments for the command */
244
267
  Command.args = {};
245
268
  Command.hasDynamicHelp = false;
269
+ Command['_--'] = false;
246
270
  Command._enableJsonFlag = false;
@@ -726,7 +726,7 @@ const defaultFlagToCached = async (flag, isWritingManifest = false) => {
726
726
  // if not specified, try the default function
727
727
  if (typeof flag.default === 'function') {
728
728
  try {
729
- return await flag.default({ options: {}, flags: {} }, isWritingManifest);
729
+ return await flag.default({ options: flag, flags: {} }, isWritingManifest);
730
730
  }
731
731
  catch { }
732
732
  }
@@ -747,7 +747,7 @@ const defaultArgToCached = async (arg, isWritingManifest = false) => {
747
747
  // if not specified, try the default function
748
748
  if (typeof arg.default === 'function') {
749
749
  try {
750
- return await arg.default({ options: arg, flags: {} }, isWritingManifest);
750
+ return await arg.default(isWritingManifest);
751
751
  }
752
752
  catch { }
753
753
  }
@@ -231,10 +231,7 @@ class Parser {
231
231
  }
232
232
  if (!(k in flags) && flag.default !== undefined) {
233
233
  this.metaData.flags[k] = { ...this.metaData.flags[k], setFromDefault: true };
234
- const defaultValue = (typeof flag.default === 'function' ? await flag.default({
235
- options: flag,
236
- flags, ...this.context,
237
- }) : flag.default);
234
+ const defaultValue = (typeof flag.default === 'function' ? await flag.default({ options: flag, flags }) : flag.default);
238
235
  flags[k] = defaultValue;
239
236
  }
240
237
  }
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.8.1",
4
+ "version": "2.8.3-beta.1",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -39,7 +39,7 @@
39
39
  "@commitlint/config-conventional": "^12.1.4",
40
40
  "@oclif/plugin-help": "^5.2.8",
41
41
  "@oclif/plugin-plugins": "^2.4.3",
42
- "@oclif/test": "^2.3.11",
42
+ "@oclif/test": "^2.3.15",
43
43
  "@types/ansi-styles": "^3.2.1",
44
44
  "@types/chai": "^4.3.4",
45
45
  "@types/chai-as-promised": "^7.1.5",