@oclif/core 2.0.0-beta.3 → 2.0.0-beta.4
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/README.md +5 -5
- package/lib/args.d.ts +39 -0
- package/lib/args.js +62 -0
- package/lib/cli-ux/action/base.d.ts +1 -1
- package/lib/cli-ux/action/pride-spinner.js +0 -1
- package/lib/cli-ux/action/spinner.js +10 -11
- package/lib/cli-ux/action/spinners.d.ts +251 -0
- package/lib/cli-ux/action/spinners.js +2 -1
- package/lib/cli-ux/config.d.ts +1 -1
- package/lib/cli-ux/config.js +7 -5
- package/lib/cli-ux/index.d.ts +27 -32
- package/lib/cli-ux/index.js +67 -24
- package/lib/cli-ux/list.js +3 -4
- package/lib/cli-ux/prompt.js +9 -8
- package/lib/cli-ux/styled/header.js +1 -1
- package/lib/cli-ux/styled/index.d.ts +7 -0
- package/lib/cli-ux/styled/index.js +15 -0
- package/lib/cli-ux/styled/json.d.ts +1 -1
- package/lib/cli-ux/styled/json.js +2 -3
- package/lib/cli-ux/styled/object.js +1 -1
- package/lib/cli-ux/styled/progress.d.ts +2 -1
- package/lib/cli-ux/styled/progress.js +1 -5
- package/lib/cli-ux/styled/table.js +1 -3
- package/lib/cli-ux/styled/tree.js +0 -1
- package/lib/cli-ux/wait.d.ts +1 -1
- package/lib/cli-ux/wait.js +0 -1
- package/lib/command.d.ts +77 -26
- package/lib/command.js +46 -43
- package/lib/config/config.d.ts +18 -17
- package/lib/config/config.js +46 -22
- package/lib/config/index.js +0 -5
- package/lib/config/plugin.d.ts +3 -2
- package/lib/config/plugin.js +4 -13
- package/lib/config/util.js +2 -2
- package/lib/errors/index.js +0 -1
- package/lib/errors/logger.js +2 -4
- package/lib/flags.d.ts +46 -18
- package/lib/flags.js +71 -29
- package/lib/help/command.d.ts +12 -12
- package/lib/help/command.js +6 -6
- package/lib/help/docopts.d.ts +3 -3
- package/lib/help/docopts.js +2 -3
- package/lib/help/formatter.d.ts +4 -3
- package/lib/help/index.d.ts +10 -14
- package/lib/help/index.js +0 -5
- package/lib/help/util.d.ts +3 -3
- package/lib/help/util.js +1 -1
- package/lib/index.d.ts +5 -4
- package/lib/index.js +10 -8
- package/lib/interfaces/args.d.ts +22 -0
- package/lib/interfaces/{command.js → args.js} +0 -0
- package/lib/interfaces/config.d.ts +1 -2
- package/lib/interfaces/flags.d.ts +2 -2
- package/lib/interfaces/hooks.d.ts +1 -1
- package/lib/interfaces/index.d.ts +2 -2
- package/lib/interfaces/manifest.d.ts +2 -2
- package/lib/interfaces/parser.d.ts +96 -81
- package/lib/interfaces/plugin.d.ts +1 -1
- package/lib/main.d.ts +54 -1
- package/lib/main.js +70 -6
- package/lib/parser/errors.d.ts +15 -8
- package/lib/parser/errors.js +17 -14
- package/lib/parser/help.d.ts +1 -1
- package/lib/parser/help.js +4 -9
- package/lib/parser/index.d.ts +2 -9
- package/lib/parser/index.js +5 -26
- package/lib/parser/parse.d.ts +4 -11
- package/lib/parser/parse.js +108 -72
- package/lib/parser/validate.d.ts +1 -1
- package/lib/parser/validate.js +6 -3
- package/lib/util.d.ts +8 -0
- package/lib/util.js +44 -1
- package/package.json +4 -4
- package/lib/cli-ux/deps.d.ts +0 -22
- package/lib/cli-ux/deps.js +0 -47
- package/lib/cli-ux/open.d.ts +0 -6
- package/lib/cli-ux/open.js +0 -69
- package/lib/help/_test-help-class.d.ts +0 -6
- package/lib/help/_test-help-class.js +0 -19
- package/lib/interfaces/command.d.ts +0 -110
- package/lib/parser/args.d.ts +0 -5
- package/lib/parser/args.js +0 -11
- package/lib/parser/deps.d.ts +0 -4
- package/lib/parser/deps.js +0 -17
- package/lib/parser/flags.d.ts +0 -60
- package/lib/parser/flags.js +0 -107
- package/lib/parser/list.d.ts +0 -2
- package/lib/parser/list.js +0 -29
- package/lib/parser/util.d.ts +0 -7
- package/lib/parser/util.js +0 -50
package/lib/flags.js
CHANGED
|
@@ -1,44 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.help = exports.version = exports.
|
|
4
|
-
const
|
|
3
|
+
exports.help = exports.version = exports.string = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.custom = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
5
5
|
const help_1 = require("./help");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
const util_1 = require("./util");
|
|
7
|
+
function custom(defaults) {
|
|
8
|
+
return (options = {}) => {
|
|
9
|
+
return {
|
|
10
|
+
parse: async (input, _ctx, _opts) => input,
|
|
11
|
+
...defaults,
|
|
12
|
+
...options,
|
|
13
|
+
input: [],
|
|
14
|
+
multiple: Boolean(options.multiple === undefined ? defaults.multiple : options.multiple),
|
|
15
|
+
type: 'option',
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.custom = custom;
|
|
20
|
+
function boolean(options = {}) {
|
|
21
|
+
return {
|
|
22
|
+
parse: async (b, _) => b,
|
|
23
|
+
...options,
|
|
24
|
+
allowNo: Boolean(options.allowNo),
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
};
|
|
26
27
|
}
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
28
|
+
exports.boolean = boolean;
|
|
29
|
+
exports.integer = custom({
|
|
30
|
+
parse: async (input, _, opts) => {
|
|
31
|
+
if (!/^-?\d+$/.test(input))
|
|
32
|
+
throw new Error(`Expected an integer but received: ${input}`);
|
|
33
|
+
const num = Number.parseInt(input, 10);
|
|
34
|
+
if (opts.min !== undefined && num < opts.min)
|
|
35
|
+
throw new Error(`Expected an integer greater than or equal to ${opts.min} but received: ${input}`);
|
|
36
|
+
if (opts.max !== undefined && num > opts.max)
|
|
37
|
+
throw new Error(`Expected an integer less than or equal to ${opts.max} but received: ${input}`);
|
|
38
|
+
return num;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
exports.directory = custom({
|
|
42
|
+
parse: async (input, _, opts) => {
|
|
43
|
+
if (opts.exists)
|
|
44
|
+
return (0, util_1.dirExists)(input);
|
|
45
|
+
return input;
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
exports.file = custom({
|
|
49
|
+
parse: async (input, _, opts) => {
|
|
50
|
+
if (opts.exists)
|
|
51
|
+
return (0, util_1.fileExists)(input);
|
|
52
|
+
return input;
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* Initializes a string as a URL. Throws an error
|
|
57
|
+
* if the string is not a valid URL.
|
|
58
|
+
*/
|
|
59
|
+
exports.url = custom({
|
|
60
|
+
parse: async (input) => {
|
|
61
|
+
try {
|
|
62
|
+
return new url_1.URL(input);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
throw new Error(`Expected a valid url but received: ${input}`);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
const stringFlag = custom({});
|
|
70
|
+
exports.string = stringFlag;
|
|
29
71
|
const version = (opts = {}) => {
|
|
30
|
-
return
|
|
72
|
+
return boolean({
|
|
31
73
|
description: 'Show CLI version.',
|
|
32
74
|
...opts,
|
|
33
|
-
parse: async (_,
|
|
34
|
-
|
|
35
|
-
|
|
75
|
+
parse: async (_, ctx) => {
|
|
76
|
+
ctx.log(ctx.config.userAgent);
|
|
77
|
+
ctx.exit(0);
|
|
36
78
|
},
|
|
37
79
|
});
|
|
38
80
|
};
|
|
39
81
|
exports.version = version;
|
|
40
82
|
const help = (opts = {}) => {
|
|
41
|
-
return
|
|
83
|
+
return boolean({
|
|
42
84
|
description: 'Show CLI help.',
|
|
43
85
|
...opts,
|
|
44
86
|
parse: async (_, cmd) => {
|
package/lib/help/command.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import * as Interfaces from '../interfaces';
|
|
2
|
-
import { Example } from '../interfaces/command';
|
|
3
2
|
import { HelpFormatter, HelpSectionRenderer } from './formatter';
|
|
3
|
+
import { Command } from '../command';
|
|
4
4
|
export declare class CommandHelp extends HelpFormatter {
|
|
5
|
-
command:
|
|
5
|
+
command: Command.Class | Command.Loadable | Command.Cached;
|
|
6
6
|
config: Interfaces.Config;
|
|
7
7
|
opts: Interfaces.HelpOptions;
|
|
8
|
-
constructor(command:
|
|
8
|
+
constructor(command: Command.Class | Command.Loadable | Command.Cached, config: Interfaces.Config, opts: Interfaces.HelpOptions);
|
|
9
9
|
generate(): string;
|
|
10
|
-
protected groupFlags(flags:
|
|
11
|
-
mainFlags:
|
|
10
|
+
protected groupFlags(flags: Array<Command.Flag.Any>): {
|
|
11
|
+
mainFlags: Array<Command.Flag.Any>;
|
|
12
12
|
flagGroups: {
|
|
13
|
-
[
|
|
13
|
+
[name: string]: Array<Command.Flag.Any>;
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
protected sections(): Array<{
|
|
@@ -21,11 +21,11 @@ export declare class CommandHelp extends HelpFormatter {
|
|
|
21
21
|
protected defaultUsage(): string;
|
|
22
22
|
protected description(): string | undefined;
|
|
23
23
|
protected aliases(aliases: string[] | undefined): string | undefined;
|
|
24
|
-
protected examples(examples: Example[] | undefined | string): string | undefined;
|
|
25
|
-
protected args(args:
|
|
26
|
-
protected arg(arg:
|
|
27
|
-
protected flagHelpLabel(flag:
|
|
28
|
-
protected flags(flags:
|
|
29
|
-
protected flagsDescriptions(flags:
|
|
24
|
+
protected examples(examples: Command.Example[] | undefined | string): string | undefined;
|
|
25
|
+
protected args(args: Command.Arg.Any[]): [string, string | undefined][] | undefined;
|
|
26
|
+
protected arg(arg: Command.Arg.Any): string;
|
|
27
|
+
protected flagHelpLabel(flag: Command.Flag.Any, showOptions?: boolean): string;
|
|
28
|
+
protected flags(flags: Array<Command.Flag.Any>): [string, string | undefined][] | undefined;
|
|
29
|
+
protected flagsDescriptions(flags: Array<Command.Flag.Any>): string | undefined;
|
|
30
30
|
}
|
|
31
31
|
export default CommandHelp;
|
package/lib/help/command.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandHelp = void 0;
|
|
4
|
-
const
|
|
4
|
+
const chalk = require("chalk");
|
|
5
5
|
const stripAnsi = require("strip-ansi");
|
|
6
6
|
const util_1 = require("../util");
|
|
7
7
|
const formatter_1 = require("./formatter");
|
|
@@ -10,11 +10,11 @@ const docopts_1 = require("./docopts");
|
|
|
10
10
|
// written on any platform, that may use \r\n or \n, will be
|
|
11
11
|
// split on any platform, not just the os specific EOL at runtime.
|
|
12
12
|
const POSSIBLE_LINE_FEED = /\r\n|\n/;
|
|
13
|
-
const { underline, } =
|
|
14
|
-
let { dim, } =
|
|
13
|
+
const { underline, } = chalk;
|
|
14
|
+
let { dim, } = chalk;
|
|
15
15
|
if (process.env.ConEmuANSI === 'ON') {
|
|
16
16
|
// eslint-disable-next-line unicorn/consistent-destructuring
|
|
17
|
-
dim =
|
|
17
|
+
dim = chalk.gray;
|
|
18
18
|
}
|
|
19
19
|
class CommandHelp extends formatter_1.HelpFormatter {
|
|
20
20
|
constructor(command, config, opts) {
|
|
@@ -31,7 +31,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
31
31
|
v.name = k;
|
|
32
32
|
return v;
|
|
33
33
|
}), f => [!f.char, f.char, f.name]);
|
|
34
|
-
const args = (cmd.args
|
|
34
|
+
const args = Object.values(cmd.args ?? {}).filter(a => !a.hidden);
|
|
35
35
|
const output = (0, util_1.compact)(this.sections().map(({ header, generate }) => {
|
|
36
36
|
const body = generate({ cmd, flags, args }, header);
|
|
37
37
|
// Generate can return a list of sections
|
|
@@ -128,7 +128,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
128
128
|
}
|
|
129
129
|
return (0, util_1.compact)([
|
|
130
130
|
this.command.id,
|
|
131
|
-
this.command.args
|
|
131
|
+
Object.values(this.command.args ?? {})?.filter(a => !a.hidden).map(a => this.arg(a)).join(' '),
|
|
132
132
|
]).join(' ');
|
|
133
133
|
}
|
|
134
134
|
description() {
|
package/lib/help/docopts.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Command } from '../command';
|
|
2
2
|
/**
|
|
3
3
|
* DocOpts - See http://docopt.org/.
|
|
4
4
|
*
|
|
@@ -59,8 +59,8 @@ export declare class DocOpts {
|
|
|
59
59
|
private cmd;
|
|
60
60
|
private flagMap;
|
|
61
61
|
private flagList;
|
|
62
|
-
constructor(cmd:
|
|
63
|
-
static generate(cmd:
|
|
62
|
+
constructor(cmd: Command.Class | Command.Loadable | Command.Cached);
|
|
63
|
+
static generate(cmd: Command.Class | Command.Loadable | Command.Cached): string;
|
|
64
64
|
toString(): string;
|
|
65
65
|
private groupFlagElements;
|
|
66
66
|
private combineElementsToFlag;
|
package/lib/help/docopts.js
CHANGED
|
@@ -75,7 +75,7 @@ class DocOpts {
|
|
|
75
75
|
toString() {
|
|
76
76
|
const opts = this.cmd.id === '.' || this.cmd.id === '' ? [] : ['<%= command.id %>'];
|
|
77
77
|
if (this.cmd.args) {
|
|
78
|
-
const a = this.cmd.args
|
|
78
|
+
const a = Object.values(this.cmd.args ?? {}).map(arg => `[${arg.name.toUpperCase()}]`) || [];
|
|
79
79
|
opts.push(...a);
|
|
80
80
|
}
|
|
81
81
|
try {
|
|
@@ -140,8 +140,7 @@ class DocOpts {
|
|
|
140
140
|
// We handled this flag, don't handle it again
|
|
141
141
|
delete this.flagMap[flagName];
|
|
142
142
|
}
|
|
143
|
-
|
|
144
|
-
generateElements(elementMap = {}, flagGroups) {
|
|
143
|
+
generateElements(elementMap = {}, flagGroups = []) {
|
|
145
144
|
const elementStrs = [];
|
|
146
145
|
for (const flag of flagGroups) {
|
|
147
146
|
let type = '';
|
package/lib/help/formatter.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Command } from '../command';
|
|
1
2
|
import * as Interfaces from '../interfaces';
|
|
2
3
|
export type HelpSectionKeyValueTable = {
|
|
3
4
|
name: string;
|
|
@@ -8,9 +9,9 @@ export type HelpSection = {
|
|
|
8
9
|
body: string | HelpSectionKeyValueTable | [string, string | undefined][] | undefined;
|
|
9
10
|
} | undefined;
|
|
10
11
|
export type HelpSectionRenderer = (data: {
|
|
11
|
-
cmd:
|
|
12
|
-
flags:
|
|
13
|
-
args:
|
|
12
|
+
cmd: Command.Class | Command.Loadable | Command.Cached;
|
|
13
|
+
flags: Command.Flag.Any[];
|
|
14
|
+
args: Command.Arg.Any[];
|
|
14
15
|
}, header: string) => HelpSection | HelpSection[] | string | undefined;
|
|
15
16
|
export declare class HelpFormatter {
|
|
16
17
|
indentSpacing: number;
|
package/lib/help/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Interfaces from '../interfaces';
|
|
2
2
|
import CommandHelp from './command';
|
|
3
3
|
import { HelpFormatter } from './formatter';
|
|
4
|
+
import { Command } from '../command';
|
|
4
5
|
export { CommandHelp } from './command';
|
|
5
6
|
export { standardizeIDFromArgv, loadHelpClass, getHelpFlagAdditions, normalizeArgv } from './util';
|
|
6
7
|
export declare abstract class HelpBase extends HelpFormatter {
|
|
@@ -15,31 +16,26 @@ export declare abstract class HelpBase extends HelpFormatter {
|
|
|
15
16
|
* @param command
|
|
16
17
|
* @param topics
|
|
17
18
|
*/
|
|
18
|
-
abstract showCommandHelp(command:
|
|
19
|
+
abstract showCommandHelp(command: Command.Class, topics: Interfaces.Topic[]): Promise<void>;
|
|
19
20
|
}
|
|
20
21
|
export declare class Help extends HelpBase {
|
|
21
22
|
protected CommandHelpClass: typeof CommandHelp;
|
|
22
23
|
private get _topics();
|
|
23
|
-
protected get sortedCommands():
|
|
24
|
+
protected get sortedCommands(): Command.Loadable[];
|
|
24
25
|
protected get sortedTopics(): Interfaces.Topic[];
|
|
25
26
|
constructor(config: Interfaces.Config, opts?: Partial<Interfaces.HelpOptions>);
|
|
26
27
|
showHelp(argv: string[]): Promise<void>;
|
|
27
|
-
showCommandHelp(command:
|
|
28
|
+
showCommandHelp(command: Command.Class | Command.Loadable | Command.Cached): Promise<void>;
|
|
28
29
|
protected showRootHelp(): Promise<void>;
|
|
29
30
|
protected showTopicHelp(topic: Interfaces.Topic): Promise<void>;
|
|
30
31
|
protected formatRoot(): string;
|
|
31
|
-
protected formatCommand(command:
|
|
32
|
-
protected getCommandHelpClass(command:
|
|
33
|
-
protected formatCommands(commands:
|
|
34
|
-
protected summary(c:
|
|
35
|
-
protected description(c:
|
|
32
|
+
protected formatCommand(command: Command.Class | Command.Loadable | Command.Cached): string;
|
|
33
|
+
protected getCommandHelpClass(command: Command.Class | Command.Loadable | Command.Cached): CommandHelp;
|
|
34
|
+
protected formatCommands(commands: Array<Command.Class | Command.Loadable | Command.Cached>): string;
|
|
35
|
+
protected summary(c: Command.Class | Command.Loadable | Command.Cached): string | undefined;
|
|
36
|
+
protected description(c: Command.Class | Command.Loadable | Command.Cached): string;
|
|
36
37
|
protected formatTopic(topic: Interfaces.Topic): string;
|
|
37
38
|
protected formatTopics(topics: Interfaces.Topic[]): string;
|
|
38
|
-
|
|
39
|
-
* @deprecated used for readme generation
|
|
40
|
-
* @param {object} command The command to generate readme help for
|
|
41
|
-
* @return {string} the readme help string for the given command
|
|
42
|
-
*/
|
|
43
|
-
protected command(command: Interfaces.Command): string;
|
|
39
|
+
protected command(command: Command.Class): string;
|
|
44
40
|
protected log(...args: string[]): void;
|
|
45
41
|
}
|
package/lib/help/index.js
CHANGED
|
@@ -264,11 +264,6 @@ class Help extends HelpBase {
|
|
|
264
264
|
});
|
|
265
265
|
return this.section('TOPICS', body);
|
|
266
266
|
}
|
|
267
|
-
/**
|
|
268
|
-
* @deprecated used for readme generation
|
|
269
|
-
* @param {object} command The command to generate readme help for
|
|
270
|
-
* @return {string} the readme help string for the given command
|
|
271
|
-
*/
|
|
272
267
|
command(command) {
|
|
273
268
|
return this.formatCommand(command);
|
|
274
269
|
}
|
package/lib/help/util.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as ejs from 'ejs';
|
|
2
|
+
import { Config as IConfig, HelpOptions, Deprecation } from '../interfaces';
|
|
2
3
|
import { HelpBase } from '.';
|
|
3
|
-
import { Deprecation } from '../interfaces/parser';
|
|
4
4
|
interface HelpBaseDerived {
|
|
5
5
|
new (config: IConfig, opts?: Partial<HelpOptions>): HelpBase;
|
|
6
6
|
}
|
|
7
7
|
export declare function loadHelpClass(config: IConfig): Promise<HelpBaseDerived>;
|
|
8
|
-
export declare function template(context:
|
|
8
|
+
export declare function template(context: ejs.Data): (t: string) => string;
|
|
9
9
|
export declare function toStandardizedId(commandID: string, config: IConfig): string;
|
|
10
10
|
export declare function toConfiguredId(commandID: string, config: IConfig): string;
|
|
11
11
|
export declare function standardizeIDFromArgv(argv: string[], config: IConfig): string[];
|
package/lib/help/util.js
CHANGED
|
@@ -45,7 +45,7 @@ function collateSpacedCmdIDFromArgs(argv, config) {
|
|
|
45
45
|
if (!id)
|
|
46
46
|
return false;
|
|
47
47
|
const cmd = config.findCommand(id);
|
|
48
|
-
return Boolean(cmd && (cmd.strict === false || cmd.args
|
|
48
|
+
return Boolean(cmd && (cmd.strict === false || Object.keys(cmd.args ?? {}).length > 0));
|
|
49
49
|
};
|
|
50
50
|
for (const arg of argv) {
|
|
51
51
|
if (idPresent(finalizeId(arg)))
|
package/lib/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import Command from './command';
|
|
2
|
-
import { run } from './main';
|
|
1
|
+
import { Command } from './command';
|
|
2
|
+
import { run, execute } from './main';
|
|
3
3
|
import { Config, Plugin, tsPath, toCached } from './config';
|
|
4
4
|
import * as Interfaces from './interfaces';
|
|
5
5
|
import * as Errors from './errors';
|
|
6
6
|
import * as Flags from './flags';
|
|
7
|
+
import * as Args from './args';
|
|
7
8
|
import { CommandHelp, HelpBase, Help, loadHelpClass } from './help';
|
|
8
9
|
import { toStandardizedId, toConfiguredId } from './help/util';
|
|
9
10
|
import * as Parser from './parser';
|
|
10
11
|
import { Hook } from './interfaces/hooks';
|
|
11
12
|
import { settings, Settings } from './settings';
|
|
12
13
|
import { HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable } from './help/formatter';
|
|
13
|
-
import * as
|
|
14
|
+
import * as ux from './cli-ux';
|
|
14
15
|
declare const flush: (ms?: number) => Promise<void>;
|
|
15
|
-
export { Command, CommandHelp, Config, Errors, Flags, loadHelpClass, Help, HelpBase, HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable, Hook, Interfaces, Parser, Plugin, run, toCached, tsPath, toStandardizedId, toConfiguredId, settings, Settings, flush,
|
|
16
|
+
export { Args, Command, CommandHelp, Config, Errors, Flags, loadHelpClass, Help, HelpBase, HelpSection, HelpSectionRenderer, HelpSectionKeyValueTable, Hook, Interfaces, Parser, Plugin, run, toCached, tsPath, toStandardizedId, toConfiguredId, settings, Settings, flush, ux, execute, };
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const path = require("path");
|
|
3
|
+
exports.execute = exports.ux = exports.flush = exports.settings = exports.toConfiguredId = exports.toStandardizedId = exports.tsPath = exports.toCached = exports.run = exports.Plugin = exports.Parser = exports.Interfaces = exports.HelpBase = exports.Help = exports.loadHelpClass = exports.Flags = exports.Errors = exports.Config = exports.CommandHelp = exports.Command = exports.Args = void 0;
|
|
5
4
|
const semver = require("semver");
|
|
6
5
|
const command_1 = require("./command");
|
|
7
|
-
exports
|
|
6
|
+
Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return command_1.Command; } });
|
|
8
7
|
const main_1 = require("./main");
|
|
9
8
|
Object.defineProperty(exports, "run", { enumerable: true, get: function () { return main_1.run; } });
|
|
9
|
+
Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return main_1.execute; } });
|
|
10
10
|
const config_1 = require("./config");
|
|
11
11
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
12
12
|
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return config_1.Plugin; } });
|
|
@@ -18,6 +18,8 @@ const Errors = require("./errors");
|
|
|
18
18
|
exports.Errors = Errors;
|
|
19
19
|
const Flags = require("./flags");
|
|
20
20
|
exports.Flags = Flags;
|
|
21
|
+
const Args = require("./args");
|
|
22
|
+
exports.Args = Args;
|
|
21
23
|
const help_1 = require("./help");
|
|
22
24
|
Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return help_1.CommandHelp; } });
|
|
23
25
|
Object.defineProperty(exports, "HelpBase", { enumerable: true, get: function () { return help_1.HelpBase; } });
|
|
@@ -30,9 +32,10 @@ const Parser = require("./parser");
|
|
|
30
32
|
exports.Parser = Parser;
|
|
31
33
|
const settings_1 = require("./settings");
|
|
32
34
|
Object.defineProperty(exports, "settings", { enumerable: true, get: function () { return settings_1.settings; } });
|
|
33
|
-
const
|
|
34
|
-
exports.
|
|
35
|
-
const
|
|
35
|
+
const ux = require("./cli-ux");
|
|
36
|
+
exports.ux = ux;
|
|
37
|
+
const util_2 = require("./util");
|
|
38
|
+
const flush = ux.flush;
|
|
36
39
|
exports.flush = flush;
|
|
37
40
|
function checkCWD() {
|
|
38
41
|
try {
|
|
@@ -45,8 +48,7 @@ function checkCWD() {
|
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
function checkNodeVersion() {
|
|
48
|
-
const
|
|
49
|
-
const pjson = require(path.join(root, 'package.json'));
|
|
51
|
+
const pjson = (0, util_2.requireJson)(__dirname, '..', 'package.json');
|
|
50
52
|
if (!semver.satisfies(process.versions.node, pjson.engines.node)) {
|
|
51
53
|
process.stderr.write(`WARNING\nWARNING Node version must be ${pjson.engines.node} to use this CLI\nWARNING Current node version: ${process.versions.node}\nWARNING\n`);
|
|
52
54
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ArgInput } from './parser';
|
|
2
|
+
/**
|
|
3
|
+
* Infer the args that are returned by Command.parse. This is useful for when you want to assign the args as a class property.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* export type StatusArgs = Interfaces.InferredArgs<typeof Status.args>
|
|
7
|
+
*
|
|
8
|
+
* export default class Status {
|
|
9
|
+
* static args = {
|
|
10
|
+
* force: Args.boolean({char: 'f', description: 'a flag'}),
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* public args!: StatusArgs
|
|
14
|
+
*
|
|
15
|
+
* public async run(): Promise<StatusArgs> {
|
|
16
|
+
* const result = await this.parse(Status)
|
|
17
|
+
* this.args = result.args
|
|
18
|
+
* return result.args
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export type InferredArgs<T> = T extends ArgInput<infer F> ? F : unknown;
|
|
File without changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PJSON } from './pjson';
|
|
2
2
|
import { Hooks, Hook } from './hooks';
|
|
3
|
-
import { Command } from './command';
|
|
4
3
|
import { Plugin, Options } from './plugin';
|
|
5
4
|
import { Topic } from './topic';
|
|
5
|
+
import { Command } from '../command';
|
|
6
6
|
export type LoadOptions = Options | string | Config | undefined;
|
|
7
7
|
export type PlatformTypes = 'darwin' | 'linux' | 'win32' | 'aix' | 'freebsd' | 'openbsd' | 'sunos' | 'wsl';
|
|
8
8
|
export type ArchTypes = 'arm' | 'arm64' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | 'x86';
|
|
@@ -91,7 +91,6 @@ export interface Config {
|
|
|
91
91
|
readonly commands: Command.Loadable[];
|
|
92
92
|
readonly topics: Topic[];
|
|
93
93
|
readonly commandIDs: string[];
|
|
94
|
-
runCommand<T = unknown>(id: string, argv?: string[]): Promise<T>;
|
|
95
94
|
runCommand<T = unknown>(id: string, argv?: string[], cachedCommand?: Command.Loadable): Promise<T>;
|
|
96
95
|
runHook<T extends keyof Hooks>(event: T, opts: Hooks[T]['options'], timeout?: number): Promise<Hook.Result<Hooks[T]['return']>>;
|
|
97
96
|
getAllCommandIDs(): string[];
|
|
@@ -3,12 +3,12 @@ import { FlagInput } from './parser';
|
|
|
3
3
|
* Infer the flags that are returned by Command.parse. This is useful for when you want to assign the flags as a class property.
|
|
4
4
|
*
|
|
5
5
|
* @example
|
|
6
|
-
* export type StatusFlags = Interfaces.InferredFlags<typeof Status.flags & typeof Status.
|
|
6
|
+
* export type StatusFlags = Interfaces.InferredFlags<typeof Status.flags & typeof Status.baseFlags>
|
|
7
7
|
*
|
|
8
8
|
* export abstract class BaseCommand extends Command {
|
|
9
9
|
* static enableJsonFlag = true
|
|
10
10
|
*
|
|
11
|
-
* static
|
|
11
|
+
* static baseFlags = {
|
|
12
12
|
* config: Flags.string({
|
|
13
13
|
* description: 'specify config file',
|
|
14
14
|
* }),
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export { AlphabetLowercase, AlphabetUppercase } from './alphabet';
|
|
2
2
|
export { Config, ArchTypes, PlatformTypes, LoadOptions } from './config';
|
|
3
|
-
export { Command, Example } from './command';
|
|
4
3
|
export { OclifError, PrettyPrintableError, CommandError } from './errors';
|
|
5
4
|
export { HelpOptions } from './help';
|
|
6
5
|
export { Hook, Hooks } from './hooks';
|
|
7
6
|
export { Manifest } from './manifest';
|
|
8
7
|
export { S3Manifest } from './s3-manifest';
|
|
9
|
-
export {
|
|
8
|
+
export { BooleanFlag, Flag, OptionFlag, Deprecation } from './parser';
|
|
10
9
|
export { PJSON } from './pjson';
|
|
11
10
|
export { Plugin, PluginOptions, Options } from './plugin';
|
|
12
11
|
export { Topic } from './topic';
|
|
13
12
|
export { TSConfig } from './ts-config';
|
|
14
13
|
export { InferredFlags } from './flags';
|
|
14
|
+
export { InferredArgs } from './args';
|