@oclif/core 3.0.0-beta.9 → 3.0.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.
Files changed (142) hide show
  1. package/README.md +4 -2
  2. package/flush.d.ts +3 -0
  3. package/flush.js +1 -0
  4. package/handle.js +1 -0
  5. package/lib/args.d.ts +2 -2
  6. package/lib/args.js +17 -18
  7. package/lib/{ux → cli-ux}/action/base.d.ts +19 -21
  8. package/lib/{ux → cli-ux}/action/base.js +126 -120
  9. package/lib/{ux → cli-ux}/action/simple.js +25 -30
  10. package/lib/{ux → cli-ux}/action/spinner.d.ts +9 -7
  11. package/lib/{ux → cli-ux}/action/spinner.js +45 -37
  12. package/lib/{ux → cli-ux}/action/spinners.js +187 -187
  13. package/lib/cli-ux/action/types.d.ts +5 -0
  14. package/lib/cli-ux/action/types.js +2 -0
  15. package/lib/{ux → cli-ux}/config.d.ts +5 -5
  16. package/lib/{ux → cli-ux}/config.js +17 -17
  17. package/lib/{ux → cli-ux}/exit.js +3 -0
  18. package/lib/cli-ux/flush.d.ts +1 -0
  19. package/lib/cli-ux/flush.js +28 -0
  20. package/lib/cli-ux/index.d.ts +39 -0
  21. package/lib/{ux → cli-ux}/index.js +74 -88
  22. package/lib/{ux → cli-ux}/list.js +3 -3
  23. package/lib/{ux → cli-ux}/prompt.d.ts +3 -3
  24. package/lib/{ux → cli-ux}/prompt.js +35 -25
  25. package/lib/{ux → cli-ux}/stream.d.ts +6 -6
  26. package/lib/{ux → cli-ux}/stream.js +11 -10
  27. package/lib/cli-ux/styled/index.d.ts +4 -0
  28. package/lib/cli-ux/styled/index.js +11 -0
  29. package/lib/{ux → cli-ux}/styled/object.js +7 -9
  30. package/lib/{ux → cli-ux}/styled/table.d.ts +10 -10
  31. package/lib/{ux → cli-ux}/styled/table.js +130 -133
  32. package/lib/{ux → cli-ux}/styled/tree.js +11 -13
  33. package/lib/cli-ux/wait.js +5 -0
  34. package/lib/command.d.ts +82 -88
  35. package/lib/command.js +196 -175
  36. package/lib/config/config.d.ts +89 -90
  37. package/lib/config/config.js +466 -566
  38. package/lib/config/index.d.ts +0 -1
  39. package/lib/config/index.js +1 -3
  40. package/lib/config/plugin-loader.d.ts +12 -12
  41. package/lib/config/plugin-loader.js +72 -56
  42. package/lib/config/plugin.d.ts +25 -24
  43. package/lib/config/plugin.js +188 -154
  44. package/lib/config/ts-node.d.ts +2 -1
  45. package/lib/config/ts-node.js +71 -58
  46. package/lib/config/util.d.ts +1 -11
  47. package/lib/config/util.js +6 -59
  48. package/lib/errors/config.d.ts +1 -1
  49. package/lib/errors/config.js +6 -6
  50. package/lib/errors/errors/cli.d.ts +7 -7
  51. package/lib/errors/errors/cli.js +20 -16
  52. package/lib/errors/errors/exit.d.ts +1 -4
  53. package/lib/errors/errors/exit.js +1 -1
  54. package/lib/errors/errors/module-load.d.ts +1 -4
  55. package/lib/errors/errors/module-load.js +1 -1
  56. package/lib/errors/errors/pretty-print.d.ts +1 -1
  57. package/lib/errors/errors/pretty-print.js +12 -10
  58. package/lib/errors/handle.d.ts +12 -2
  59. package/lib/errors/handle.js +26 -14
  60. package/lib/errors/index.d.ts +10 -10
  61. package/lib/errors/index.js +25 -24
  62. package/lib/errors/logger.d.ts +2 -2
  63. package/lib/errors/logger.js +14 -13
  64. package/lib/execute.d.ts +6 -6
  65. package/lib/execute.js +10 -9
  66. package/lib/flags.d.ts +103 -32
  67. package/lib/flags.js +79 -45
  68. package/lib/help/command.d.ts +16 -14
  69. package/lib/help/command.js +178 -163
  70. package/lib/help/docopts.d.ts +5 -5
  71. package/lib/help/docopts.js +50 -54
  72. package/lib/help/formatter.d.ts +37 -37
  73. package/lib/help/formatter.js +66 -55
  74. package/lib/help/index.d.ts +25 -21
  75. package/lib/help/index.js +169 -147
  76. package/lib/help/root.d.ts +1 -1
  77. package/lib/help/root.js +15 -17
  78. package/lib/help/util.d.ts +2 -8
  79. package/lib/help/util.js +8 -28
  80. package/lib/index.d.ts +19 -20
  81. package/lib/index.js +37 -43
  82. package/lib/interfaces/config.d.ts +67 -66
  83. package/lib/interfaces/errors.d.ts +5 -5
  84. package/lib/interfaces/help.d.ts +17 -17
  85. package/lib/interfaces/hooks.d.ts +49 -49
  86. package/lib/interfaces/index.d.ts +7 -7
  87. package/lib/interfaces/manifest.d.ts +1 -1
  88. package/lib/interfaces/parser.d.ts +175 -51
  89. package/lib/interfaces/pjson.d.ts +45 -41
  90. package/lib/interfaces/plugin.d.ts +47 -41
  91. package/lib/interfaces/s3-manifest.d.ts +7 -7
  92. package/lib/interfaces/topic.d.ts +1 -1
  93. package/lib/interfaces/ts-config.d.ts +7 -7
  94. package/lib/main.d.ts +2 -2
  95. package/lib/main.js +16 -16
  96. package/lib/module-loader.d.ts +67 -77
  97. package/lib/module-loader.js +183 -150
  98. package/lib/parser/errors.d.ts +7 -7
  99. package/lib/parser/errors.js +29 -22
  100. package/lib/parser/help.js +5 -5
  101. package/lib/parser/index.js +2 -2
  102. package/lib/parser/parse.d.ts +9 -6
  103. package/lib/parser/parse.js +253 -221
  104. package/lib/parser/validate.js +53 -33
  105. package/lib/performance.d.ts +43 -32
  106. package/lib/performance.js +133 -91
  107. package/lib/screen.js +2 -2
  108. package/lib/settings.d.ts +11 -12
  109. package/lib/settings.js +2 -2
  110. package/lib/util/aggregate-flags.d.ts +2 -0
  111. package/lib/util/aggregate-flags.js +13 -0
  112. package/lib/util/cache-command.d.ts +3 -0
  113. package/lib/util/cache-command.js +109 -0
  114. package/lib/util/cache-default-value.d.ts +2 -0
  115. package/lib/util/cache-default-value.js +28 -0
  116. package/lib/util/ensure-arg-object.d.ts +12 -0
  117. package/lib/util/ensure-arg-object.js +14 -0
  118. package/lib/util/fs.d.ts +7 -0
  119. package/lib/util/fs.js +54 -0
  120. package/lib/util/os.d.ts +19 -0
  121. package/lib/util/os.js +28 -0
  122. package/lib/{util.d.ts → util/util.d.ts} +7 -16
  123. package/lib/util/util.js +98 -0
  124. package/package.json +35 -37
  125. package/lib/util.js +0 -126
  126. package/lib/ux/flush.d.ts +0 -1
  127. package/lib/ux/flush.js +0 -27
  128. package/lib/ux/index.d.ts +0 -58
  129. package/lib/ux/styled/index.d.ts +0 -6
  130. package/lib/ux/styled/index.js +0 -13
  131. package/lib/ux/styled/json.d.ts +0 -1
  132. package/lib/ux/styled/json.js +0 -15
  133. package/lib/ux/wait.js +0 -7
  134. package/lib/{ux → cli-ux}/action/simple.d.ts +4 -4
  135. package/lib/{ux → cli-ux}/action/spinners.d.ts +117 -117
  136. package/lib/{ux → cli-ux}/exit.d.ts +2 -2
  137. package/lib/{ux → cli-ux}/list.d.ts +0 -0
  138. package/lib/{ux → cli-ux}/styled/object.d.ts +0 -0
  139. package/lib/{ux → cli-ux}/styled/progress.d.ts +0 -0
  140. package/lib/{ux → cli-ux}/styled/progress.js +0 -0
  141. package/lib/{ux → cli-ux}/styled/tree.d.ts +1 -1
  142. /package/lib/{ux → cli-ux}/wait.d.ts +0 -0
