@oclif/core 1.16.7 → 1.18.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 +6 -3
- package/lib/command.js +13 -5
- package/lib/config/config.js +5 -0
- package/lib/help/index.js +10 -4
- package/lib/help/util.d.ts +3 -0
- package/lib/help/util.js +29 -3
- package/lib/interfaces/command.d.ts +8 -4
- package/lib/interfaces/parser.d.ts +13 -0
- package/lib/interfaces/pjson.d.ts +1 -1
- package/lib/parser/parse.d.ts +1 -0
- package/lib/parser/parse.js +6 -0
- package/package.json +1 -1
package/lib/command.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Config } from './config';
|
|
2
2
|
import * as Interfaces from './interfaces';
|
|
3
3
|
import { PrettyPrintableError } from './errors';
|
|
4
|
+
import { Deprecation } from './interfaces/parser';
|
|
4
5
|
/**
|
|
5
6
|
* An abstract class which acts as the base for each command
|
|
6
7
|
* in your project.
|
|
@@ -22,10 +23,11 @@ export default abstract class Command {
|
|
|
22
23
|
* If no summary, the first line of the description will be used as the summary.
|
|
23
24
|
*/
|
|
24
25
|
static description: string | undefined;
|
|
25
|
-
/** Hide the command from help
|
|
26
|
+
/** Hide the command from help */
|
|
26
27
|
static hidden: boolean;
|
|
27
|
-
/** Mark the command as a given state (e.g. beta) in help
|
|
28
|
-
static state?: string;
|
|
28
|
+
/** Mark the command as a given state (e.g. beta or deprecated) in help */
|
|
29
|
+
static state?: 'beta' | 'deprecated' | string;
|
|
30
|
+
static deprecationOptions?: Deprecation;
|
|
29
31
|
/**
|
|
30
32
|
* An override string (or strings) for the default usage documentation.
|
|
31
33
|
*/
|
|
@@ -95,6 +97,7 @@ export default abstract class Command {
|
|
|
95
97
|
*/
|
|
96
98
|
abstract run(): PromiseLike<any>;
|
|
97
99
|
protected init(): Promise<any>;
|
|
100
|
+
protected checkForDeprecations(): void;
|
|
98
101
|
protected parse<F extends Interfaces.FlagOutput, G extends Interfaces.FlagOutput, A extends {
|
|
99
102
|
[name: string]: any;
|
|
100
103
|
}>(options?: Interfaces.Input<F, G>, argv?: string[]): Promise<Interfaces.ParserOutput<F, G, A>>;
|
package/lib/command.js
CHANGED
|
@@ -7,6 +7,7 @@ const config_1 = require("./config");
|
|
|
7
7
|
const Errors = require("./errors");
|
|
8
8
|
const Parser = require("./parser");
|
|
9
9
|
const Flags = require("./flags");
|
|
10
|
+
const util_2 = require("./help/util");
|
|
10
11
|
const pjson = require('../package.json');
|
|
11
12
|
/**
|
|
12
13
|
* swallows stdout epipe errors
|
|
@@ -122,13 +123,21 @@ class Command {
|
|
|
122
123
|
Errors.config.debug = true;
|
|
123
124
|
if (this.config.errlog)
|
|
124
125
|
Errors.config.errlog = this.config.errlog;
|
|
125
|
-
// global['cli-ux'].context = global['cli-ux'].context || {
|
|
126
|
-
// command: compact([this.id, ...this.argv]).join(' '),
|
|
127
|
-
// version: this.config.userAgent,
|
|
128
|
-
// }
|
|
129
126
|
const g = global;
|
|
130
127
|
g['http-call'] = g['http-call'] || {};
|
|
131
128
|
g['http-call'].userAgent = this.config.userAgent;
|
|
129
|
+
this.checkForDeprecations();
|
|
130
|
+
}
|
|
131
|
+
checkForDeprecations() {
|
|
132
|
+
if (this.ctor.state === 'deprecated') {
|
|
133
|
+
const cmdName = (0, index_1.toConfiguredId)(this.ctor.id, this.config);
|
|
134
|
+
this.warn((0, util_2.formatCommandDeprecationWarning)(cmdName, this.ctor.deprecationOptions));
|
|
135
|
+
}
|
|
136
|
+
for (const [flag, opts] of Object.entries(this.ctor.flags ?? {})) {
|
|
137
|
+
if (opts.deprecated) {
|
|
138
|
+
this.warn((0, util_2.formatFlagDeprecationWarning)(flag, opts.deprecated));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
132
141
|
}
|
|
133
142
|
async parse(options, argv = this.argv) {
|
|
134
143
|
if (!options)
|
|
@@ -160,7 +169,6 @@ class Command {
|
|
|
160
169
|
const config = Errors.config;
|
|
161
170
|
if (config.errorLogger)
|
|
162
171
|
await config.errorLogger.flush();
|
|
163
|
-
// tslint:disable-next-line no-console
|
|
164
172
|
}
|
|
165
173
|
catch (error) {
|
|
166
174
|
console.error(error);
|
package/lib/config/config.js
CHANGED
|
@@ -643,6 +643,8 @@ async function toCached(c, plugin) {
|
|
|
643
643
|
allowNo: flag.allowNo,
|
|
644
644
|
dependsOn: flag.dependsOn,
|
|
645
645
|
exclusive: flag.exclusive,
|
|
646
|
+
deprecated: flag.deprecated,
|
|
647
|
+
aliases: flag.aliases,
|
|
646
648
|
};
|
|
647
649
|
}
|
|
648
650
|
else {
|
|
@@ -663,6 +665,8 @@ async function toCached(c, plugin) {
|
|
|
663
665
|
relationships: flag.relationships,
|
|
664
666
|
exclusive: flag.exclusive,
|
|
665
667
|
default: await defaultToCached(flag),
|
|
668
|
+
deprecated: flag.deprecated,
|
|
669
|
+
aliases: flag.aliases,
|
|
666
670
|
};
|
|
667
671
|
// a command-level placeholder in the manifest so that oclif knows it should regenerate the command during help-time
|
|
668
672
|
if (typeof flag.defaultHelp === 'function') {
|
|
@@ -692,6 +696,7 @@ async function toCached(c, plugin) {
|
|
|
692
696
|
state: c.state,
|
|
693
697
|
aliases: c.aliases || [],
|
|
694
698
|
examples: c.examples || c.example,
|
|
699
|
+
deprecationOptions: c.deprecationOptions,
|
|
695
700
|
flags,
|
|
696
701
|
args,
|
|
697
702
|
};
|
package/lib/help/index.js
CHANGED
|
@@ -118,8 +118,11 @@ class Help extends HelpBase {
|
|
|
118
118
|
const subCommands = this.sortedCommands.filter(c => c.id.startsWith(name + ':') && c.id.split(':').length === depth + 1);
|
|
119
119
|
const plugin = this.config.plugins.find(p => p.name === command.pluginName);
|
|
120
120
|
const state = this.config.pjson?.oclif?.state || plugin?.pjson?.oclif?.state || command.state;
|
|
121
|
-
if (state)
|
|
122
|
-
this.log(
|
|
121
|
+
if (state) {
|
|
122
|
+
this.log(state === 'deprecated' ?
|
|
123
|
+
`${(0, util_2.formatCommandDeprecationWarning)((0, util_2.toConfiguredId)(name, this.config), command.deprecationOptions)}` :
|
|
124
|
+
`This command is in ${state}.\n`);
|
|
125
|
+
}
|
|
123
126
|
const summary = this.summary(command);
|
|
124
127
|
if (summary) {
|
|
125
128
|
this.log(summary + '\n');
|
|
@@ -144,8 +147,11 @@ class Help extends HelpBase {
|
|
|
144
147
|
let rootTopics = this.sortedTopics;
|
|
145
148
|
let rootCommands = this.sortedCommands;
|
|
146
149
|
const state = this.config.pjson?.oclif?.state;
|
|
147
|
-
if (state)
|
|
148
|
-
this.log(
|
|
150
|
+
if (state) {
|
|
151
|
+
this.log(state === 'deprecated' ?
|
|
152
|
+
`${this.config.bin} is deprecated` :
|
|
153
|
+
`${this.config.bin} is in ${state}.\n`);
|
|
154
|
+
}
|
|
149
155
|
this.log(this.formatRoot());
|
|
150
156
|
this.log('');
|
|
151
157
|
if (!this.opts.all) {
|
package/lib/help/util.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Config as IConfig, HelpOptions } from '../interfaces';
|
|
2
2
|
import { HelpBase } from '.';
|
|
3
|
+
import { Deprecation } from '../interfaces/parser';
|
|
3
4
|
interface HelpBaseDerived {
|
|
4
5
|
new (config: IConfig, opts?: Partial<HelpOptions>): HelpBase;
|
|
5
6
|
}
|
|
@@ -9,4 +10,6 @@ export declare function toStandardizedId(commandID: string, config: IConfig): st
|
|
|
9
10
|
export declare function toConfiguredId(commandID: string, config: IConfig): string;
|
|
10
11
|
export declare function standardizeIDFromArgv(argv: string[], config: IConfig): string[];
|
|
11
12
|
export declare function getHelpFlagAdditions(config: IConfig): string[];
|
|
13
|
+
export declare function formatFlagDeprecationWarning(flag: string, opts: true | Deprecation): string;
|
|
14
|
+
export declare function formatCommandDeprecationWarning(command: string, opts?: Deprecation): string;
|
|
12
15
|
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.getHelpFlagAdditions = exports.standardizeIDFromArgv = exports.toConfiguredId = exports.toStandardizedId = exports.template = exports.loadHelpClass = void 0;
|
|
3
|
+
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");
|
|
@@ -71,8 +71,8 @@ function toStandardizedId(commandID, config) {
|
|
|
71
71
|
}
|
|
72
72
|
exports.toStandardizedId = toStandardizedId;
|
|
73
73
|
function toConfiguredId(commandID, config) {
|
|
74
|
-
const
|
|
75
|
-
return commandID.replace(new RegExp(
|
|
74
|
+
const defaultTopicSeparator = ':';
|
|
75
|
+
return commandID.replace(new RegExp(defaultTopicSeparator, 'g'), config.topicSeparator || defaultTopicSeparator);
|
|
76
76
|
}
|
|
77
77
|
exports.toConfiguredId = toConfiguredId;
|
|
78
78
|
function standardizeIDFromArgv(argv, config) {
|
|
@@ -91,3 +91,29 @@ function getHelpFlagAdditions(config) {
|
|
|
91
91
|
return [...new Set([...helpFlags, ...additionalHelpFlags]).values()];
|
|
92
92
|
}
|
|
93
93
|
exports.getHelpFlagAdditions = getHelpFlagAdditions;
|
|
94
|
+
function formatFlagDeprecationWarning(flag, opts) {
|
|
95
|
+
let message = `The "${flag}" flag has been deprecated`;
|
|
96
|
+
if (opts === true)
|
|
97
|
+
return `${message}.`;
|
|
98
|
+
if (opts.message)
|
|
99
|
+
return opts.message;
|
|
100
|
+
if (opts.version) {
|
|
101
|
+
message += ` and will be removed in version ${opts.version}`;
|
|
102
|
+
}
|
|
103
|
+
message += opts.to ? `. Use "${opts.to}" instead.` : '.';
|
|
104
|
+
return message;
|
|
105
|
+
}
|
|
106
|
+
exports.formatFlagDeprecationWarning = formatFlagDeprecationWarning;
|
|
107
|
+
function formatCommandDeprecationWarning(command, opts) {
|
|
108
|
+
let message = `The "${command}" command has been deprecated`;
|
|
109
|
+
if (!opts)
|
|
110
|
+
return `${message}.`;
|
|
111
|
+
if (opts.message)
|
|
112
|
+
return opts.message;
|
|
113
|
+
if (opts.version) {
|
|
114
|
+
message += ` and will be removed in version ${opts.version}`;
|
|
115
|
+
}
|
|
116
|
+
message += opts.to ? `. Use "${opts.to}" instead.` : '.';
|
|
117
|
+
return message;
|
|
118
|
+
}
|
|
119
|
+
exports.formatCommandDeprecationWarning = formatCommandDeprecationWarning;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Config, LoadOptions } from './config';
|
|
2
|
-
import { ArgInput, BooleanFlagProps, FlagInput, OptionFlagProps } from './parser';
|
|
2
|
+
import { ArgInput, BooleanFlagProps, Deprecation, FlagInput, OptionFlagProps } from './parser';
|
|
3
3
|
import { Plugin as IPlugin } from './plugin';
|
|
4
4
|
export declare type Example = string | {
|
|
5
5
|
description: string;
|
|
@@ -8,10 +8,14 @@ export declare type Example = string | {
|
|
|
8
8
|
export interface CommandProps {
|
|
9
9
|
/** A command ID, used mostly in error or verbose reporting. */
|
|
10
10
|
id: string;
|
|
11
|
-
/** Hide the command from help
|
|
11
|
+
/** Hide the command from help */
|
|
12
12
|
hidden: boolean;
|
|
13
|
-
/** Mark the command as a given state (e.g. beta) in help
|
|
14
|
-
state?: string;
|
|
13
|
+
/** Mark the command as a given state (e.g. beta or deprecated) in help */
|
|
14
|
+
state?: 'beta' | 'deprecated' | string;
|
|
15
|
+
/**
|
|
16
|
+
* Provide details to the deprecation warning if state === 'deprecated'
|
|
17
|
+
*/
|
|
18
|
+
deprecationOptions?: Deprecation;
|
|
15
19
|
/** An array of aliases for this command. */
|
|
16
20
|
aliases: string[];
|
|
17
21
|
/**
|
|
@@ -92,6 +92,11 @@ export declare type Relationship = {
|
|
|
92
92
|
type: 'all' | 'some' | 'none';
|
|
93
93
|
flags: FlagRelationship[];
|
|
94
94
|
};
|
|
95
|
+
export declare type Deprecation = {
|
|
96
|
+
to?: string;
|
|
97
|
+
message?: string;
|
|
98
|
+
version?: string;
|
|
99
|
+
};
|
|
95
100
|
export declare type FlagProps = {
|
|
96
101
|
name: string;
|
|
97
102
|
char?: AlphabetLowercase | AlphabetUppercase;
|
|
@@ -143,6 +148,14 @@ export declare type FlagProps = {
|
|
|
143
148
|
* Define complex relationships between flags.
|
|
144
149
|
*/
|
|
145
150
|
relationships?: Relationship[];
|
|
151
|
+
/**
|
|
152
|
+
* Make the flag as deprecated.
|
|
153
|
+
*/
|
|
154
|
+
deprecated?: true | Deprecation;
|
|
155
|
+
/**
|
|
156
|
+
* Alternate names that can be used for this flag.
|
|
157
|
+
*/
|
|
158
|
+
aliases?: string[];
|
|
146
159
|
};
|
|
147
160
|
export declare type BooleanFlagProps = FlagProps & {
|
|
148
161
|
type: 'boolean';
|
package/lib/parser/parse.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare class Parser<T extends ParserInput, TFlags extends OutputFlags<T[
|
|
|
4
4
|
private readonly argv;
|
|
5
5
|
private readonly raw;
|
|
6
6
|
private readonly booleanFlags;
|
|
7
|
+
private readonly flagAliases;
|
|
7
8
|
private readonly context;
|
|
8
9
|
private readonly metaData;
|
|
9
10
|
private currentFlag?;
|
package/lib/parser/parse.js
CHANGED
|
@@ -38,6 +38,9 @@ class Parser {
|
|
|
38
38
|
this.argv = [...input.argv];
|
|
39
39
|
this._setNames();
|
|
40
40
|
this.booleanFlags = pickBy(input.flags, f => f.type === 'boolean');
|
|
41
|
+
this.flagAliases = Object.fromEntries(Object.values(input.flags).flatMap(flag => {
|
|
42
|
+
return (flag.aliases ?? []).map(a => [a, flag]);
|
|
43
|
+
}));
|
|
41
44
|
this.metaData = {};
|
|
42
45
|
}
|
|
43
46
|
async parse() {
|
|
@@ -47,6 +50,9 @@ class Parser {
|
|
|
47
50
|
if (this.input.flags[name]) {
|
|
48
51
|
return name;
|
|
49
52
|
}
|
|
53
|
+
if (this.flagAliases[name]) {
|
|
54
|
+
return this.flagAliases[name].name;
|
|
55
|
+
}
|
|
50
56
|
if (arg.startsWith('--no-')) {
|
|
51
57
|
const flag = this.booleanFlags[arg.slice(5)];
|
|
52
58
|
if (flag && flag.allowNo)
|