@oclif/core 1.17.0 → 1.19.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 +7 -3
- package/lib/command.js +19 -6
- package/lib/config/config.js +3 -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 +9 -0
- package/lib/interfaces/pjson.d.ts +1 -1
- 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,8 @@ export default abstract class Command {
|
|
|
95
97
|
*/
|
|
96
98
|
abstract run(): PromiseLike<any>;
|
|
97
99
|
protected init(): Promise<any>;
|
|
100
|
+
protected warnIfFlagDeprecated(flags: Record<string, unknown>): void;
|
|
101
|
+
protected warnIfCommandDeprecated(): void;
|
|
98
102
|
protected parse<F extends Interfaces.FlagOutput, G extends Interfaces.FlagOutput, A extends {
|
|
99
103
|
[name: string]: any;
|
|
100
104
|
}>(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,24 @@ 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.warnIfCommandDeprecated();
|
|
130
|
+
}
|
|
131
|
+
warnIfFlagDeprecated(flags) {
|
|
132
|
+
for (const flag of Object.keys(flags)) {
|
|
133
|
+
const deprecated = this.ctor.flags[flag]?.deprecated;
|
|
134
|
+
if (deprecated) {
|
|
135
|
+
this.warn((0, util_2.formatFlagDeprecationWarning)(flag, deprecated));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
warnIfCommandDeprecated() {
|
|
140
|
+
if (this.ctor.state === 'deprecated') {
|
|
141
|
+
const cmdName = (0, index_1.toConfiguredId)(this.ctor.id, this.config);
|
|
142
|
+
this.warn((0, util_2.formatCommandDeprecationWarning)(cmdName, this.ctor.deprecationOptions));
|
|
143
|
+
}
|
|
132
144
|
}
|
|
133
145
|
async parse(options, argv = this.argv) {
|
|
134
146
|
if (!options)
|
|
@@ -137,7 +149,9 @@ class Command {
|
|
|
137
149
|
// the spread operator doesn't work with getters so we have to manually add it here
|
|
138
150
|
opts.flags = options?.flags;
|
|
139
151
|
opts.args = options?.args;
|
|
140
|
-
|
|
152
|
+
const results = await Parser.parse(argv, opts);
|
|
153
|
+
this.warnIfFlagDeprecated(results.flags ?? {});
|
|
154
|
+
return results;
|
|
141
155
|
}
|
|
142
156
|
async catch(err) {
|
|
143
157
|
process.exitCode = process.exitCode ?? err.exitCode ?? 1;
|
|
@@ -160,7 +174,6 @@ class Command {
|
|
|
160
174
|
const config = Errors.config;
|
|
161
175
|
if (config.errorLogger)
|
|
162
176
|
await config.errorLogger.flush();
|
|
163
|
-
// tslint:disable-next-line no-console
|
|
164
177
|
}
|
|
165
178
|
catch (error) {
|
|
166
179
|
console.error(error);
|
package/lib/config/config.js
CHANGED
|
@@ -643,6 +643,7 @@ async function toCached(c, plugin) {
|
|
|
643
643
|
allowNo: flag.allowNo,
|
|
644
644
|
dependsOn: flag.dependsOn,
|
|
645
645
|
exclusive: flag.exclusive,
|
|
646
|
+
deprecated: flag.deprecated,
|
|
646
647
|
aliases: flag.aliases,
|
|
647
648
|
};
|
|
648
649
|
}
|
|
@@ -664,6 +665,7 @@ async function toCached(c, plugin) {
|
|
|
664
665
|
relationships: flag.relationships,
|
|
665
666
|
exclusive: flag.exclusive,
|
|
666
667
|
default: await defaultToCached(flag),
|
|
668
|
+
deprecated: flag.deprecated,
|
|
667
669
|
aliases: flag.aliases,
|
|
668
670
|
};
|
|
669
671
|
// a command-level placeholder in the manifest so that oclif knows it should regenerate the command during help-time
|
|
@@ -694,6 +696,7 @@ async function toCached(c, plugin) {
|
|
|
694
696
|
state: c.state,
|
|
695
697
|
aliases: c.aliases || [],
|
|
696
698
|
examples: c.examples || c.example,
|
|
699
|
+
deprecationOptions: c.deprecationOptions,
|
|
697
700
|
flags,
|
|
698
701
|
args,
|
|
699
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,10 @@ 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;
|
|
146
155
|
/**
|
|
147
156
|
* Alternate names that can be used for this flag.
|
|
148
157
|
*/
|