package/lib/command.js CHANGED
@@ -1,18 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Command = void 0;
4
- const url_1 = require("url");
5
- const chalk = require("chalk");
6
- const util_1 = require("util");
7
- const ux_1 = require("./ux");
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const node_url_1 = require("node:url");
7
+ const node_util_1 = require("node:util");
8
+ const cli_ux_1 = require("./cli-ux");
9
+ const stream_1 = require("./cli-ux/stream");
8
10
  const config_1 = require("./config");
9
- const Errors = require("./errors");
10
- const Parser = require("./parser");
11
- const util_2 = require("./help/util");
12
- const flags_1 = require("./flags");
13
- const util_3 = require("./util");
14
- const stream_1 = require("./ux/stream");
15
- const pjson = (0, util_3.requireJson)(__dirname, '..', 'package.json');
11
+ const Errors = tslib_1.__importStar(require("./errors"));
12
+ const util_1 = require("./help/util");
13
+ const Parser = tslib_1.__importStar(require("./parser"));
14
+ const aggregate_flags_1 = require("./util/aggregate-flags");
15
+ const fs_1 = require("./util/fs");
16
+ const util_2 = require("./util/util");
17
+ const pjson = (0, fs_1.requireJson)(__dirname, '..', 'package.json');
16
18
  /**
17
19
  * swallows stdout epipe errors
18
20
  * this occurs when stdout closes such as when piping to head
@@ -22,40 +24,86 @@ stream_1.stdout.on('error', (err) => {
22
24
  return;
23
25
  throw err;
24
26
  });
25
- const jsonFlag = {
26
- json: (0, flags_1.boolean)({
27
- description: 'Format output as json.',
28
- helpGroup: 'GLOBAL',
29
- }),
30
- };
31
27
  /**
32
28
  * An abstract class which acts as the base for each command
33
29
  * in your project.
34
30
  */
