@oclif/core 1.19.1 → 1.20.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.
package/lib/command.d.ts CHANGED
@@ -28,6 +28,10 @@ export default abstract class Command {
28
28
  /** Mark the command as a given state (e.g. beta or deprecated) in help */
29
29
  static state?: 'beta' | 'deprecated' | string;
30
30
  static deprecationOptions?: Deprecation;
31
+ /**
32
+ * Emit deprecation warning when a command alias is used
33
+ */
34
+ static deprecateAliases?: boolean;
31
35
  /**
32
36
  * An override string (or strings) for the default usage documentation.
33
37
  */
package/lib/command.js CHANGED
@@ -134,9 +134,23 @@ class Command {
134
134
  if (deprecated) {
135
135
  this.warn((0, util_2.formatFlagDeprecationWarning)(flag, deprecated));
136
136
  }
137
+ const deprecateAliases = this.ctor.flags[flag]?.deprecateAliases;
138
+ const aliases = (this.ctor.flags[flag]?.aliases ?? []).map(a => a.length === 1 ? `-${a}` : `--${a}`);
139
+ if (deprecateAliases && aliases.length > 0) {
140
+ const foundAliases = this.argv.filter(a => aliases.includes(a));
141
+ for (const alias of foundAliases) {
142
+ this.warn((0, util_2.formatFlagDeprecationWarning)(alias, { to: this.ctor.flags[flag]?.name }));
143
+ }
144
+ }
137
145
  }
138
146
  }
139
147
  warnIfCommandDeprecated() {
148
+ const [id] = (0, util_2.normalizeArgv)(this.config);
149
+ if (this.ctor.deprecateAliases && this.ctor.aliases.includes(id)) {
150
+ const cmdName = (0, index_1.toConfiguredId)(this.ctor.id, this.config);
151
+ const aliasName = (0, index_1.toConfiguredId)(id, this.config);
152
+ this.warn((0, util_2.formatCommandDeprecationWarning)(aliasName, { to: cmdName }));
153
+ }
140
154
  if (this.ctor.state === 'deprecated') {
141
155
  const cmdName = (0, index_1.toConfiguredId)(this.ctor.id, this.config);
142
156
  this.warn((0, util_2.formatCommandDeprecationWarning)(cmdName, this.ctor.deprecationOptions));
@@ -642,8 +642,10 @@ async function toCached(c, plugin) {
642
642
  helpGroup: flag.helpGroup,
643
643
  allowNo: flag.allowNo,
644
644
  dependsOn: flag.dependsOn,
645
+ relationships: flag.relationships,
645
646
  exclusive: flag.exclusive,
646
647
  deprecated: flag.deprecated,
648
+ deprecateAliases: c.deprecateAliases,
647
649
  aliases: flag.aliases,
648
650
  };
649
651
  }
@@ -666,6 +668,7 @@ async function toCached(c, plugin) {
666
668
  exclusive: flag.exclusive,
667
669
  default: await defaultToCached(flag),
668
670
  deprecated: flag.deprecated,
671
+ deprecateAliases: c.deprecateAliases,
669
672
  aliases: flag.aliases,
670
673
  };
671
674
  // a command-level placeholder in the manifest so that oclif knows it should regenerate the command during help-time
@@ -697,11 +700,12 @@ async function toCached(c, plugin) {
697
700
  aliases: c.aliases || [],
698
701
  examples: c.examples || c.example,
699
702
  deprecationOptions: c.deprecationOptions,
703
+ deprecateAliases: c.deprecateAliases,
700
704
  flags,
701
705
  args,
702
706
  };
703
707
  // do not include these properties in manifest
704
- const ignoreCommandProperties = ['plugin', '_flags'];
708
+ const ignoreCommandProperties = ['plugin', '_flags', '_enableJsonFlag', '_globalFlags'];
705
709
  const stdKeys = Object.keys(stdProperties);
706
710
  const keysToAdd = Object.keys(c).filter(property => ![...stdKeys, ...ignoreCommandProperties].includes(property));
707
711
  const additionalProperties = {};
package/lib/flags.js CHANGED
@@ -42,7 +42,7 @@ const help = (opts = {}) => {
42
42
  description: 'Show CLI help.',
43
43
  ...opts,
44
44
  parse: async (_, cmd) => {
45
- new help_1.Help(cmd.config).showHelp(cmd.argv);
45
+ new help_1.Help(cmd.config).showHelp(cmd.id ? [cmd.id, ...cmd.argv] : cmd.argv);
46
46
  cmd.exit(0);
47
47
  },
48
48
  });
@@ -2,7 +2,7 @@ import * as Interfaces from '../interfaces';
2
2
  import CommandHelp from './command';
3
3
  import { HelpFormatter } from './formatter';
4
4
  export { CommandHelp } from './command';
