@oclif/core 3.0.0-beta.13 → 3.0.0-beta.15
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 +3 -1
- package/lib/args.d.ts +1 -1
- package/lib/args.js +13 -15
- package/lib/cli-ux/action/base.d.ts +1 -1
- package/lib/cli-ux/action/base.js +20 -15
- package/lib/cli-ux/action/simple.js +10 -8
- package/lib/cli-ux/action/spinner.js +11 -10
- package/lib/cli-ux/config.js +8 -7
- package/lib/cli-ux/flush.js +2 -3
- package/lib/cli-ux/index.d.ts +10 -28
- package/lib/cli-ux/index.js +26 -45
- package/lib/cli-ux/list.js +1 -1
- package/lib/cli-ux/prompt.js +24 -19
- package/lib/cli-ux/styled/index.d.ts +5 -6
- package/lib/cli-ux/styled/index.js +11 -11
- package/lib/cli-ux/styled/json.js +3 -2
- package/lib/cli-ux/styled/object.js +6 -8
- package/lib/cli-ux/styled/table.d.ts +4 -4
- package/lib/cli-ux/styled/table.js +36 -45
- package/lib/cli-ux/wait.js +3 -5
- package/lib/command.d.ts +7 -5
- package/lib/command.js +35 -28
- package/lib/config/config.d.ts +2 -2
- package/lib/config/config.js +57 -43
- package/lib/config/plugin-loader.js +25 -11
- package/lib/config/plugin.d.ts +1 -1
- package/lib/config/plugin.js +66 -56
- package/lib/config/ts-node.d.ts +2 -1
- package/lib/config/ts-node.js +41 -34
- package/lib/config/util.d.ts +1 -5
- package/lib/config/util.js +5 -46
- package/lib/errors/config.js +1 -1
- package/lib/errors/errors/cli.d.ts +1 -1
- package/lib/errors/errors/cli.js +14 -13
- package/lib/errors/errors/exit.d.ts +0 -3
- package/lib/errors/errors/module-load.d.ts +0 -3
- package/lib/errors/errors/pretty-print.js +9 -8
- package/lib/errors/handle.d.ts +12 -2
- package/lib/errors/handle.js +23 -14
- package/lib/errors/index.d.ts +2 -2
- package/lib/errors/index.js +20 -19
- package/lib/errors/logger.js +4 -4
- package/lib/execute.d.ts +5 -5
- package/lib/execute.js +6 -5
- package/lib/flags.d.ts +102 -31
- package/lib/flags.js +75 -42
- package/lib/help/command.d.ts +2 -0
- package/lib/help/command.js +32 -32
- package/lib/help/docopts.js +2 -9
- package/lib/help/formatter.d.ts +1 -1
- package/lib/help/formatter.js +17 -17
- package/lib/help/index.d.ts +2 -2
- package/lib/help/index.js +22 -21
- package/lib/help/root.js +2 -2
- package/lib/help/util.d.ts +1 -1
- package/lib/help/util.js +9 -9
- package/lib/index.d.ts +19 -20
- package/lib/index.js +38 -42
- package/lib/interfaces/config.d.ts +5 -4
- package/lib/interfaces/errors.d.ts +1 -1
- package/lib/interfaces/parser.d.ts +168 -45
- package/lib/interfaces/plugin.d.ts +1 -0
- package/lib/main.d.ts +1 -1
- package/lib/main.js +16 -16
- package/lib/module-loader.d.ts +67 -77
- package/lib/module-loader.js +179 -149
- package/lib/parser/errors.d.ts +2 -2
- package/lib/parser/errors.js +4 -3
- package/lib/parser/help.js +3 -2
- package/lib/parser/parse.d.ts +3 -0
- package/lib/parser/parse.js +56 -52
- package/lib/parser/validate.js +9 -5
- package/lib/performance.d.ts +6 -2
- package/lib/performance.js +23 -12
- package/lib/util.d.ts +25 -1
- package/lib/util.js +93 -29
- package/package.json +10 -15
package/lib/execute.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.execute = void 0;
|
|
4
4
|
const flush_1 = require("./cli-ux/flush");
|
|
5
5
|
const handle_1 = require("./errors/handle");
|
|
6
6
|
const main_1 = require("./main");
|
|
7
|
+
const settings_1 = require("./settings");
|
|
7
8
|
/**
|
|
8
9
|
* Load and run oclif CLI
|
|
9
10
|
*
|
|
@@ -12,7 +13,7 @@ const main_1 = require("./main");
|
|
|
12
13
|
*
|
|
13
14
|
* @example For ESM dev.js
|
|
14
15
|
* ```
|
|
15
|
-
* #!/usr/bin/env node
|
|
16
|
+
* #!/usr/bin/env ts-node
|
|
16
17
|
* void (async () => {
|
|
17
18
|
* const oclif = await import('@oclif/core')
|
|
18
19
|
* await oclif.execute({development: true, dir: import.meta.url})
|
|
@@ -30,7 +31,7 @@ const main_1 = require("./main");
|
|
|
30
31
|
*
|
|
31
32
|
* @example For CJS dev.js
|
|
32
33
|
* ```
|
|
33
|
-
* #!/usr/bin/env node
|
|
34
|
+
* #!/usr/bin/env ts-node
|
|
34
35
|
* void (async () => {
|
|
35
36
|
* const oclif = await import('@oclif/core')
|
|
36
37
|
* await oclif.execute({development: true, dir: __dirname})
|
|
@@ -52,11 +53,11 @@ async function execute(options) {
|
|
|
52
53
|
process.env.NODE_ENV = 'development';
|
|
53
54
|
settings_1.settings.debug = true;
|
|
54
55
|
}
|
|
55
|
-
return (0, main_1.
|
|
56
|
+
return (0, main_1.run)(options.args ?? process.argv.slice(2), options.loadOptions ?? options.dir)
|
|
56
57
|
.then(async (result) => {
|
|
57
58
|
(0, flush_1.flush)();
|
|
58
59
|
return result;
|
|
59
60
|
})
|
|
60
61
|
.catch(async (error) => (0, handle_1.handle)(error));
|
|
61
62
|
}
|
|
62
|
-
exports.
|
|
63
|
+
exports.execute = execute;
|
package/lib/flags.d.ts
CHANGED
|
@@ -1,49 +1,120 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
import { BooleanFlag, CustomOptions, FlagDefinition, OptionFlag } from './interfaces';
|
|
3
|
+
import { URL } from 'node:url';
|
|
4
|
+
type NotArray<T> = T extends Array<any> ? never : T;
|
|
5
|
+
export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<T[], P>> & {
|
|
6
|
+
multiple: true;
|
|
7
|
+
} & ({
|
|
8
|
+
required: true;
|
|
9
|
+
} | {
|
|
10
|
+
default: OptionFlag<T[], P>['default'];
|
|
11
|
+
})): FlagDefinition<T, P, {
|
|
12
|
+
multiple: true;
|
|
13
|
+
requiredOrDefaulted: true;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<T, P>> & {
|
|
16
|
+
multiple?: false | undefined;
|
|
17
|
+
} & ({
|
|
18
|
+
required: true;
|
|
19
|
+
} | {
|
|
20
|
+
default: OptionFlag<NotArray<T>, P>['default'];
|
|
21
|
+
})): FlagDefinition<T, P, {
|
|
22
|
+
multiple: false;
|
|
23
|
+
requiredOrDefaulted: true;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<T, P>> & {
|
|
26
|
+
default?: OptionFlag<NotArray<T>, P>['default'] | undefined;
|
|
27
|
+
multiple?: false | undefined;
|
|
28
|
+
required?: false | undefined;
|
|
29
|
+
}): FlagDefinition<T, P, {
|
|
30
|
+
multiple: false;
|
|
31
|
+
requiredOrDefaulted: false;
|
|
32
|
+
}>;
|
|
33
|
+
export declare function custom<T = string, P extends CustomOptions = CustomOptions>(defaults: Partial<OptionFlag<T[], P>> & {
|
|
34
|
+
multiple: true;
|
|
35
|
+
default?: OptionFlag<T[], P>['default'] | undefined;
|
|
36
|
+
required?: false | undefined;
|
|
37
|
+
}): FlagDefinition<T, P, {
|
|
38
|
+
multiple: true;
|
|
39
|
+
requiredOrDefaulted: false;
|
|
40
|
+
}>;
|
|
41
|
+
export declare function custom<T = string, P extends CustomOptions = CustomOptions>(): FlagDefinition<T, P, {
|
|
42
|
+
multiple: false;
|
|
43
|
+
requiredOrDefaulted: false;
|
|
44
|
+
}>;
|
|
30
45
|
export declare function boolean<T = boolean>(options?: Partial<BooleanFlag<T>>): BooleanFlag<T>;
|
|
31
46
|
export declare const integer: FlagDefinition<number, {
|
|
32
47
|
min?: number | undefined;
|
|
33
48
|
max?: number | undefined;
|
|
49
|
+
}, {
|
|
50
|
+
multiple: false;
|
|
51
|
+
requiredOrDefaulted: false;
|
|
34
52
|
}>;
|
|
35
53
|
export declare const directory: FlagDefinition<string, {
|
|
36
54
|
exists?: boolean | undefined;
|
|
55
|
+
}, {
|
|
56
|
+
multiple: false;
|
|
57
|
+
requiredOrDefaulted: false;
|
|
37
58
|
}>;
|
|
38
59
|
export declare const file: FlagDefinition<string, {
|
|
39
60
|
exists?: boolean | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
multiple: false;
|
|
63
|
+
requiredOrDefaulted: false;
|
|
40
64
|
}>;
|
|
41
65
|
/**
|
|
42
66
|
* Initializes a string as a URL. Throws an error
|
|
43
67
|
* if the string is not a valid URL.
|
|
44
68
|
*/
|
|
45
|
-
export declare const url: FlagDefinition<URL,
|
|
46
|
-
|
|
47
|
-
|
|
69
|
+
export declare const url: FlagDefinition<URL, CustomOptions, {
|
|
70
|
+
multiple: false;
|
|
71
|
+
requiredOrDefaulted: false;
|
|
72
|
+
}>;
|
|
73
|
+
export declare const string: FlagDefinition<string, CustomOptions, {
|
|
74
|
+
multiple: false;
|
|
75
|
+
requiredOrDefaulted: false;
|
|
76
|
+
}>;
|
|
48
77
|
export declare const version: (opts?: Partial<BooleanFlag<boolean>>) => BooleanFlag<void>;
|
|
49
78
|
export declare const help: (opts?: Partial<BooleanFlag<boolean>>) => BooleanFlag<void>;
|
|
79
|
+
type ElementType<T extends ReadonlyArray<unknown>> = T[number];
|
|
80
|
+
export declare function option<T extends readonly string[], P extends CustomOptions>(defaults: Partial<OptionFlag<ElementType<T>[], P>> & {
|
|
81
|
+
options: T;
|
|
82
|
+
multiple: true;
|
|
83
|
+
} & ({
|
|
84
|
+
required: true;
|
|
85
|
+
} | {
|
|
86
|
+
default: OptionFlag<ElementType<T>[], P>['default'] | undefined;
|
|
87
|
+
})): FlagDefinition<typeof defaults.options[number], P, {
|
|
88
|
+
multiple: true;
|
|
89
|
+
requiredOrDefaulted: true;
|
|
90
|
+
}>;
|
|
91
|
+
export declare function option<T extends readonly string[], P extends CustomOptions>(defaults: Partial<OptionFlag<ElementType<T>, P>> & {
|
|
92
|
+
options: T;
|
|
93
|
+
multiple?: false | undefined;
|
|
94
|
+
} & ({
|
|
95
|
+
required: true;
|
|
96
|
+
} | {
|
|
97
|
+
default: OptionFlag<ElementType<T>, P>['default'];
|
|
98
|
+
})): FlagDefinition<typeof defaults.options[number], P, {
|
|
99
|
+
multiple: false;
|
|
100
|
+
requiredOrDefaulted: true;
|
|
101
|
+
}>;
|
|
102
|
+
export declare function option<T extends readonly string[], P extends CustomOptions>(defaults: Partial<OptionFlag<ElementType<T>, P>> & {
|
|
103
|
+
options: T;
|
|
104
|
+
default?: OptionFlag<ElementType<T>, P>['default'] | undefined;
|
|
105
|
+
multiple?: false | undefined;
|
|
106
|
+
required?: false | undefined;
|
|
107
|
+
}): FlagDefinition<typeof defaults.options[number], P, {
|
|
108
|
+
multiple: false;
|
|
109
|
+
requiredOrDefaulted: false;
|
|
110
|
+
}>;
|
|
111
|
+
export declare function option<T extends readonly string[], P extends CustomOptions>(defaults: Partial<OptionFlag<ElementType<T>[], P>> & {
|
|
112
|
+
options: T;
|
|
113
|
+
multiple: true;
|
|
114
|
+
default?: OptionFlag<ElementType<T>[], P>['default'] | undefined;
|
|
115
|
+
required?: false | undefined;
|
|
116
|
+
}): FlagDefinition<typeof defaults.options[number], P, {
|
|
117
|
+
multiple: true;
|
|
118
|
+
requiredOrDefaulted: false;
|
|
119
|
+
}>;
|
|
120
|
+
export {};
|
package/lib/flags.js
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
-
const help_1 = require("./help");
|
|
3
|
+
exports.option = exports.help = exports.version = exports.string = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.custom = void 0;
|
|
6
4
|
const util_1 = require("./util");
|
|
7
5
|
const errors_1 = require("./errors");
|
|
6
|
+
const node_url_1 = require("node:url");
|
|
7
|
+
const help_1 = require("./help");
|
|
8
|
+
/**
|
|
9
|
+
* Create a custom flag.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* type Id = string
|
|
13
|
+
* type IdOpts = { startsWith: string; length: number };
|
|
14
|
+
*
|
|
15
|
+
* export const myFlag = custom<Id, IdOpts>({
|
|
16
|
+
* parse: async (input, opts) => {
|
|
17
|
+
* if (input.startsWith(opts.startsWith) && input.length === opts.length) {
|
|
18
|
+
* return input
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* throw new Error('Invalid id')
|
|
22
|
+
* },
|
|
23
|
+
* })
|
|
24
|
+
*/
|
|
8
25
|
function custom(defaults) {
|
|
9
|
-
return (options = {}) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
};
|
|
26
|
+
return (options = {}) => ({
|
|
27
|
+
parse: async (input, _ctx, _opts) => input,
|
|
28
|
+
...defaults,
|
|
29
|
+
...options,
|
|
30
|
+
input: [],
|
|
31
|
+
multiple: Boolean(options.multiple === undefined ? defaults?.multiple ?? false : options.multiple),
|
|
32
|
+
type: 'option',
|
|
33
|
+
});
|
|
19
34
|
}
|
|
20
35
|
exports.custom = custom;
|
|
21
36
|
function boolean(options = {}) {
|
|
@@ -28,7 +43,7 @@ function boolean(options = {}) {
|
|
|
28
43
|
}
|
|
29
44
|
exports.boolean = boolean;
|
|
30
45
|
exports.integer = custom({
|
|
31
|
-
|
|
46
|
+
async parse(input, _, opts) {
|
|
32
47
|
if (!/^-?\d+$/.test(input))
|
|
33
48
|
throw new errors_1.CLIError(`Expected an integer but received: ${input}`);
|
|
34
49
|
const num = Number.parseInt(input, 10);
|
|
@@ -40,14 +55,14 @@ exports.integer = custom({
|
|
|
40
55
|
},
|
|
41
56
|
});
|
|
42
57
|
exports.directory = custom({
|
|
43
|
-
|
|
58
|
+
async parse(input, _, opts) {
|
|
44
59
|
if (opts.exists)
|
|
45
60
|
return (0, util_1.dirExists)(input);
|
|
46
61
|
return input;
|
|
47
62
|
},
|
|
48
63
|
});
|
|
49
64
|
exports.file = custom({
|
|
50
|
-
|
|
65
|
+
async parse(input, _, opts) {
|
|
51
66
|
if (opts.exists)
|
|
52
67
|
return (0, util_1.fileExists)(input);
|
|
53
68
|
return input;
|
|
@@ -58,37 +73,55 @@ exports.file = custom({
|
|
|
58
73
|
* if the string is not a valid URL.
|
|
59
74
|
*/
|
|
60
75
|
exports.url = custom({
|
|
61
|
-
|
|
76
|
+
async parse(input) {
|
|
62
77
|
try {
|
|
63
|
-
return new
|
|
78
|
+
return new node_url_1.URL(input);
|
|
64
79
|
}
|
|
65
80
|
catch {
|
|
66
|
-
throw new
|
|
81
|
+
throw new errors_1.CLIError(`Expected a valid url but received: ${input}`);
|
|
67
82
|
}
|
|
68
83
|
},
|
|
69
84
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
};
|
|
85
|
+
exports.string = custom();
|
|
86
|
+
const version = (opts = {}) => boolean({
|
|
87
|
+
description: 'Show CLI version.',
|
|
88
|
+
...opts,
|
|
89
|
+
async parse(_, ctx) {
|
|
90
|
+
ctx.log(ctx.config.userAgent);
|
|
91
|
+
ctx.exit(0);
|
|
92
|
+
},
|
|
93
|
+
});
|
|
82
94
|
exports.version = version;
|
|
83
|
-
const help = (opts = {}) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
-
};
|
|
95
|
+
const help = (opts = {}) => boolean({
|
|
96
|
+
description: 'Show CLI help.',
|
|
97
|
+
...opts,
|
|
98
|
+
async parse(_, cmd) {
|
|
99
|
+
const Help = await (0, help_1.loadHelpClass)(cmd.config);
|
|
100
|
+
await new Help(cmd.config, cmd.config.pjson.helpOptions).showHelp(cmd.id ? [cmd.id, ...cmd.argv] : cmd.argv);
|
|
101
|
+
cmd.exit(0);
|
|
102
|
+
},
|
|
103
|
+
});
|
|
94
104
|
exports.help = help;
|
|
105
|
+
/**
|
|
106
|
+
* Create a custom flag that infers the flag type from the provided options.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* export default class MyCommand extends Command {
|
|
110
|
+
* static flags = {
|
|
111
|
+
* name: Flags.option({
|
|
112
|
+
* options: ['foo', 'bar'] as const,
|
|
113
|
+
* })(),
|
|
114
|
+
* }
|
|
115
|
+
* }
|
|
116
|
+
*/
|
|
117
|
+
function option(defaults) {
|
|
118
|
+
return (options = {}) => ({
|
|
119
|
+
parse: async (input, _ctx, _opts) => input,
|
|
120
|
+
...defaults,
|
|
121
|
+
...options,
|
|
122
|
+
input: [],
|
|
123
|
+
multiple: Boolean(options.multiple === undefined ? defaults.multiple : options.multiple),
|
|
124
|
+
type: 'option',
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
exports.option = option;
|
package/lib/help/command.d.ts
CHANGED
|
@@ -27,5 +27,7 @@ export declare class CommandHelp extends HelpFormatter {
|
|
|
27
27
|
protected flagHelpLabel(flag: Command.Flag.Any, showOptions?: boolean): string;
|
|
28
28
|
protected flags(flags: Array<Command.Flag.Any>): [string, string | undefined][] | undefined;
|
|
29
29
|
protected flagsDescriptions(flags: Array<Command.Flag.Any>): string | undefined;
|
|
30
|
+
private formatIfCommand;
|
|
31
|
+
private isCommand;
|
|
30
32
|
}
|
|
31
33
|
export default CommandHelp;
|
package/lib/help/command.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandHelp = void 0;
|
|
4
|
-
const
|
|
5
|
-
const stripAnsi = require("strip-ansi");
|
|
6
|
-
const util_1 = require("../util");
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
7
5
|
const formatter_1 = require("./formatter");
|
|
6
|
+
const util_1 = require("../util");
|
|
8
7
|
const docopts_1 = require("./docopts");
|
|
8
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
9
|
+
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
9
10
|
// Don't use os.EOL because we need to ensure that a string
|
|
10
11
|
// written on any platform, that may use \r\n or \n, will be
|
|
11
12
|
// split on any platform, not just the os specific EOL at runtime.
|
|
12
13
|
const POSSIBLE_LINE_FEED = /\r\n|\n/;
|
|
13
|
-
|
|
14
|
-
let { dim, } = chalk;
|
|
14
|
+
let { dim, } = chalk_1.default;
|
|
15
15
|
if (process.env.ConEmuANSI === 'ON') {
|
|
16
16
|
// eslint-disable-next-line unicorn/consistent-destructuring
|
|
17
|
-
dim =
|
|
17
|
+
dim = chalk_1.default.gray;
|
|
18
18
|
}
|
|
19
19
|
class CommandHelp extends formatter_1.HelpFormatter {
|
|
20
20
|
constructor(command, config, opts) {
|
|
@@ -106,15 +106,15 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
106
106
|
];
|
|
107
107
|
}
|
|
108
108
|
usage() {
|
|
109
|
-
const usage = this.command
|
|
109
|
+
const { usage } = this.command;
|
|
110
110
|
const body = (usage ? (0, util_1.castArray)(usage) : [this.defaultUsage()])
|
|
111
111
|
.map(u => {
|
|
112
112
|
const allowedSpacing = this.opts.maxWidth - this.indentSpacing;
|
|
113
113
|
const line = `$ ${this.config.bin} ${u}`.trim();
|
|
114
114
|
if (line.length > allowedSpacing) {
|
|
115
115
|
const splitIndex = line.slice(0, Math.max(0, allowedSpacing)).lastIndexOf(' ');
|
|
116
|
-
return line.slice(0, Math.max(0, splitIndex)) + '\n'
|
|
117
|
-
this.indent(this.wrap(line.slice(Math.max(0, splitIndex)), this.indentSpacing * 2));
|
|
116
|
+
return line.slice(0, Math.max(0, splitIndex)) + '\n'
|
|
117
|
+
+ this.indent(this.wrap(line.slice(Math.max(0, splitIndex)), this.indentSpacing * 2));
|
|
118
118
|
}
|
|
119
119
|
return this.wrap(line);
|
|
120
120
|
})
|
|
@@ -157,47 +157,36 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
157
157
|
examples(examples) {
|
|
158
158
|
if (!examples || examples.length === 0)
|
|
159
159
|
return;
|
|
160
|
-
const formatIfCommand = (example) => {
|
|
161
|
-
example = this.render(example);
|
|
162
|
-
if (example.startsWith(this.config.bin))
|
|
163
|
-
return dim(`$ ${example}`);
|
|
164
|
-
if (example.startsWith(`$ ${this.config.bin}`))
|
|
165
|
-
return dim(example);
|
|
166
|
-
return example;
|
|
167
|
-
};
|
|
168
|
-
const isCommand = (example) => stripAnsi(formatIfCommand(example)).startsWith(`$ ${this.config.bin}`);
|
|
169
160
|
const body = (0, util_1.castArray)(examples).map(a => {
|
|
170
161
|
let description;
|
|
171
162
|
let commands;
|
|
172
163
|
if (typeof a === 'string') {
|
|
173
164
|
const lines = a
|
|
174
165
|
.split(POSSIBLE_LINE_FEED)
|
|
175
|
-
.filter(
|
|
166
|
+
.filter(Boolean);
|
|
176
167
|
// If the example is <description>\n<command> then format correctly
|
|
177
|
-
|
|
178
|
-
if (lines.length >= 2 && !isCommand(lines[0]) && lines.slice(1).every(isCommand)) {
|
|
168
|
+
if (lines.length >= 2 && !this.isCommand(lines[0]) && lines.slice(1).every(i => this.isCommand(i))) {
|
|
179
169
|
description = lines[0];
|
|
180
170
|
commands = lines.slice(1);
|
|
181
171
|
}
|
|
182
172
|
else {
|
|
183
|
-
return lines.map(line => formatIfCommand(line)).join('\n');
|
|
173
|
+
return lines.map(line => this.formatIfCommand(line)).join('\n');
|
|
184
174
|
}
|
|
185
175
|
}
|
|
186
176
|
else {
|
|
187
177
|
description = a.description;
|
|
188
178
|
commands = [a.command];
|
|
189
179
|
}
|
|
190
|
-
const multilineSeparator = this.config.platform === 'win32'
|
|
191
|
-
(this.config.shell.includes('powershell') ? '`' : '^')
|
|
192
|
-
'\\';
|
|
180
|
+
const multilineSeparator = this.config.platform === 'win32'
|
|
181
|
+
? (this.config.shell.includes('powershell') ? '`' : '^')
|
|
182
|
+
: '\\';
|
|
193
183
|
// The command will be indented in the section, which is also indented
|
|
194
184
|
const finalIndentedSpacing = this.indentSpacing * 2;
|
|
195
|
-
const multilineCommands = commands.map(c =>
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}).join('\n');
|
|
185
|
+
const multilineCommands = commands.map(c =>
|
|
186
|
+
// First indent keeping room for escaped newlines
|
|
187
|
+
this.indent(this.wrap(this.formatIfCommand(c), finalIndentedSpacing + 4))
|
|
188
|
+
// Then add the escaped newline
|
|
189
|
+
.split(POSSIBLE_LINE_FEED).join(` ${multilineSeparator}\n `)).join('\n');
|
|
201
190
|
return `${this.wrap(description, finalIndentedSpacing)}\n\n${multilineCommands}`;
|
|
202
191
|
}).join('\n\n');
|
|
203
192
|
return body;
|
|
@@ -245,7 +234,7 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
245
234
|
if (flag.multiple)
|
|
246
235
|
value += '...';
|
|
247
236
|
if (!value.includes('|'))
|
|
248
|
-
value = underline(value);
|
|
237
|
+
value = chalk_1.default.underline(value);
|
|
249
238
|
label += `=${value}`;
|
|
250
239
|
}
|
|
251
240
|
return label;
|
|
@@ -280,6 +269,17 @@ class CommandHelp extends formatter_1.HelpFormatter {
|
|
|
280
269
|
}).join('\n\n');
|
|
281
270
|
return body;
|
|
282
271
|
}
|
|
272
|
+
formatIfCommand(example) {
|
|
273
|
+
example = this.render(example);
|
|
274
|
+
if (example.startsWith(this.config.bin))
|
|
275
|
+
return dim(`$ ${example}`);
|
|
276
|
+
if (example.startsWith(`$ ${this.config.bin}`))
|
|
277
|
+
return dim(example);
|
|
278
|
+
return example;
|
|
279
|
+
}
|
|
280
|
+
isCommand(example) {
|
|
281
|
+
return (0, strip_ansi_1.default)(this.formatIfCommand(example)).startsWith(`$ ${this.config.bin}`);
|
|
282
|
+
}
|
|
283
283
|
}
|
|
284
284
|
exports.CommandHelp = CommandHelp;
|
|
285
285
|
exports.default = CommandHelp;
|
package/lib/help/docopts.js
CHANGED
|
@@ -76,9 +76,7 @@ class DocOpts {
|
|
|
76
76
|
toString() {
|
|
77
77
|
const opts = this.cmd.id === '.' || this.cmd.id === '' ? [] : ['<%= command.id %>'];
|
|
78
78
|
if (this.cmd.args) {
|
|
79
|
-
const a = Object.values((0, util_1.ensureArgObject)(this.cmd.args)).map(arg => {
|
|
80
|
-
return arg.required ? arg.name.toUpperCase() : `[${arg.name.toUpperCase()}]`;
|
|
81
|
-
}) || [];
|
|
79
|
+
const a = Object.values((0, util_1.ensureArgObject)(this.cmd.args)).map(arg => arg.required ? arg.name.toUpperCase() : `[${arg.name.toUpperCase()}]`) || [];
|
|
82
80
|
opts.push(...a);
|
|
83
81
|
}
|
|
84
82
|
try {
|
|
@@ -134,12 +132,7 @@ class DocOpts {
|
|
|
134
132
|
delete elementMap[toCombine];
|
|
135
133
|
delete this.flagMap[toCombine];
|
|
136
134
|
}
|
|
137
|
-
|
|
138
|
-
elementMap[flagName] = `(${elementMap[flagName] || ''})`;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
elementMap[flagName] = `[${elementMap[flagName] || ''}]`;
|
|
142
|
-
}
|
|
135
|
+
elementMap[flagName] = isRequired ? `(${elementMap[flagName] || ''})` : `[${elementMap[flagName] || ''}]`;
|
|
143
136
|
// We handled this flag, don't handle it again
|
|
144
137
|
delete this.flagMap[flagName];
|
|
145
138
|
}
|
package/lib/help/formatter.d.ts
CHANGED
package/lib/help/formatter.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HelpFormatter = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
|
+
const indent_string_1 = tslib_1.__importDefault(require("indent-string"));
|
|
7
7
|
const screen_1 = require("../screen");
|
|
8
|
+
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
8
9
|
const util_1 = require("./util");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const { bold, } = Chalk;
|
|
10
|
+
const widest_line_1 = tslib_1.__importDefault(require("widest-line"));
|
|
11
|
+
const string_width_1 = tslib_1.__importDefault(require("string-width"));
|
|
12
|
+
const wrap_ansi_1 = tslib_1.__importDefault(require("wrap-ansi"));
|
|
13
13
|
class HelpFormatter {
|
|
14
14
|
constructor(config, opts = {}) {
|
|
15
15
|
this.indentSpacing = 2;
|
|
@@ -46,7 +46,7 @@ class HelpFormatter {
|
|
|
46
46
|
* @returns the formatted wrapped text
|
|
47
47
|
*/
|
|
48
48
|
wrap(body, spacing = this.indentSpacing) {
|
|
49
|
-
return
|
|
49
|
+
return (0, wrap_ansi_1.default)(this.render(body), this.opts.maxWidth - spacing, { hard: true });
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Indent by `this.indentSpacing`. The text should be wrap based on terminal width before indented.
|
|
@@ -78,7 +78,7 @@ class HelpFormatter {
|
|
|
78
78
|
* @return the formatted indented text
|
|
79
79
|
*/
|
|
80
80
|
indent(body, spacing = this.indentSpacing) {
|
|
81
|
-
return
|
|
81
|
+
return (0, indent_string_1.default)(body, spacing);
|
|
82
82
|
}
|
|
83
83
|
renderList(input, opts) {
|
|
84
84
|
if (input.length === 0) {
|
|
@@ -91,12 +91,12 @@ class HelpFormatter {
|
|
|
91
91
|
continue;
|
|
92
92
|
if (left) {
|
|
93
93
|
if (opts.stripAnsi)
|
|
94
|
-
left =
|
|
94
|
+
left = (0, strip_ansi_1.default)(left);
|
|
95
95
|
output += this.wrap(left.trim(), opts.indentation);
|
|
96
96
|
}
|
|
97
97
|
if (right) {
|
|
98
98
|
if (opts.stripAnsi)
|
|
99
|
-
right =
|
|
99
|
+
right = (0, strip_ansi_1.default)(right);
|
|
100
100
|
output += '\n';
|
|
101
101
|
output += this.indent(this.wrap(right.trim(), opts.indentation + 2), 4);
|
|
102
102
|
}
|
|
@@ -106,7 +106,7 @@ class HelpFormatter {
|
|
|
106
106
|
};
|
|
107
107
|
if (opts.multiline)
|
|
108
108
|
return renderMultiline();
|
|
109
|
-
const maxLength =
|
|
109
|
+
const maxLength = (0, widest_line_1.default)(input.map(i => i[0]).join('\n'));
|
|
110
110
|
let output = '';
|
|
111
111
|
let spacer = opts.spacer || '\n';
|
|
112
112
|
let cur = '';
|
|
@@ -118,16 +118,16 @@ class HelpFormatter {
|
|
|
118
118
|
}
|
|
119
119
|
cur = left || '';
|
|
120
120
|
if (opts.stripAnsi)
|
|
121
|
-
cur =
|
|
121
|
+
cur = (0, strip_ansi_1.default)(cur);
|
|
122
122
|
if (!right) {
|
|
123
123
|
cur = cur.trim();
|
|
124
124
|
continue;
|
|
125
125
|
}
|
|
126
126
|
if (opts.stripAnsi)
|
|
127
|
-
right =
|
|
127
|
+
right = (0, strip_ansi_1.default)(right);
|
|
128
128
|
right = this.wrap(right.trim(), opts.indentation + maxLength + 2);
|
|
129
129
|
const [first, ...lines] = right.split('\n').map(s => s.trim());
|
|
130
|
-
cur += ' '.repeat(maxLength -
|
|
130
|
+
cur += ' '.repeat(maxLength - (0, string_width_1.default)(cur) + 2);
|
|
131
131
|
cur += first;
|
|
132
132
|
if (lines.length === 0) {
|
|
133
133
|
continue;
|
|
@@ -172,10 +172,10 @@ class HelpFormatter {
|
|
|
172
172
|
.map(([left, right]) => ([this.render(left), right && this.render(right)]));
|
|
173
173
|
}
|
|
174
174
|
const output = [
|
|
175
|
-
bold(header),
|
|
175
|
+
chalk_1.default.bold(header),
|
|
176
176
|
this.indent(Array.isArray(newBody) ? this.renderList(newBody, { stripAnsi: this.opts.stripAnsi, indentation: 2 }) : newBody),
|
|
177
177
|
].join('\n');
|
|
178
|
-
return this.opts.stripAnsi ?
|
|
178
|
+
return this.opts.stripAnsi ? (0, strip_ansi_1.default)(output) : output;
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
exports.HelpFormatter = HelpFormatter;
|
package/lib/help/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Interfaces from '../interfaces';
|
|
2
|
-
import CommandHelp from './command';
|
|
3
|
-
import { HelpFormatter } from './formatter';
|
|
4
2
|
import { Command } from '../command';
|
|
3
|
+
import { CommandHelp } from './command';
|
|
4
|
+
import { HelpFormatter } from './formatter';
|
|
5
5
|
export { CommandHelp } from './command';
|
|
6
6
|
export { standardizeIDFromArgv, loadHelpClass, getHelpFlagAdditions, normalizeArgv } from './util';
|
|
7
7
|
export declare abstract class HelpBase extends HelpFormatter {
|