burgee 0.0.0 → 0.3.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.
Files changed (116) hide show
  1. package/README.md +28 -1
  2. package/dist/agent.d.ts +19 -0
  3. package/dist/agent.js +25 -0
  4. package/dist/brand.d.ts +186 -0
  5. package/dist/brand.js +232 -0
  6. package/dist/cli.d.ts +62 -0
  7. package/dist/cli.js +121 -0
  8. package/dist/commander-argument.d.ts +22 -0
  9. package/dist/commander-argument.js +72 -0
  10. package/dist/commander-command.d.ts +355 -0
  11. package/dist/commander-command.js +1621 -0
  12. package/dist/commander-error.d.ts +10 -0
  13. package/dist/commander-error.js +20 -0
  14. package/dist/commander-help.d.ts +67 -0
  15. package/dist/commander-help.js +319 -0
  16. package/dist/commander-option.d.ts +58 -0
  17. package/dist/commander-option.js +164 -0
  18. package/dist/commander-suggest.d.ts +2 -0
  19. package/dist/commander-suggest.js +59 -0
  20. package/dist/commander.d.ts +18 -0
  21. package/dist/commander.js +12 -0
  22. package/dist/completions.d.ts +39 -0
  23. package/dist/completions.js +224 -0
  24. package/dist/config.d.ts +28 -0
  25. package/dist/config.js +98 -0
  26. package/dist/contrast.d.ts +70 -0
  27. package/dist/contrast.js +93 -0
  28. package/dist/dev.d.ts +47 -0
  29. package/dist/dev.js +132 -0
  30. package/dist/execute.d.ts +118 -0
  31. package/dist/execute.js +469 -0
  32. package/dist/exit-code.d.ts +18 -0
  33. package/dist/exit-code.js +12 -0
  34. package/dist/help.d.ts +34 -0
  35. package/dist/help.js +187 -0
  36. package/dist/index.d.ts +16 -1
  37. package/dist/index.js +9 -2
  38. package/dist/manifest.d.ts +207 -0
  39. package/dist/manifest.js +66 -0
  40. package/dist/mcp.d.ts +52 -0
  41. package/dist/mcp.js +124 -0
  42. package/dist/names.d.ts +5 -0
  43. package/dist/names.js +6 -0
  44. package/dist/pkg.d.ts +5 -0
  45. package/dist/pkg.js +21 -0
  46. package/dist/precedence.d.ts +55 -0
  47. package/dist/precedence.js +100 -0
  48. package/dist/runtime.d.ts +39 -0
  49. package/dist/runtime.js +24 -0
  50. package/dist/schema.d.ts +79 -0
  51. package/dist/schema.js +116 -0
  52. package/dist/testing-helpers.d.ts +79 -0
  53. package/dist/testing-helpers.js +145 -0
  54. package/dist/testing.d.ts +10 -0
  55. package/dist/testing.js +3 -0
  56. package/dist/validate.d.ts +27 -0
  57. package/dist/validate.js +133 -0
  58. package/dist/yargs-burgee.d.ts +50 -0
  59. package/dist/yargs-burgee.js +104 -0
  60. package/dist/yargs-cliui.d.ts +56 -0
  61. package/dist/yargs-cliui.js +421 -0
  62. package/dist/yargs-command.d.ts +82 -0
  63. package/dist/yargs-command.js +414 -0
  64. package/dist/yargs-completion.d.ts +41 -0
  65. package/dist/yargs-completion.js +271 -0
  66. package/dist/yargs-factory.d.ts +193 -0
  67. package/dist/yargs-factory.js +1606 -0
  68. package/dist/yargs-helpers.d.ts +6 -0
  69. package/dist/yargs-helpers.js +2 -0
  70. package/dist/yargs-middleware.d.ts +32 -0
  71. package/dist/yargs-middleware.js +81 -0
  72. package/dist/yargs-parser.d.ts +41 -0
  73. package/dist/yargs-parser.js +929 -0
  74. package/dist/yargs-shim.d.ts +54 -0
  75. package/dist/yargs-shim.js +84 -0
  76. package/dist/yargs-usage.d.ts +42 -0
  77. package/dist/yargs-usage.js +479 -0
  78. package/dist/yargs-utils.d.ts +33 -0
  79. package/dist/yargs-utils.js +209 -0
  80. package/dist/yargs-validation.d.ts +26 -0
  81. package/dist/yargs-validation.js +261 -0
  82. package/dist/yargs-y18n.d.ts +21 -0
  83. package/dist/yargs-y18n.js +117 -0
  84. package/dist/yargs.d.ts +6 -0
  85. package/dist/yargs.js +8 -0
  86. package/locales/be.json +46 -0
  87. package/locales/cs.json +51 -0
  88. package/locales/de.json +46 -0
  89. package/locales/en.json +55 -0
  90. package/locales/es.json +46 -0
  91. package/locales/fi.json +49 -0
  92. package/locales/fr.json +53 -0
  93. package/locales/he.json +55 -0
  94. package/locales/hi.json +49 -0
  95. package/locales/hu.json +46 -0
  96. package/locales/id.json +50 -0
  97. package/locales/it.json +46 -0
  98. package/locales/ja.json +51 -0
  99. package/locales/ka.json +55 -0
  100. package/locales/ko.json +49 -0
  101. package/locales/nb.json +44 -0
  102. package/locales/nl.json +49 -0
  103. package/locales/nn.json +44 -0
  104. package/locales/pirate.json +13 -0
  105. package/locales/pl.json +49 -0
  106. package/locales/pt.json +45 -0
  107. package/locales/pt_BR.json +48 -0
  108. package/locales/ru.json +51 -0
  109. package/locales/th.json +46 -0
  110. package/locales/tr.json +48 -0
  111. package/locales/uk_UA.json +51 -0
  112. package/locales/uz.json +52 -0
  113. package/locales/zh_CN.json +48 -0
  114. package/locales/zh_TW.json +51 -0
  115. package/package.json +62 -9
  116. package/dist/index.js.map +0 -1