5
- export { standardizeIDFromArgv, loadHelpClass, getHelpFlagAdditions } from './util';
5
+ export { standardizeIDFromArgv, loadHelpClass, getHelpFlagAdditions, normalizeArgv } from './util';
6
6
  export declare abstract class HelpBase extends HelpFormatter {
7
7
  constructor(config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>);
8
8
  /**
package/lib/help/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Help = exports.HelpBase = exports.getHelpFlagAdditions = exports.loadHelpClass = exports.standardizeIDFromArgv = exports.CommandHelp = void 0;
3
+ exports.Help = exports.HelpBase = exports.normalizeArgv = exports.getHelpFlagAdditions = exports.loadHelpClass = exports.standardizeIDFromArgv = exports.CommandHelp = void 0;
4
4
  const stripAnsi = require("strip-ansi");
5
5
  const errors_1 = require("../errors");
6
6
  const command_1 = require("./command");
@@ -15,6 +15,7 @@ var util_3 = require("./util");
15
15
  Object.defineProperty(exports, "standardizeIDFromArgv", { enumerable: true, get: function () { return util_3.standardizeIDFromArgv; } });
16
16
  Object.defineProperty(exports, "loadHelpClass", { enumerable: true, get: function () { return util_3.loadHelpClass; } });
17
17
  Object.defineProperty(exports, "getHelpFlagAdditions", { enumerable: true, get: function () { return util_3.getHelpFlagAdditions; } });
18
+ Object.defineProperty(exports, "normalizeArgv", { enumerable: true, get: function () { return util_3.normalizeArgv; } });
18
19
  function getHelpSubject(args, config) {
19
20
  // for each help flag that starts with '--' create a new flag with same name sans '--'
20
21
  const mergedHelpFlags = (0, util_2.getHelpFlagAdditions)(config);
@@ -12,4 +12,5 @@ export declare function standardizeIDFromArgv(argv: string[], config: IConfig):
12
12
  export declare function getHelpFlagAdditions(config: IConfig): string[];
13
13
  export declare function formatFlagDeprecationWarning(flag: string, opts: true | Deprecation): string;
14
14
  export declare function formatCommandDeprecationWarning(command: string, opts?: Deprecation): string;
15
+ export declare function normalizeArgv(config: IConfig, argv?: string[]): string[];
15
16
  export {};
package/lib/help/util.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatCommandDeprecationWarning = exports.formatFlagDeprecationWarning = exports.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.toConfiguredId = exports.toStandardizedId = exports.template = exports.loadHelpClass = void 0;
3
+ exports.normalizeArgv = exports.formatCommandDeprecationWarning = exports.formatFlagDeprecationWarning = exports.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.toConfiguredId = exports.toStandardizedId = exports.template = exports.loadHelpClass = void 0;
4
4
  const ejs = require("ejs");
5
5
  const _1 = require(".");
6
6
  const module_loader_1 = require("../module-loader");
@@ -100,7 +100,7 @@ function formatFlagDeprecationWarning(flag, opts) {
100
100
  if (opts.version) {
101
101
  message += ` and will be removed in version ${opts.version}`;
102
102
  }
103
- message += opts.to ? `. Use "${opts.to}" instead.` : '.';
103
+ message += opts.to ? `. Use "--${opts.to}" instead.` : '.';
104
104
  return message;
105
105
  }
106
106
  exports.formatFlagDeprecationWarning = formatFlagDeprecationWarning;
@@ -117,3 +117,9 @@ function formatCommandDeprecationWarning(command, opts) {
117
117
  return message;
118
118
  }
119
119
  exports.formatCommandDeprecationWarning = formatCommandDeprecationWarning;
120
+ function normalizeArgv(config, argv = process.argv.slice(2)) {
121
+ if (config.topicSeparator !== ':' && !argv[0]?.includes(':'))
122
+ argv = standardizeIDFromArgv(argv, config);
123
+ return argv;
124
+ }
125
+ exports.normalizeArgv = normalizeArgv;
@@ -16,6 +16,10 @@ export interface CommandProps {
16
16
  * Provide details to the deprecation warning if state === 'deprecated'
17
17
  */
18
18
  deprecationOptions?: Deprecation;
19
+ /**
20
+ * Emit a deprecation warning when a command alias is used.
21
+ */
22
+ deprecateAliases?: boolean;
19
23
  /** An array of aliases for this command. */
20
24
  aliases: string[];
21
25
  /**
@@ -156,6 +156,10 @@ export declare type FlagProps = {
156
156
  * Alternate names that can be used for this flag.
157
157
  */
158
158
  aliases?: string[];
159
+ /**
160
+ * Emit deprecation warning when a flag alias is provided
161
+ */
162
+ deprecateAliases?: boolean;
159
163
  };
160
164
  export declare type BooleanFlagProps = FlagProps & {
161
165
  type: 'boolean';
package/lib/main.js CHANGED
@@ -40,9 +40,7 @@ async function run(argv = process.argv.slice(2), options) {
40
40
  }
41
41
  // return Main.run(argv, options)
42
42
  const config = await config_1.Config.load(options || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname);
43
- if (config.topicSeparator !== ':' && !argv[0]?.includes(':'))
44
- argv = (0, help_1.standardizeIDFromArgv)(argv, config);
45
- let [id, ...argvSlice] = argv;
43
+ let [id, ...argvSlice] = (0, help_1.normalizeArgv)(config, argv);
46
44
  // run init hook
47
45
  await config.runHook('init', { id, argv: argvSlice });
48
46
  // display version if applicable
@@ -59,8 +59,11 @@ class Parser {
59
59
  return flag.name;
60
60
  }
61
61
  };
62
- const findShortFlag = (arg) => {
63
- return Object.keys(this.input.flags).find(k => this.input.flags[k].char === arg[1]);
62
+ const findShortFlag = ([_, char]) => {
63
+ if (this.flagAliases[char]) {
64
+ return this.flagAliases[char].name;
65
+ }
66
+ return Object.keys(this.input.flags).find(k => this.input.flags[k].char === char);
64
67
  };
65
68
  const parseFlag = (arg) => {
66
69
  const long = arg.startsWith('--');
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.19.1",
4
+ "version": "1.20.0",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {