@oclif/core 1.19.2 → 1.20.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/cli-ux/action/base.d.ts +1 -1
- package/lib/cli-ux/prompt.d.ts +4 -4
- package/lib/cli-ux/prompt.js +2 -2
- package/lib/command.d.ts +4 -0
- package/lib/command.js +14 -0
- package/lib/config/config.js +3 -0
- package/lib/flags.js +1 -1
- package/lib/help/index.d.ts +1 -1
- package/lib/help/index.js +2 -1
- package/lib/help/util.d.ts +1 -0
- package/lib/help/util.js +8 -2
- package/lib/interfaces/command.d.ts +4 -0
- package/lib/interfaces/parser.d.ts +4 -0
- package/lib/main.js +1 -3
- package/lib/parser/parse.js +6 -3
- package/package.json +2 -2
|
@@ -22,7 +22,7 @@ export declare class ActionBase {
|
|
|
22
22
|
get running(): boolean;
|
|
23
23
|
get status(): string | undefined;
|
|
24
24
|
set status(status: string | undefined);
|
|
25
|
-
pauseAsync(fn: () => Promise<
|
|
25
|
+
pauseAsync<T extends any>(fn: () => Promise<T>, icon?: string): Promise<T>;
|
|
26
26
|
pause(fn: () => any, icon?: string): any;
|
|
27
27
|
protected _start(): void;
|
|
28
28
|
protected _stop(_: string): void;
|
package/lib/cli-ux/prompt.d.ts
CHANGED
|
@@ -12,9 +12,9 @@ export interface IPromptOptions {
|
|
|
12
12
|
* prompt for input
|
|
13
13
|
* @param name - prompt text
|
|
14
14
|
* @param options - @see IPromptOptions
|
|
15
|
-
* @returns
|
|
15
|
+
* @returns Promise<string>
|
|
16
16
|
*/
|
|
17
|
-
export declare function prompt(name: string, options?: IPromptOptions): Promise<
|
|
17
|
+
export declare function prompt(name: string, options?: IPromptOptions): Promise<string>;
|
|
18
18
|
/**
|
|
19
19
|
* confirmation prompt (yes/no)
|
|
20
20
|
* @param message - confirmation text
|
|
@@ -24,6 +24,6 @@ export declare function confirm(message: string): Promise<boolean>;
|
|
|
24
24
|
/**
|
|
25
25
|
* "press anykey to continue"
|
|
26
26
|
* @param message - optional message to display to user
|
|
27
|
-
* @returns Promise<
|
|
27
|
+
* @returns Promise<string>
|
|
28
28
|
*/
|
|
29
|
-
export declare function anykey(message?: string): Promise<
|
|
29
|
+
export declare function anykey(message?: string): Promise<string>;
|
package/lib/cli-ux/prompt.js
CHANGED
|
@@ -98,7 +98,7 @@ function _prompt(name, inputOptions = {}) {
|
|
|
98
98
|
* prompt for input
|
|
99
99
|
* @param name - prompt text
|
|
100
100
|
* @param options - @see IPromptOptions
|
|
101
|
-
* @returns
|
|
101
|
+
* @returns Promise<string>
|
|
102
102
|
*/
|
|
103
103
|
function prompt(name, options = {}) {
|
|
104
104
|
return config_1.default.action.pauseAsync(() => {
|
|
@@ -128,7 +128,7 @@ exports.confirm = confirm;
|
|
|
128
128
|
/**
|
|
129
129
|
* "press anykey to continue"
|
|
130
130
|
* @param message - optional message to display to user
|
|
131
|
-
* @returns Promise<
|
|
131
|
+
* @returns Promise<string>
|
|
132
132
|
*/
|
|
133
133
|
async function anykey(message) {
|
|
134
134
|
const tty = Boolean(process.stdin.setRawMode);
|
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));
|
package/lib/config/config.js
CHANGED
|
@@ -645,6 +645,7 @@ async function toCached(c, plugin) {
|
|
|
645
645
|
relationships: flag.relationships,
|
|
646
646
|
exclusive: flag.exclusive,
|
|
647
647
|
deprecated: flag.deprecated,
|
|
648
|
+
deprecateAliases: c.deprecateAliases,
|
|
648
649
|
aliases: flag.aliases,
|
|
649
650
|
};
|
|
650
651
|
}
|
|
@@ -667,6 +668,7 @@ async function toCached(c, plugin) {
|
|
|
667
668
|
exclusive: flag.exclusive,
|
|
668
669
|
default: await defaultToCached(flag),
|
|
669
670
|
deprecated: flag.deprecated,
|
|
671
|
+
deprecateAliases: c.deprecateAliases,
|
|
670
672
|
aliases: flag.aliases,
|
|
671
673
|
};
|
|
672
674
|
// a command-level placeholder in the manifest so that oclif knows it should regenerate the command during help-time
|
|
@@ -698,6 +700,7 @@ async function toCached(c, plugin) {
|
|
|
698
700
|
aliases: c.aliases || [],
|
|
699
701
|
examples: c.examples || c.example,
|
|
700
702
|
deprecationOptions: c.deprecationOptions,
|
|
703
|
+
deprecateAliases: c.deprecateAliases,
|
|
701
704
|
flags,
|
|
702
705
|
args,
|
|
703
706
|
};
|
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
|
});
|
package/lib/help/index.d.ts
CHANGED
|
@@ -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);
|
package/lib/help/util.d.ts
CHANGED
|
@@ -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 "
|
|
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
|
-
|
|
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
|
package/lib/parser/parse.js
CHANGED
|
@@ -59,8 +59,11 @@ class Parser {
|
|
|
59
59
|
return flag.name;
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
const findShortFlag = (
|
|
63
|
-
|
|
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('--');
|
|
@@ -175,7 +178,7 @@ class Parser {
|
|
|
175
178
|
const flag = this.input.flags[k];
|
|
176
179
|
if (flags[k])
|
|
177
180
|
continue;
|
|
178
|
-
if (flag.env) {
|
|
181
|
+
if (flag.env && Object.prototype.hasOwnProperty.call(process.env, flag.env)) {
|
|
179
182
|
const input = process.env[flag.env];
|
|
180
183
|
if (flag.type === 'option') {
|
|
181
184
|
if (input) {
|
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.
|
|
4
|
+
"version": "1.20.1",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/core/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@commitlint/config-conventional": "^12.1.4",
|
|
39
39
|
"@oclif/plugin-help": "^5.1.11",
|
|
40
40
|
"@oclif/plugin-plugins": "^2.1.0",
|
|
41
|
-
"@oclif/test": "^2.
|
|
41
|
+
"@oclif/test": "^2.2.8",
|
|
42
42
|
"@types/ansi-styles": "^3.2.1",
|
|
43
43
|
"@types/chai": "^4.3.0",
|
|
44
44
|
"@types/chai-as-promised": "^7.1.5",
|