@oclif/core 2.8.1-beta.4 → 2.8.2

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;
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-beta.4",
4
+ "version": "2.8.2",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {
@@ -38,8 +38,8 @@
38
38
  "devDependencies": {
39
39
  "@commitlint/config-conventional": "^12.1.4",
40
40
  "@oclif/plugin-help": "^5.2.8",
41
- "@oclif/plugin-plugins": "^2.4.1",
42
- "@oclif/test": "^2.3.11",
41
+ "@oclif/plugin-plugins": "^2.4.3",
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",
@@ -65,7 +65,7 @@
65
65
  "eslint": "^7.32.0",
66
66
  "eslint-config-oclif": "^4.0.0",
67
67
  "eslint-config-oclif-typescript": "^1.0.3",
68
- "fancy-test": "^2.0.15",
68
+ "fancy-test": "^2.0.16",
69
69
  "globby": "^11.1.0",
70
70
  "husky": "6",
71
71
  "mocha": "^8.4.0",