@oclif/core 2.0.1 → 2.0.2-beta.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.
Files changed (90) hide show
  1. package/README.md +5 -5
  2. package/lib/args.d.ts +39 -0
  3. package/lib/args.js +62 -0
  4. package/lib/cli-ux/action/base.d.ts +1 -1
  5. package/lib/cli-ux/action/pride-spinner.js +0 -1
  6. package/lib/cli-ux/action/spinner.js +10 -11
  7. package/lib/cli-ux/action/spinners.d.ts +251 -0
  8. package/lib/cli-ux/action/spinners.js +2 -1
  9. package/lib/cli-ux/config.d.ts +1 -1
  10. package/lib/cli-ux/config.js +7 -5
  11. package/lib/cli-ux/index.d.ts +51 -29
  12. package/lib/cli-ux/index.js +111 -69
  13. package/lib/cli-ux/list.js +3 -4
  14. package/lib/cli-ux/prompt.js +9 -8
  15. package/lib/cli-ux/styled/header.js +1 -1
  16. package/lib/cli-ux/styled/index.d.ts +7 -0
  17. package/lib/cli-ux/styled/index.js +15 -0
  18. package/lib/cli-ux/styled/json.d.ts +1 -1
  19. package/lib/cli-ux/styled/json.js +2 -3
  20. package/lib/cli-ux/styled/object.js +1 -1
  21. package/lib/cli-ux/styled/progress.d.ts +2 -1
  22. package/lib/cli-ux/styled/progress.js +1 -5
  23. package/lib/cli-ux/styled/table.js +1 -3
  24. package/lib/cli-ux/styled/tree.js +0 -1
  25. package/lib/cli-ux/wait.d.ts +1 -1
  26. package/lib/cli-ux/wait.js +0 -1
  27. package/lib/command.d.ts +78 -27
  28. package/lib/command.js +51 -43
  29. package/lib/config/config.d.ts +18 -17
  30. package/lib/config/config.js +46 -22
  31. package/lib/config/index.js +0 -5
  32. package/lib/config/plugin.d.ts +3 -2
  33. package/lib/config/plugin.js +4 -13
  34. package/lib/config/util.js +2 -2
  35. package/lib/errors/index.js +0 -1
  36. package/lib/errors/logger.js +2 -4
  37. package/lib/flags.d.ts +46 -18
  38. package/lib/flags.js +71 -29
  39. package/lib/help/command.d.ts +12 -12
  40. package/lib/help/command.js +6 -6
  41. package/lib/help/docopts.d.ts +3 -3
  42. package/lib/help/docopts.js +2 -3
  43. package/lib/help/formatter.d.ts +4 -3
  44. package/lib/help/index.d.ts +10 -14
  45. package/lib/help/index.js +0 -5
  46. package/lib/help/util.d.ts +3 -3
  47. package/lib/help/util.js +1 -1
  48. package/lib/index.d.ts +6 -5
  49. package/lib/index.js +10 -8
  50. package/lib/interfaces/args.d.ts +22 -0
  51. package/lib/interfaces/{command.js → args.js} +0 -0
  52. package/lib/interfaces/config.d.ts +1 -2
  53. package/lib/interfaces/flags.d.ts +2 -2
  54. package/lib/interfaces/hooks.d.ts +1 -1
  55. package/lib/interfaces/index.d.ts +2 -2
  56. package/lib/interfaces/manifest.d.ts +2 -2
  57. package/lib/interfaces/parser.d.ts +96 -81
  58. package/lib/interfaces/plugin.d.ts +1 -1
  59. package/lib/main.d.ts +54 -1
  60. package/lib/main.js +70 -6
  61. package/lib/parser/errors.d.ts +15 -8
  62. package/lib/parser/errors.js +17 -14
  63. package/lib/parser/help.d.ts +1 -1
  64. package/lib/parser/help.js +4 -9
  65. package/lib/parser/index.d.ts +2 -9
  66. package/lib/parser/index.js +5 -26
  67. package/lib/parser/parse.d.ts +4 -11
  68. package/lib/parser/parse.js +108 -72
  69. package/lib/parser/validate.d.ts +1 -1
  70. package/lib/parser/validate.js +6 -3
  71. package/lib/util.d.ts +8 -0
  72. package/lib/util.js +44 -1
  73. package/package.json +4 -4
  74. package/lib/cli-ux/deps.d.ts +0 -22
  75. package/lib/cli-ux/deps.js +0 -47
  76. package/lib/cli-ux/open.d.ts +0 -6
  77. package/lib/cli-ux/open.js +0 -69
  78. package/lib/help/_test-help-class.d.ts +0 -6
  79. package/lib/help/_test-help-class.js +0 -19
  80. package/lib/interfaces/command.d.ts +0 -110
  81. package/lib/parser/args.d.ts +0 -5
  82. package/lib/parser/args.js +0 -11
  83. package/lib/parser/deps.d.ts +0 -4
  84. package/lib/parser/deps.js +0 -17
  85. package/lib/parser/flags.d.ts +0 -60
  86. package/lib/parser/flags.js +0 -107
  87. package/lib/parser/list.d.ts +0 -2
  88. package/lib/parser/list.js +0 -29
  89. package/lib/parser/util.d.ts +0 -7
  90. package/lib/parser/util.js +0 -50