35
31
  class Command {
36
- static get enableJsonFlag() {
37
- return this._enableJsonFlag;
38
- }
39
- static set enableJsonFlag(value) {
40
- this._enableJsonFlag = value;
41
- if (value === true) {
42
- this.baseFlags = jsonFlag;
32
+ argv;
33
+ config;
34
+ /** An array of aliases for this command. */
35
+ static aliases = [];
36
+ /** An order-dependent object of arguments for the command */
37
+ static args = {};
38
+ static baseFlags;
39
+ /**
40
+ * Emit deprecation warning when a command alias is used
41
+ */
42
+ static deprecateAliases;
43
+ static deprecationOptions;
44
+ /**
45
+ * A full description of how to use the command.
46
+ *
47
+ * If no summary, the first line of the description will be used as the summary.
48
+ */
49
+ static description;
50
+ static enableJsonFlag = false;
51
+ /**
52
+ * An array of examples to show at the end of the command's help.
53
+ *
54
+ * IF only a string is provided, it will try to look for a line that starts
55
+ * with the cmd.bin as the example command and the rest as the description.
56
+ * If found, the command will be formatted appropriately.
57
+ *
58
+ * ```
59
+ * EXAMPLES:
60
+ * A description of a particular use case.
61
+ *
62
+ * $ <%= config.bin => command flags
63
+ * ```
64
+ */
65
+ static examples;
66
+ /** A hash of flags for the command */
67
+ static flags;
68
+ static hasDynamicHelp = false;
69
+ static help;
70
+ /** Hide the command from help */
71
+ static hidden;
72
+ /** A command ID, used mostly in error or verbose reporting. */
73
+ static id;
74
+ static plugin;
75
+ static pluginAlias;
76
+ static pluginName;
77
+ static pluginType;
78
+ /** Mark the command as a given state (e.g. beta or deprecated) in help */
79
+ static state;
80
+ /** When set to false, allows a variable amount of arguments */
81
+ static strict = true;
82
+ /**
83
+ * The tweet-sized description for your class, used in a parent-commands
84
+ * sub-command listing and as the header for the command help.
85
+ */
86
+ static summary;
87
+ /**
88
+ * An override string (or strings) for the default usage documentation.
89
+ */
90
+ static usage;
91
+ static _base = `${pjson.name}@${pjson.version}`;
92
+ debug;
93
+ id;
94
+ constructor(argv, config) {
95
+ this.argv = argv;
96
+ this.config = config;
97
+ this.id = this.ctor.id;
98
+ try {
99
+ this.debug = require('debug')(this.id ? `${this.config.bin}:${this.id}` : this.config.bin);
43
100
  }
44
- else {
45
- delete this.baseFlags?.json;
46
- this.flags = {}; // force the flags setter to run
47
- delete this.flags?.json;
101
+ catch {
102
+ this.debug = () => {
103
+ // noop
104
+ };
48
105
  }
49
106
  }
50
- static get '--'() {
51
- return Command['_--'];
52
- }
53
- static set '--'(value) {
54
- Command['_--'] = value;
55
- }
56
- get passThroughEnabled() {
57
- return Command['_--'];
58
- }
59
107
  /**
60
108
  * instantiate and run the command
61
109
  *
@@ -69,7 +117,7 @@ class Command {
69
117
  argv = process.argv.slice(2);
70
118
  // Handle the case when a file URL string is passed in such as 'import.meta.url'; covert to file path.
71
119
  if (typeof opts === 'string' && opts.startsWith('file://')) {
72
- opts = (0, url_1.fileURLToPath)(opts);
120
+ opts = (0, node_url_1.fileURLToPath)(opts);
73
121
  }
74
122
  const config = await config_1.Config.load(opts || require.main?.filename || __dirname);
75
123
  const cmd = new this(argv, config);
@@ -80,33 +128,6 @@ class Command {
80
128
  }
81
129
  return cmd._run();
82
130
  }
83
- static get baseFlags() {
84
- return this._baseFlags;
85
- }
86
- static set baseFlags(flags) {
87
- this._baseFlags = Object.assign({}, this.baseFlags, flags);
88
- this.flags = {}; // force the flags setter to run
89
- }
90
- static get flags() {
91
- return this._flags;
92
- }
93
- static set flags(flags) {
94
- this._flags = Object.assign({}, this._flags ?? {}, this.baseFlags, flags);
95
- }
96
- constructor(argv, config) {
97
- this.argv = argv;
98
- this.config = config;
99
- this.id = this.ctor.id;
100
- try {
101
- this.debug = require('debug')(this.id ? `${this.config.bin}:${this.id}` : this.config.bin);
102
- }
103
- catch {
104
- this.debug = () => { };
105
- }
106
- }
107
- get ctor() {
108
- return this.constructor;
109
- }
110
131
  async _run() {
111
132
  let err;
112
133
  let result;
@@ -127,45 +148,46 @@ class Command {
127
148
  this.logJson(this.toSuccessJson(result));
128
149
  return result;
129
150
  }
130
- exit(code = 0) {
131
- Errors.exit(code);
151
+ removeEnvVar(envVar) {
152
+ const keys = [];
153
+ try {
154
+ keys.push(...this.config.scopedEnvVarKeys(envVar));
155
+ }
156
+ catch {
157
+ keys.push(this.config.scopedEnvVarKey(envVar));
158
+ }
159
+ keys.map((key) => delete process.env[key]);
132
160
  }
133
- warn(input) {
134
- if (!this.jsonEnabled())
135
- Errors.warn(input);
136
- return input;
161
+ async catch(err) {
162
+ process.exitCode = process.exitCode ?? err.exitCode ?? 1;
163
+ if (this.jsonEnabled()) {
164
+ this.logJson(this.toErrorJson(err));
165
+ }
166
+ else {
167
+ if (!err.message)
168
+ throw err;
169
+ try {
170
+ cli_ux_1.ux.action.stop(chalk_1.default.bold.red('!'));
171
+ }
172
+ catch { }
173
+ throw err;
174
+ }
137
175
  }
138
176
  error(input, options = {}) {
139
177
  return Errors.error(input, options);
140
178
  }
141
- log(message = '', ...args) {
142
- if (!this.jsonEnabled()) {
143
- message = typeof message === 'string' ? message : (0, util_1.inspect)(message);
144
- stream_1.stdout.write((0, util_1.format)(message, ...args) + '\n');
145
- }
179
+ exit(code = 0) {
180
+ Errors.exit(code);
146
181
  }
147
- logToStderr(message = '', ...args) {
148
- if (!this.jsonEnabled()) {
149
- message = typeof message === 'string' ? message : (0, util_1.inspect)(message);
150
- stream_1.stderr.write((0, util_1.format)(message, ...args) + '\n');
182
+ async finally(_) {
183
+ try {
184
+ const { config } = Errors;
185
+ if (config.errorLogger)
186
+ await config.errorLogger.flush();
151
187
  }
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
- */
158
- jsonEnabled() {
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);
188
+ catch (error) {
189
+ console.error(error);
167
190
  }
168
- return this.argv.includes('--json') || this.config.scopedEnvVar?.('CONTENT_TYPE')?.toLowerCase() === 'json';
169
191
  }
170
192
  async init() {
171
193
  this.debug('init version: %s argv: %o', this.ctor._base, this.argv);
@@ -178,103 +200,102 @@ class Command {
178
200
  g['http-call'].userAgent = this.config.userAgent;
179
201
  this.warnIfCommandDeprecated();
180
202
  }
181
- warnIfFlagDeprecated(flags) {
182
- for (const flag of Object.keys(flags)) {
183
- const flagDef = this.ctor.flags[flag];
184
- const deprecated = flagDef?.deprecated;
185
- if (deprecated) {
186
- this.warn((0, util_2.formatFlagDeprecationWarning)(flag, deprecated));
187
- }
188
- const deprecateAliases = flagDef?.deprecateAliases;
189
- const aliases = (flagDef?.aliases ?? []).map(a => a.length === 1 ? `-${a}` : `--${a}`);
190
- if (deprecateAliases && aliases.length > 0) {
191
- const foundAliases = aliases.filter(alias => this.argv.some(a => a.startsWith(alias)));
192
- for (const alias of foundAliases) {
193
- let preferredUsage = `--${flagDef?.name}`;
194
- if (flagDef?.char) {
195
- preferredUsage += ` | -${flagDef?.char}`;
196
- }
197
- this.warn((0, util_2.formatFlagDeprecationWarning)(alias, { to: preferredUsage }));
198
- }
199
- }
200
- }
203
+ /**
204
+ * Determine if the command is being run with the --json flag in a command that supports it.
205
+ *
206
+ * @returns {boolean} true if the command supports json and the --json flag is present
207
+ */
208
+ jsonEnabled() {
209
+ // If the command doesn't support json, return false
210
+ if (!this.ctor.enableJsonFlag)
211
+ return false;
212
+ // If the CONTENT_TYPE env var is set to json, return true
213
+ if (this.config.scopedEnvVar?.('CONTENT_TYPE')?.toLowerCase() === 'json')
214
+ return true;
215
+ const passThroughIndex = this.argv.indexOf('--');
216
+ const jsonIndex = this.argv.indexOf('--json');
217
+ return passThroughIndex === -1
218
+ ? // If '--' is not present, then check for `--json` in this.argv
219
+ jsonIndex > -1
220
+ : // If '--' is present, return true only the --json flag exists and is before the '--'
221
+ jsonIndex > -1 && jsonIndex < passThroughIndex;
201
222
  }
202
- warnIfCommandDeprecated() {
203
- const [id] = (0, util_2.normalizeArgv)(this.config);
204
- if (this.ctor.deprecateAliases && this.ctor.aliases.includes(id)) {
205
- const cmdName = (0, util_2.toConfiguredId)(this.ctor.id, this.config);
206
- const aliasName = (0, util_2.toConfiguredId)(id, this.config);
207
- this.warn((0, util_2.formatCommandDeprecationWarning)(aliasName, { to: cmdName }));
223
+ log(message = '', ...args) {
224
+ if (!this.jsonEnabled()) {
225
+ message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
226
+ stream_1.stdout.write((0, node_util_1.format)(message, ...args) + '\n');
208
227
  }
209
- if (this.ctor.state === 'deprecated') {
210
- const cmdName = (0, util_2.toConfiguredId)(this.ctor.id, this.config);
211
- this.warn((0, util_2.formatCommandDeprecationWarning)(cmdName, this.ctor.deprecationOptions));
228
+ }
229
+ logJson(json) {
230
+ cli_ux_1.ux.styledJSON(json);
231
+ }
232
+ logToStderr(message = '', ...args) {
233
+ if (!this.jsonEnabled()) {
234
+ message = typeof message === 'string' ? message : (0, node_util_1.inspect)(message);
235
+ stream_1.stderr.write((0, node_util_1.format)(message, ...args) + '\n');
212
236
  }
213
237
  }
214
238
  async parse(options, argv = this.argv) {
215
239
  if (!options)
216
240
  options = this.ctor;
217
- const opts = { context: this, ...options };
218
- // the spread operator doesn't work with getters so we have to manually add it here
219
- opts.flags = options?.flags;
220
- opts.args = options?.args;
241
+ const opts = {
242
+ context: this,
243
+ ...options,
244
+ flags: (0, aggregate_flags_1.aggregateFlags)(options.flags, options.baseFlags, options.enableJsonFlag),
245
+ };
221
246
  const results = await Parser.parse(argv, opts);
222
247
  this.warnIfFlagDeprecated(results.flags ?? {});
223
248
  return results;
224
249
  }
225
- async catch(err) {
226
- process.exitCode = process.exitCode ?? err.exitCode ?? 1;
227
- if (this.jsonEnabled()) {
228
- this.logJson(this.toErrorJson(err));
229
- }
230
- else {
231
- if (!err.message)
232
- throw err;
233
- try {
234
- ux_1.default.action.stop(chalk.bold.red('!'));
235
- }
236
- catch { }
237
- throw err;
238
- }
239
- }
240
- async finally(_) {
241
- try {
242
- const config = Errors.config;
243
- if (config.errorLogger)
244
- await config.errorLogger.flush();
245
- }
246
- catch (error) {
247
- console.error(error);
248
- }
250
+ toErrorJson(err) {
251
+ return { error: err };
249
252
  }
250
253
  toSuccessJson(result) {
251
254
  return result;
252
255
  }
253
- toErrorJson(err) {
254
- return { error: err };
255
- }
256
- logJson(json) {
257
- ux_1.default.styledJSON(json);
256
+ warn(input) {
257
+ if (!this.jsonEnabled())
258
+ Errors.warn(input);
259
+ return input;
258
260
  }
259
- removeEnvVar(envVar) {
260
- const keys = [];
261
- try {
262
- keys.push(...this.config.scopedEnvVarKeys(envVar));
261
+ warnIfCommandDeprecated() {
262
+ const [id] = (0, util_1.normalizeArgv)(this.config);
263
+ if (this.ctor.deprecateAliases && this.ctor.aliases.includes(id)) {
264
+ const cmdName = (0, util_1.toConfiguredId)(this.ctor.id, this.config);
265
+ const aliasName = (0, util_1.toConfiguredId)(id, this.config);
266
+ this.warn((0, util_1.formatCommandDeprecationWarning)(aliasName, { to: cmdName }));
263
267
  }
264
- catch {
265
- keys.push(this.config.scopedEnvVarKey(envVar));
268
+ if (this.ctor.state === 'deprecated') {
269
+ const cmdName = (0, util_1.toConfiguredId)(this.ctor.id, this.config);
270
+ this.warn((0, util_1.formatCommandDeprecationWarning)(cmdName, this.ctor.deprecationOptions));
271
+ }
272
+ }
273
+ warnIfFlagDeprecated(flags) {
274
+ const allFlags = (0, aggregate_flags_1.aggregateFlags)(this.ctor.flags, this.ctor.baseFlags, this.ctor.enableJsonFlag);
275
+ for (const flag of Object.keys(flags)) {
276
+ const flagDef = allFlags[flag];
277
+ const deprecated = flagDef?.deprecated;
278
+ if (deprecated) {
279
+ this.warn((0, util_1.formatFlagDeprecationWarning)(flag, deprecated));
280
+ }
281
+ const deprecateAliases = flagDef?.deprecateAliases;
282
+ if (deprecateAliases) {
283
+ const aliases = (0, util_2.uniq)([...(flagDef?.aliases ?? []), ...(flagDef?.charAliases ?? [])]).map((a) => a.length === 1 ? `-${a}` : `--${a}`);
284
+ if (aliases.length === 0)
285
+ return;
286
+ const foundAliases = aliases.filter((alias) => this.argv.some((a) => a.startsWith(alias)));
287
+ for (const alias of foundAliases) {
288
+ let preferredUsage = `--${flagDef?.name}`;
289
+ if (flagDef?.char) {
290
+ preferredUsage += ` | -${flagDef?.char}`;
291
+ }
292
+ this.warn((0, util_1.formatFlagDeprecationWarning)(alias, { to: preferredUsage }));
293
+ }
294
+ }
266
295
  }
267
- keys.map(key => delete process.env[key]);
296
+ }
297
+ get ctor() {
298
+ return this.constructor;
268
299
  }
269
300
  }
270
301
  exports.Command = Command;
271
- Command._base = `${pjson.name}@${pjson.version}`;
272
- /** An array of aliases for this command. */
273
- Command.aliases = [];
274
- /** When set to false, allows a variable amount of arguments */
275
- Command.strict = true;
276
- /** An order-dependent object of arguments for the command */
277
- Command.args = {};
278
- Command.hasDynamicHelp = false;
279
- Command['_--'] = false;
280
- Command._enableJsonFlag = false;