@@ -0,0 +1,54 @@
1
+ /**
2
+ * yargs' Node platform shim — the one object every yargs module reaches the platform
3
+ * through — built from burgee's own ports of its dependencies (J9). Anything that
4
+ * yargs 18 took from `cliui`, `escalade`, `get-caller-file`, `string-width`, `y18n`
5
+ * and `yargs-parser` is served from here.
6
+ */
7
+ import { readdirSync, readFileSync } from 'node:fs';
8
+ import { basename, dirname, extname, join, relative, resolve } from 'node:path';
9
+ import { inspect } from 'node:util';
10
+ import { cliui } from './yargs-cliui.js';
11
+ import { Parser } from './yargs-parser.js';
12
+ import { type Y18N } from './yargs-y18n.js';
13
+ export interface PlatformShim {
14
+ assert: {
15
+ notStrictEqual: (a: any, b: any, m?: string) => void;
16
+ strictEqual: (a: any, b: any, m?: string) => void;
17
+ };
18
+ cliui: typeof cliui;
19
+ findUp: (start: string, callback: (dir: string, names: string[]) => string | undefined) => string | undefined;
20
+ getEnv: (key: string) => string | undefined;
21
+ inspect: typeof inspect;
22
+ getProcessArgvBin: () => string;
23
+ mainFilename: string;
24
+ Parser: typeof Parser;
25
+ path: {
26
+ basename: typeof basename;
27
+ dirname: typeof dirname;
28
+ extname: typeof extname;
29
+ relative: typeof relative;
30
+ resolve: typeof resolve;
31
+ join: typeof join;
32
+ };
33
+ process: {
34
+ argv: () => string[];
35
+ cwd: () => string;
36
+ emitWarning: (warning: string | Error, type?: string) => void;
37
+ execPath: () => string;
38
+ exit: (code: number) => void;
39
+ nextTick: (cb: () => void) => void;
40
+ stdColumns: number | null;
41
+ /** burgee: the streams --mcp serves on, reached through the shim like everything else. */
42
+ stdin: () => NodeJS.ReadableStream;
43
+ stdout: () => {
44
+ write: (s: string) => unknown;
45
+ };
46
+ };
47
+ readFileSync: typeof readFileSync;
48
+ readdirSync: typeof readdirSync;
49
+ require: NodeJS.Require;
50
+ getCallerFile: () => string;
51
+ stringWidth: (str: string) => number;
52
+ y18n: Y18N;
53
+ }
54
+ export declare const shim: PlatformShim;
@@ -0,0 +1,84 @@
1
+ import { readdirSync, readFileSync, statSync } from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import { basename, dirname, extname, join, relative, resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { inspect } from 'node:util';
6
+ import { cliui, stringWidth } from './yargs-cliui.js';
7
+ import { Parser } from './yargs-parser.js';
8
+ import { getProcessArgvBin } from './yargs-utils.js';
9
+ import { y18n } from './yargs-y18n.js';
10
+ const here = fileURLToPath(import.meta.url);
11
+ const mainFilename = here.substring(0, here.lastIndexOf('node_modules'));
12
+ const nodeRequire = createRequire(import.meta.url);
13
+ function findUp(start, callback) {
14
+ let dir = resolve('.', start);
15
+ let tmp;
16
+ const stats = statSync(dir);
17
+ if (!stats.isDirectory())
18
+ dir = dirname(dir);
19
+ for (;;) {
20
+ tmp = callback(dir, readdirSync(dir));
21
+ if (tmp)
22
+ return resolve(dir, tmp);
23
+ tmp = dir;
24
+ dir = dirname(dir);
25
+ if (tmp === dir)
26
+ break;
27
+ }
28
+ return undefined;
29
+ }
30
+ function getCallerFile(position = 2) {
31
+ if (position >= Error.stackTraceLimit) {
32
+ throw new TypeError(`getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: \`${position}\` and Error.stackTraceLimit was: \`${Error.stackTraceLimit}\``);
33
+ }
34
+ const oldPrepareStackTrace = Error.prepareStackTrace;
35
+ Error.prepareStackTrace = (_, stack) => stack;
36
+ const stack = new Error().stack;
37
+ Error.prepareStackTrace = oldPrepareStackTrace;
38
+ if (stack !== null && typeof stack === 'object') {
39
+ const site = stack[position];
40
+ return site ? (site.getFileName() ?? undefined) : undefined;
41
+ }
42
+ return undefined;
43
+ }
44
+ function notStrictEqual(actual, expected, message) {
45
+ if (actual === expected)
46
+ throw new Error(message ?? `Expected "actual" to be strictly unequal to: ${inspect(expected)}`);
47
+ }
48
+ function strictEqual(actual, expected, message) {
49
+ if (actual !== expected)
50
+ throw new Error(message ?? `Expected values to be strictly equal:\n\n${inspect(actual)} !== ${inspect(expected)}\n`);
51
+ }
52
+ export const shim = {
53
+ assert: { notStrictEqual, strictEqual },
54
+ cliui,
55
+ findUp,
56
+ getEnv: (key) => process.env[key],
57
+ inspect,
58
+ getProcessArgvBin,
59
+ mainFilename: mainFilename || process.cwd(),
60
+ Parser,
61
+ path: { basename, dirname, extname, relative, resolve, join },
62
+ process: {
63
+ argv: () => process.argv,
64
+ cwd: process.cwd,
65
+ emitWarning: (warning, type) => process.emitWarning(warning, type),
66
+ execPath: () => process.execPath,
67
+ exit: (code) => {
68
+ process.exit(code);
69
+ },
70
+ nextTick: process.nextTick,
71
+ stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null,
72
+ stdin: () => process.stdin,
73
+ stdout: () => process.stdout,
74
+ },
75
+ readFileSync,
76
+ readdirSync,
77
+ require: nodeRequire,
78
+ getCallerFile: () => {
79
+ const callerFile = getCallerFile(3) ?? '';
80
+ return /^file:\/\//.exec(callerFile) ? fileURLToPath(callerFile) : callerFile;
81
+ },
82
+ stringWidth,
83
+ y18n: y18n({ directory: resolve(dirname(here), '../locales'), updateFiles: false }),
84
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * yargs' usage — the help screen, `fail`, examples, epilogues, descriptions and the
3
+ * version string — ported for `burgee/yargs`. Help is rendered through the cliui port,
4
+ * so yargs' usage tests compare whole screens byte for byte.
5
+ */
6
+ import type { PlatformShim } from './yargs-shim.js';
7
+ export type FailureFunction = (msg: string | undefined | null, err: Error | undefined, usage: UsageInstance) => void;
8
+ export interface UsageInstance {
9
+ failFn: (f: FailureFunction | boolean) => void;
10
+ showHelpOnFail: (arg1?: boolean | string, arg2?: string) => UsageInstance;
11
+ fail: (msg?: string | null, err?: Error) => void;
12
+ usage: (msg: string | null, description?: string | false) => UsageInstance;
13
+ getUsage: () => [string, string][];
14
+ getUsageDisabled: () => boolean;
15
+ getPositionalGroupName: () => string;
16
+ example: (cmd: string, description?: string) => void;
17
+ command: (cmd: string, description: string | false, isDefault: boolean, aliases: string[], deprecated?: boolean | string) => void;
18
+ getCommands: () => [string, string, boolean, string[], boolean | string][];
19
+ describe: (keyOrKeys: string | string[] | Record<string, string>, desc?: string) => void;
20
+ getDescriptions: () => Record<string, string | undefined>;
21
+ epilog: (msg: string) => void;
22
+ wrap: (cols: number | null | undefined) => void;
23
+ getWrap: () => number | null | undefined;
24
+ deferY18nLookup: (str: string) => string;
25
+ help: () => string;
26
+ cacheHelpMessage: () => void;
27
+ clearCachedHelpMessage: () => void;
28
+ hasCachedHelpMessage: () => boolean;
29
+ showHelp: (level?: 'error' | 'log' | ((message: string) => void)) => void;
30
+ functionDescription: (fn: {
31
+ name?: string;
32
+ }) => string;
33
+ stringifiedValues: (values?: any[], separator?: string) => string;
34
+ version: (ver: any) => void;
35
+ /** burgee: the version string `.version()` recorded, for the manifest. */
36
+ getVersion: () => any;
37
+ showVersion: (level?: 'error' | 'log' | ((message: string) => void)) => void;
38
+ reset: (localLookup: Record<string, boolean>) => UsageInstance;
39
+ freeze: () => void;
40
+ unfreeze: (defaultCommand?: boolean) => void;
41
+ }
42
+ export declare function usage(yargs: any, shim: PlatformShim): UsageInstance;
@@ -0,0 +1,479 @@
1
+ import { objFilter, setBlocking, YError } from './yargs-utils.js';
2
+ function isBoolean(fail) {
3
+ return typeof fail === 'boolean';
4
+ }
5
+ export function usage(yargs, shim) {
6
+ const __ = shim.y18n.__;
7
+ const self = {};
8
+ const fails = [];
9
+ self.failFn = function failFn(f) {
10
+ fails.push(f);
11
+ };
12
+ let failMessage = null;
13
+ let globalFailMessage = null;
14
+ let showHelpOnFail = true;
15
+ self.showHelpOnFail = function showHelpOnFailFn(arg1 = true, arg2) {
16
+ const [enabled, message] = typeof arg1 === 'string' ? [true, arg1] : [arg1, arg2];
17
+ if (yargs.getInternalMethods().isGlobalContext())
18
+ globalFailMessage = message;
19
+ failMessage = message;
20
+ showHelpOnFail = enabled;
21
+ return self;
22
+ };
23
+ let failureOutput = false;
24
+ self.fail = function fail(msg, err) {
25
+ const logger = yargs.getInternalMethods().getLoggerInstance();
26
+ if (fails.length) {
27
+ for (let i = fails.length - 1; i >= 0; --i) {
28
+ const f = fails[i];
29
+ if (isBoolean(f)) {
30
+ if (err)
31
+ throw err;
32
+ else if (msg)
33
+ throw Error(msg);
34
+ }
35
+ else
36
+ f(msg, err, self);
37
+ }
38
+ }
39
+ else {
40
+ if (yargs.getExitProcess())
41
+ setBlocking(true);
42
+ if (!failureOutput) {
43
+ failureOutput = true;
44
+ if (showHelpOnFail) {
45
+ yargs.showHelp('error');
46
+ logger.error();
47
+ }
48
+ if (msg || err)
49
+ logger.error(msg || err);
50
+ const globalOrCommandFailMessage = failMessage || globalFailMessage;
51
+ if (globalOrCommandFailMessage) {
52
+ if (msg || err)
53
+ logger.error('');
54
+ logger.error(globalOrCommandFailMessage);
55
+ }
56
+ }
57
+ err = err || new YError(msg);
58
+ if (yargs.getExitProcess())
59
+ return yargs.exit(1, err);
60
+ else if (yargs.getInternalMethods().hasParseCallback())
61
+ return yargs.exit(1, err);
62
+ else
63
+ throw err;
64
+ }
65
+ };
66
+ let usages = [];
67
+ let usageDisabled = false;
68
+ self.usage = (msg, description) => {
69
+ if (msg === null) {
70
+ usageDisabled = true;
71
+ usages = [];
72
+ return self;
73
+ }
74
+ usageDisabled = false;
75
+ usages.push([msg, description || '']);
76
+ return self;
77
+ };
78
+ self.getUsage = () => usages;
79
+ self.getUsageDisabled = () => usageDisabled;
80
+ self.getPositionalGroupName = () => __('Positionals:');
81
+ let examples = [];
82
+ self.example = (cmd, description) => {
83
+ examples.push([cmd, description || '']);
84
+ };
85
+ let commands = [];
86
+ self.command = function command(cmd, description, isDefault, aliases, deprecated = false) {
87
+ if (isDefault) {
88
+ commands = commands.map((cmdArray) => {
89
+ cmdArray[2] = false;
90
+ return cmdArray;
91
+ });
92
+ }
93
+ commands.push([cmd, description || '', isDefault, aliases, deprecated]);
94
+ };
95
+ self.getCommands = () => commands;
96
+ let descriptions = {};
97
+ self.describe = function describe(keyOrKeys, desc) {
98
+ if (Array.isArray(keyOrKeys)) {
99
+ keyOrKeys.forEach((k) => {
100
+ self.describe(k, desc);
101
+ });
102
+ }
103
+ else if (typeof keyOrKeys === 'object') {
104
+ Object.keys(keyOrKeys).forEach((k) => {
105
+ self.describe(k, keyOrKeys[k]);
106
+ });
107
+ }
108
+ else
109
+ descriptions[keyOrKeys] = desc;
110
+ };
111
+ self.getDescriptions = () => descriptions;
112
+ let epilogs = [];
113
+ self.epilog = (msg) => {
114
+ epilogs.push(msg);
115
+ };
116
+ let wrapSet = false;
117
+ let wrap;
118
+ self.wrap = (cols) => {
119
+ wrapSet = true;
120
+ wrap = cols;
121
+ };
122
+ self.getWrap = () => {
123
+ if (shim.getEnv('YARGS_DISABLE_WRAP'))
124
+ return null;
125
+ if (!wrapSet) {
126
+ wrap = windowWidth();
127
+ wrapSet = true;
128
+ }
129
+ return wrap;
130
+ };
131
+ const deferY18nLookupPrefix = '__yargsString__:';
132
+ self.deferY18nLookup = (str) => deferY18nLookupPrefix + str;
133
+ self.help = function help() {
134
+ if (cachedHelpMessage)
135
+ return cachedHelpMessage;
136
+ normalizeAliases();
137
+ const base$0 = yargs.customScriptName ? yargs.$0 : shim.path.basename(yargs.$0);
138
+ const demandedOptions = yargs.getDemandedOptions();
139
+ const demandedCommands = yargs.getDemandedCommands();
140
+ const deprecatedOptions = yargs.getDeprecatedOptions();
141
+ const groups = yargs.getGroups();
142
+ const options = yargs.getOptions();
143
+ let keys = [];
144
+ keys = keys.concat(Object.keys(descriptions));
145
+ keys = keys.concat(Object.keys(demandedOptions));
146
+ keys = keys.concat(Object.keys(demandedCommands));
147
+ keys = keys.concat(Object.keys(options.default));
148
+ keys = keys.filter(filterHiddenOptions);
149
+ keys = Object.keys(keys.reduce((acc, key) => {
150
+ if (key !== '_')
151
+ acc[key] = true;
152
+ return acc;
153
+ }, {}));
154
+ const theWrap = self.getWrap();
155
+ const ui = shim.cliui({ width: theWrap, wrap: !!theWrap });
156
+ if (!usageDisabled) {
157
+ if (usages.length) {
158
+ usages.forEach((u) => {
159
+ ui.div({ text: `${u[0].replace(/\$0/g, base$0)}`, padding: [0, 0, 0, 0] });
160
+ if (u[1])
161
+ ui.div({ text: `${u[1]}`, padding: [1, 0, 0, 0] });
162
+ });
163
+ ui.div();
164
+ }
165
+ else if (commands.length) {
166
+ let u;
167
+ if (demandedCommands._)
168
+ u = `${base$0} <${__('command')}>\n`;
169
+ else
170
+ u = `${base$0} [${__('command')}]\n`;
171
+ ui.div(`${u}`);
172
+ }
173
+ }
174
+ if (commands.length > 1 || (commands.length === 1 && !commands[0][2])) {
175
+ ui.div(__('Commands:'));
176
+ const context = yargs.getInternalMethods().getContext();
177
+ const parentCommands = context.commands.length ? `${context.commands.join(' ')} ` : '';
178
+ if (yargs.getInternalMethods().getParserConfiguration()['sort-commands'] === true) {
179
+ commands = commands.sort((a, b) => a[0].localeCompare(b[0]));
180
+ }
181
+ const prefix = base$0 ? `${base$0} ` : '';
182
+ commands.forEach((command) => {
183
+ const commandString = `${prefix}${parentCommands}${command[0].replace(/^\$0 ?/, '')}`;
184
+ ui.span({ text: commandString, padding: [0, 2, 0, 2], width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4 }, { text: command[1], padding: [0, 0, 0, 0] });
185
+ const hints = [];
186
+ if (command[2])
187
+ hints.push(`[${__('default')}]`);
188
+ if (command[3] && command[3].length)
189
+ hints.push(`[${__('aliases:')} ${command[3].join(', ')}]`);
190
+ if (command[4]) {
191
+ if (typeof command[4] === 'string')
192
+ hints.push(`[${__('deprecated: %s', command[4])}]`);
193
+ else
194
+ hints.push(`[${__('deprecated')}]`);
195
+ }
196
+ if (hints.length)
197
+ ui.div({ text: hints.join(' '), padding: [0, 0, 0, 2], align: 'right' });
198
+ else
199
+ ui.div();
200
+ });
201
+ ui.div();
202
+ }
203
+ const aliasKeys = (Object.keys(options.alias) || []).concat(Object.keys(yargs.parsed.newAliases) || []);
204
+ keys = keys.filter((key) => !yargs.parsed.newAliases[key] && aliasKeys.every((alias) => (options.alias[alias] || []).indexOf(key) === -1));
205
+ const defaultGroup = __('Options:');
206
+ if (!groups[defaultGroup])
207
+ groups[defaultGroup] = [];
208
+ addUngroupedKeys(keys, options.alias, groups, defaultGroup);
209
+ const isLongSwitch = (sw) => /^--/.test(getText(sw));
210
+ const displayedGroups = Object.keys(groups)
211
+ .filter((groupName) => groups[groupName].length > 0)
212
+ .map((groupName) => {
213
+ const normalizedKeys = groups[groupName].filter(filterHiddenOptions).map((key) => {
214
+ if (aliasKeys.includes(key))
215
+ return key;
216
+ for (let i = 0, aliasKey; (aliasKey = aliasKeys[i]) !== undefined; i++) {
217
+ if ((options.alias[aliasKey] || []).includes(key))
218
+ return aliasKey;
219
+ }
220
+ return key;
221
+ });
222
+ return { groupName, normalizedKeys };
223
+ })
224
+ .filter(({ normalizedKeys }) => normalizedKeys.length > 0)
225
+ .map(({ groupName, normalizedKeys }) => {
226
+ const switches = normalizedKeys.reduce((acc, key) => {
227
+ acc[key] = [key]
228
+ .concat(options.alias[key] || [])
229
+ .map((sw) => {
230
+ if (groupName === self.getPositionalGroupName())
231
+ return sw;
232
+ return (/^[0-9]$/.test(sw) ? (options.boolean.includes(key) ? '-' : '--') : sw.length > 1 ? '--' : '-') + sw;
233
+ })
234
+ .sort((sw1, sw2) => (isLongSwitch(sw1) === isLongSwitch(sw2) ? 0 : isLongSwitch(sw1) ? 1 : -1))
235
+ .join(', ');
236
+ return acc;
237
+ }, {});
238
+ return { groupName, normalizedKeys, switches };
239
+ });
240
+ const shortSwitchesUsed = displayedGroups
241
+ .filter(({ groupName }) => groupName !== self.getPositionalGroupName())
242
+ .some(({ normalizedKeys, switches }) => !normalizedKeys.every((key) => isLongSwitch(switches[key])));
243
+ if (shortSwitchesUsed) {
244
+ displayedGroups
245
+ .filter(({ groupName }) => groupName !== self.getPositionalGroupName())
246
+ .forEach(({ normalizedKeys, switches }) => {
247
+ normalizedKeys.forEach((key) => {
248
+ if (isLongSwitch(switches[key]))
249
+ switches[key] = addIndentation(switches[key], '-x, '.length);
250
+ });
251
+ });
252
+ }
253
+ displayedGroups.forEach(({ groupName, normalizedKeys, switches }) => {
254
+ ui.div(groupName);
255
+ normalizedKeys.forEach((key) => {
256
+ const kswitch = switches[key];
257
+ let desc = descriptions[key] || '';
258
+ let type = null;
259
+ if (desc.includes(deferY18nLookupPrefix))
260
+ desc = __(desc.substring(deferY18nLookupPrefix.length));
261
+ if (options.boolean.includes(key))
262
+ type = `[${__('boolean')}]`;
263
+ if (options.count.includes(key))
264
+ type = `[${__('count')}]`;
265
+ if (options.string.includes(key))
266
+ type = `[${__('string')}]`;
267
+ if (options.normalize.includes(key))
268
+ type = `[${__('string')}]`;
269
+ if (options.array.includes(key))
270
+ type = `[${__('array')}]`;
271
+ if (options.number.includes(key))
272
+ type = `[${__('number')}]`;
273
+ const deprecatedExtra = (deprecated) => typeof deprecated === 'string' ? `[${__('deprecated: %s', deprecated)}]` : `[${__('deprecated')}]`;
274
+ const extra = [
275
+ key in deprecatedOptions ? deprecatedExtra(deprecatedOptions[key]) : null,
276
+ type,
277
+ key in demandedOptions ? `[${__('required')}]` : null,
278
+ options.choices && options.choices[key] ? `[${__('choices:')} ${self.stringifiedValues(options.choices[key])}]` : null,
279
+ defaultString(options.default[key], options.defaultDescription[key]),
280
+ ]
281
+ .filter(Boolean)
282
+ .join(' ');
283
+ ui.span({ text: getText(kswitch), padding: [0, 2, 0, 2 + getIndentation(kswitch)], width: maxWidth(switches, theWrap) + 4 }, desc);
284
+ const shouldHideOptionExtras = yargs.getInternalMethods().getUsageConfiguration()['hide-types'] === true;
285
+ if (extra && !shouldHideOptionExtras)
286
+ ui.div({ text: extra, padding: [0, 0, 0, 2], align: 'right' });
287
+ else
288
+ ui.div();
289
+ });
290
+ ui.div();
291
+ });
292
+ if (examples.length) {
293
+ ui.div(__('Examples:'));
294
+ examples.forEach((example) => {
295
+ example[0] = example[0].replace(/\$0/g, base$0);
296
+ });
297
+ examples.forEach((example) => {
298
+ if (example[1] === '')
299
+ ui.div({ text: example[0], padding: [0, 2, 0, 2] });
300
+ else
301
+ ui.div({ text: example[0], padding: [0, 2, 0, 2], width: maxWidth(examples, theWrap) + 4 }, { text: example[1], padding: [0, 0, 0, 0] });
302
+ });
303
+ ui.div();
304
+ }
305
+ if (epilogs.length > 0) {
306
+ const e = epilogs.map((epilog) => epilog.replace(/\$0/g, base$0)).join('\n');
307
+ ui.div(`${e}\n`);
308
+ }
309
+ return ui.toString().replace(/\s*$/, '');
310
+ };
311
+ function maxWidth(table, theWrap, modifier) {
312
+ let width = 0;
313
+ let rows;
314
+ if (!Array.isArray(table))
315
+ rows = Object.values(table).map((v) => [v]);
316
+ else
317
+ rows = table;
318
+ rows.forEach((v) => {
319
+ width = Math.max(shim.stringWidth(modifier ? `${modifier} ${getText(v[0])}` : getText(v[0])) + getIndentation(v[0]), width);
320
+ });
321
+ if (theWrap)
322
+ width = Math.min(width, parseInt((theWrap * 0.5).toString(), 10));
323
+ return width;
324
+ }
325
+ function normalizeAliases() {
326
+ const demandedOptions = yargs.getDemandedOptions();
327
+ const options = yargs.getOptions();
328
+ (Object.keys(options.alias) || []).forEach((key) => {
329
+ options.alias[key].forEach((alias) => {
330
+ if (descriptions[alias])
331
+ self.describe(key, descriptions[alias]);
332
+ if (alias in demandedOptions)
333
+ yargs.demandOption(key, demandedOptions[alias]);
334
+ if (options.boolean.includes(alias))
335
+ yargs.boolean(key);
336
+ if (options.count.includes(alias))
337
+ yargs.count(key);
338
+ if (options.string.includes(alias))
339
+ yargs.string(key);
340
+ if (options.normalize.includes(alias))
341
+ yargs.normalize(key);
342
+ if (options.array.includes(alias))
343
+ yargs.array(key);
344
+ if (options.number.includes(alias))
345
+ yargs.number(key);
346
+ });
347
+ });
348
+ }
349
+ let cachedHelpMessage;
350
+ self.cacheHelpMessage = function () {
351
+ cachedHelpMessage = this.help();
352
+ };
353
+ self.clearCachedHelpMessage = function () {
354
+ cachedHelpMessage = undefined;
355
+ };
356
+ self.hasCachedHelpMessage = function () {
357
+ return !!cachedHelpMessage;
358
+ };
359
+ function addUngroupedKeys(keys, aliases, groups, defaultGroup) {
360
+ let groupedKeys = [];
361
+ let toCheck = null;
362
+ Object.keys(groups).forEach((group) => {
363
+ groupedKeys = groupedKeys.concat(groups[group]);
364
+ });
365
+ keys.forEach((key) => {
366
+ toCheck = [key].concat(aliases[key]);
367
+ if (!toCheck.some((k) => groupedKeys.indexOf(k) !== -1))
368
+ groups[defaultGroup].push(key);
369
+ });
370
+ return groupedKeys;
371
+ }
372
+ function filterHiddenOptions(key) {
373
+ return yargs.getOptions().hiddenOptions.indexOf(key) < 0 || yargs.parsed.argv[yargs.getOptions().showHiddenOpt];
374
+ }
375
+ self.showHelp = (level) => {
376
+ const logger = yargs.getInternalMethods().getLoggerInstance();
377
+ if (!level)
378
+ level = 'error';
379
+ const emit = typeof level === 'function' ? level : logger[level];
380
+ emit(self.help());
381
+ };
382
+ self.functionDescription = (fn) => {
383
+ const description = fn.name ? shim.Parser.decamelize(fn.name, '-') : __('generated-value');
384
+ return ['(', description, ')'].join('');
385
+ };
386
+ self.stringifiedValues = function stringifiedValues(values, separator) {
387
+ let string = '';
388
+ const sep = separator || ', ';
389
+ const array = [].concat(values);
390
+ if (!values || !array.length)
391
+ return string;
392
+ array.forEach((value) => {
393
+ if (string.length)
394
+ string += sep;
395
+ string += JSON.stringify(value);
396
+ });
397
+ return string;
398
+ };
399
+ function defaultString(value, defaultDescription) {
400
+ let string = `[${__('default:')} `;
401
+ if (value === undefined && !defaultDescription)
402
+ return null;
403
+ if (defaultDescription)
404
+ string += defaultDescription;
405
+ else {
406
+ switch (typeof value) {
407
+ case 'string':
408
+ string += `"${value}"`;
409
+ break;
410
+ case 'object':
411
+ string += JSON.stringify(value);
412
+ break;
413
+ default:
414
+ string += value;
415
+ }
416
+ }
417
+ return `${string}]`;
418
+ }
419
+ function windowWidth() {
420
+ const max = 80;
421
+ if (shim.process.stdColumns)
422
+ return Math.min(max, shim.process.stdColumns);
423
+ return max;
424
+ }
425
+ let version = null;
426
+ self.version = (ver) => {
427
+ version = ver;
428
+ };
429
+ self.getVersion = () => version;
430
+ self.showVersion = (level) => {
431
+ const logger = yargs.getInternalMethods().getLoggerInstance();
432
+ if (!level)
433
+ level = 'error';
434
+ const emit = typeof level === 'function' ? level : logger[level];
435
+ emit(version);
436
+ };
437
+ self.reset = function reset(localLookup) {
438
+ failMessage = null;
439
+ failureOutput = false;
440
+ usages = [];
441
+ usageDisabled = false;
442
+ epilogs = [];
443
+ examples = [];
444
+ commands = [];
445
+ descriptions = objFilter(descriptions, (k) => !localLookup[k]);
446
+ return self;
447
+ };
448
+ const frozens = [];
449
+ self.freeze = function freeze() {
450
+ frozens.push({ failMessage, failureOutput, usages, usageDisabled, epilogs, examples, commands, descriptions });
451
+ };
452
+ self.unfreeze = function unfreeze(defaultCommand = false) {
453
+ const frozen = frozens.pop();
454
+ if (!frozen)
455
+ return;
456
+ if (defaultCommand) {
457
+ descriptions = { ...frozen.descriptions, ...descriptions };
458
+ commands = [...frozen.commands, ...commands];
459
+ usages = [...frozen.usages, ...usages];
460
+ examples = [...frozen.examples, ...examples];
461
+ epilogs = [...frozen.epilogs, ...epilogs];
462
+ }
463
+ else
464
+ ({ failMessage, failureOutput, usages, usageDisabled, epilogs, examples, commands, descriptions } = frozen);
465
+ };
466
+ return self;
467
+ }
468
+ function isIndentedText(text) {
469
+ return typeof text === 'object';
470
+ }
471
+ function addIndentation(text, indent) {
472
+ return isIndentedText(text) ? { text: text.text, indentation: text.indentation + indent } : { text, indentation: indent };
473
+ }
474
+ function getIndentation(text) {
475
+ return isIndentedText(text) ? text.indentation : 0;
476
+ }
477
+ function getText(text) {
478
+ return isIndentedText(text) ? text.text : text;
479
+ }