@@ -1,110 +0,0 @@
1
- import { Config, LoadOptions } from './config';
2
- import { ArgInput, BooleanFlagProps, Deprecation, FlagInput, OptionFlagProps } from './parser';
3
- import { Plugin as IPlugin } from './plugin';
4
- export type Example = string | {
5
- description: string;
6
- command: string;
7
- };
8
- export interface CommandProps {
9
- /** A command ID, used mostly in error or verbose reporting. */
10
- id: string;
11
- /** Hide the command from help */
12
- hidden: boolean;
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;
19
- /**
20
- * Emit a deprecation warning when a command alias is used.
21
- */
22
- deprecateAliases?: boolean;
23
- /** An array of aliases for this command. */
24
- aliases: string[];
25
- /**
26
- * The tweet-sized description for your class, used in a parent-commands
27
- * sub-command listing and as the header for the command help.
28
- */
29
- summary?: string;
30
- /**
31
- * A full description of how to use the command.
32
- *
33
- * If no summary, the first line of the description will be used as the summary.
34
- */
35
- description?: string;
36
- /**
37
- * An override string (or strings) for the default usage documentation.
38
- */
39
- usage?: string | string[];
40
- /**
41
- * An array of examples to show at the end of the command's help.
42
- *
43
- * IF only a string is provide, it will try to look for a line that starts
44
- * with the cmd.bin as the example command and the rest as the description.
45
- * If found, the command will be formatted appropriately.
46
- *
47
- * ```
48
- * EXAMPLES:
49
- * A description of a particular use case.
50
- *
51
- * $ <%= config.bin => command flags
52
- * ```
53
- */
54
- examples?: Example[];
55
- }
56
- export interface Command extends CommandProps {
57
- type?: string;
58
- pluginName?: string;
59
- pluginType?: string;
60
- pluginAlias?: string;
61
- flags: {
62
- [name: string]: Command.Flag;
63
- };
64
- args: Command.Arg[];
65
- strict: boolean;
66
- hasDynamicHelp?: boolean;
67
- }
68
- export declare namespace Command {
69
- interface Arg {
70
- name: string;
71
- description?: string;
72
- required?: boolean;
73
- hidden?: boolean;
74
- default?: string;
75
- options?: string[];
76
- }
77
- type Flag = Flag.Boolean | Flag.Option;
78
- namespace Flag {
79
- interface Boolean extends BooleanFlagProps {
80
- }
81
- interface Option extends OptionFlagProps {
82
- default?: string;
83
- defaultHelp?: () => Promise<string>;
84
- }
85
- }
86
- interface Base extends CommandProps {
87
- _base: string;
88
- }
89
- interface Class extends Base {
90
- plugin?: IPlugin;
91
- flags?: FlagInput<any>;
92
- args?: ArgInput;
93
- strict: boolean;
94
- hasDynamicHelp?: boolean;
95
- new (argv: string[], config: Config): Instance;
96
- run(argv?: string[], config?: LoadOptions): PromiseLike<any>;
97
- }
98
- interface Instance {
99
- _run(argv: string[]): Promise<any>;
100
- }
101
- interface Loadable extends Command {
102
- load(): Promise<Class>;
103
- }
104
- /**
105
- * @deprecated use Command.Loadable instead.
106
- */
107
- interface Plugin extends Command {
108
- load(): Promise<Class>;
109
- }
110
- }
@@ -1,5 +0,0 @@
1
- import { ParserArg, Arg, ParseFn } from '../interfaces';
2
- export declare function newArg<T>(arg: Arg & {
3
- Parse: ParseFn<T>;
4
- }): ParserArg<T>;
5
- export declare function newArg(arg: Arg): ParserArg<string>;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.newArg = void 0;
4
- function newArg(arg) {
5
- return {
6
- parse: (i) => i,
7
- ...arg,
8
- required: Boolean(arg.required),
9
- };
10
- }
11
- exports.newArg = newArg;
@@ -1,4 +0,0 @@
1
- declare const _default: () => {
2
- add<T, K extends string, U>(this: T, name: K, fn: () => U): T & { [P in K]: U; };
3
- };
4
- export default _default;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = () => {
4
- const cache = {};
5
- return {
6
- add(name, fn) {
7
- Object.defineProperty(this, name, {
8
- enumerable: true,
9
- get: () => {
10
- cache[name] = cache[name] || fn();
11
- return cache[name];
12
- },
13
- });
14
- return this;
15
- },
16
- };
17
- };
@@ -1,60 +0,0 @@
1
- /// <reference types="node" />
2
- import { URL } from 'url';
3
- import { Definition, OptionFlag, BooleanFlag } from '../interfaces';
4
- import { FlagParser, CustomOptionFlag } from '../interfaces/parser';
5
- /**
6
- * Create a custom flag.
7
- *
8
- * @example
9
- * type Id = string
10
- * type IdOpts = { startsWith: string; length: number };
11
- *
12
- * export const myFlag = custom<Id, IdOpts>({
13
- * parse: async (input, opts) => {
14
- * if (input.startsWith(opts.startsWith) && input.length === opts.length) {
15
- * return input
16
- * }
17
- *
18
- * throw new Error('Invalid id')
19
- * },
20
- * })
21
- */
22
- export declare function custom<T, P = Record<string, unknown>>(defaults: {
23
- parse: FlagParser<T, string, P>;
24
- multiple: true;
25
- } & Partial<CustomOptionFlag<T, P, true>>): Definition<T, P>;
26
- export declare function custom<T, P = Record<string, unknown>>(defaults: {
27
- parse: FlagParser<T, string, P>;
28
- } & Partial<CustomOptionFlag<T, P>>): Definition<T, P>;
29
- export declare function custom<T = string, P = Record<string, unknown>>(defaults: Partial<CustomOptionFlag<T, P>>): Definition<T, P>;
30
- /**
31
- * @deprecated Use Flags.custom instead.
32
- */
33
- export declare function build<T>(defaults: {
34
- parse: OptionFlag<T>['parse'];
35
- } & Partial<OptionFlag<T>>): Definition<T>;
36
- export declare function build(defaults: Partial<OptionFlag<string>>): Definition<string>;
37
- export declare function boolean<T = boolean>(options?: Partial<BooleanFlag<T>>): BooleanFlag<T>;
38
- export declare const integer: Definition<number, {
39
- min?: number | undefined;
40
- max?: number | undefined;
41
- }>;
42
- export declare const directory: Definition<string, {
43
- exists?: boolean | undefined;
44
- }>;
45
- export declare const file: Definition<string, {
46
- exists?: boolean | undefined;
47
- }>;
48
- /**
49
- * Initializes a string as a URL. Throws an error
50
- * if the string is not a valid URL.
51
- */
52
- export declare const url: Definition<URL, Record<string, unknown>>;
53
- export declare function option<T>(options: {
54
- parse: OptionFlag<T>['parse'];
55
- } & Partial<CustomOptionFlag<T>>): OptionFlag<T | undefined>;
56
- declare const stringFlag: Definition<string, Record<string, unknown>>;
57
- export { stringFlag as string };
58
- export declare const defaultFlags: {
59
- color: BooleanFlag<boolean>;
60
- };
@@ -1,107 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultFlags = exports.string = exports.option = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.build = exports.custom = void 0;
4
- const url_1 = require("url");
5
- const fs = require("fs");
6
- function custom(defaults) {
7
- return (options = {}) => {
8
- return {
9
- parse: async (i, _context, _opts) => i,
10
- ...defaults,
11
- ...options,
12
- input: [],
13
- multiple: Boolean(options.multiple === undefined ? defaults.multiple : options.multiple),
14
- type: 'option',
15
- };
16
- };
17
- }
18
- exports.custom = custom;
19
- function build(defaults) {
20
- return (options = {}) => {
21
- return {
22
- parse: async (i, _context) => i,
23
- ...defaults,
24
- ...options,
25
- input: [],
26
- multiple: Boolean(options.multiple === undefined ? defaults.multiple : options.multiple),
27
- type: 'option',
28
- };
29
- };
30
- }
31
- exports.build = build;
32
- function boolean(options = {}) {
33
- return {
34
- parse: async (b, _) => b,
35
- ...options,
36
- allowNo: Boolean(options.allowNo),
37
- type: 'boolean',
38
- };
39
- }
40
- exports.boolean = boolean;
41
- exports.integer = custom({
42
- parse: async (input, _, opts) => {
43
- if (!/^-?\d+$/.test(input))
44
- throw new Error(`Expected an integer but received: ${input}`);
45
- const num = Number.parseInt(input, 10);
46
- if (opts.min !== undefined && num < opts.min)
47
- throw new Error(`Expected an integer greater than or equal to ${opts.min} but received: ${input}`);
48
- if (opts.max !== undefined && num > opts.max)
49
- throw new Error(`Expected an integer less than or equal to ${opts.max} but received: ${input}`);
50
- return num;
51
- },
52
- });
53
- exports.directory = custom({
54
- parse: async (input, _, opts) => {
55
- if (opts.exists)
56
- return dirExists(input);
57
- return input;
58
- },
59
- });
60
- exports.file = custom({
61
- parse: async (input, _, opts) => {
62
- if (opts.exists)
63
- return fileExists(input);
64
- return input;
65
- },
66
- });
67
- /**
68
- * Initializes a string as a URL. Throws an error
69
- * if the string is not a valid URL.
70
- */
71
- exports.url = custom({
72
- parse: async (input) => {
73
- try {
74
- return new url_1.URL(input);
75
- }
76
- catch {
77
- throw new Error(`Expected a valid url but received: ${input}`);
78
- }
79
- },
80
- });
81
- function option(options) {
82
- return custom(options)();
83
- }
84
- exports.option = option;
85
- const stringFlag = custom({});
86
- exports.string = stringFlag;
87
- exports.defaultFlags = {
88
- color: boolean({ allowNo: true }),
89
- };
90
- const dirExists = async (input) => {
91
- if (!fs.existsSync(input)) {
92
- throw new Error(`No directory found at ${input}`);
93
- }
94
- if (!(await fs.promises.stat(input)).isDirectory()) {
95
- throw new Error(`${input} exists but is not a directory`);
96
- }
97
- return input;
98
- };
99
- const fileExists = async (input) => {
100
- if (!fs.existsSync(input)) {
101
- throw new Error(`No file found at ${input}`);
102
- }
103
- if (!(await fs.promises.stat(input)).isFile()) {
104
- throw new Error(`${input} exists but is not a file`);
105
- }
106
- return input;
107
- };
@@ -1,2 +0,0 @@
1
- import { List } from '../interfaces';
2
- export declare function renderList(items: List): string;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderList = void 0;
4
- const screen_1 = require("../screen");
5
- const util_1 = require("./util");
6
- function linewrap(length, s) {
7
- const lw = require('@oclif/linewrap');
8
- return lw(length, screen_1.stdtermwidth, {
9
- skipScheme: 'ansi-color',
10
- })(s).trim();
11
- }
12
- function renderList(items) {
13
- if (items.length === 0) {
14
- return '';
15
- }
16
- const maxLength = (0, util_1.maxBy)(items, i => i[0].length)[0].length;
17
- const lines = items.map(i => {
18
- let left = i[0];
19
- let right = i[1];
20
- if (!right) {
21
- return left;
22
- }
23
- left = left.padEnd(maxLength);
24
- right = linewrap(maxLength + 2, right);
25
- return `${left} ${right}`;
26
- });
27
- return lines.join('\n');
28
- }
29
- exports.renderList = renderList;
@@ -1,7 +0,0 @@
1
- export declare function pickBy<T extends {
2
- [s: string]: T[keyof T];
3
- } | ArrayLike<T[keyof T]>>(obj: T, fn: (i: T[keyof T]) => boolean): Partial<T>;
4
- export declare function maxBy<T>(arr: T[], fn: (i: T) => number): T | undefined;
5
- type SortTypes = string | number | undefined | boolean;
6
- export declare function sortBy<T>(arr: T[], fn: (i: T) => SortTypes | SortTypes[]): T[];
7
- export {};
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sortBy = exports.maxBy = exports.pickBy = void 0;
4
- function pickBy(obj, fn) {
5
- return Object.entries(obj)
6
- .reduce((o, [k, v]) => {
7
- if (fn(v))
8
- o[k] = v;
9
- return o;
10
- }, {});
11
- }
12
- exports.pickBy = pickBy;
13
- function maxBy(arr, fn) {
14
- let max;
15
- for (const cur of arr) {
16
- const i = fn(cur);
17
- if (!max || i > max.i) {
18
- max = { i, element: cur };
19
- }
20
- }
21
- return max && max.element;
22
- }
23
- exports.maxBy = maxBy;
24
- function sortBy(arr, fn) {
25
- // function castType(t: SortTypes | SortTypes[]): string | number | SortTypes[] {
26
- // if (t === undefined) return 0
27
- // if (t === false) return 1
28
- // if (t === true) return -1
29
- // return t
30
- // }
31
- function compare(a, b) {
32
- a = a === undefined ? 0 : a;
33
- b = b === undefined ? 0 : b;
34
- if (Array.isArray(a) && Array.isArray(b)) {
35
- if (a.length === 0 && b.length === 0)
36
- return 0;
37
- const diff = compare(a[0], b[0]);
38
- if (diff !== 0)
39
- return diff;
40
- return compare(a.slice(1), b.slice(1));
41
- }
42
- if (a < b)
43
- return -1;
44
- if (a > b)
45
- return 1;
46
- return 0;
47
- }
48
- return arr.sort((a, b) => compare(fn(a), fn(b)));
49
- }
50
- exports.sortBy = sortBy;