burgee 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -1
- package/dist/agent.d.ts +19 -0
- package/dist/agent.js +25 -0
- package/dist/brand.d.ts +186 -0
- package/dist/brand.js +232 -0
- package/dist/cli.d.ts +51 -0
- package/dist/cli.js +105 -0
- package/dist/commander-argument.d.ts +22 -0
- package/dist/commander-argument.js +72 -0
- package/dist/commander-command.d.ts +345 -0
- package/dist/commander-command.js +1605 -0
- package/dist/commander-error.d.ts +10 -0
- package/dist/commander-error.js +20 -0
- package/dist/commander-help.d.ts +67 -0
- package/dist/commander-help.js +319 -0
- package/dist/commander-option.d.ts +58 -0
- package/dist/commander-option.js +164 -0
- package/dist/commander-suggest.d.ts +2 -0
- package/dist/commander-suggest.js +59 -0
- package/dist/commander.d.ts +18 -0
- package/dist/commander.js +12 -0
- package/dist/completions.d.ts +39 -0
- package/dist/completions.js +224 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.js +98 -0
- package/dist/contrast.d.ts +70 -0
- package/dist/contrast.js +93 -0
- package/dist/execute.d.ts +97 -0
- package/dist/execute.js +433 -0
- package/dist/exit-code.d.ts +18 -0
- package/dist/exit-code.js +12 -0
- package/dist/help.d.ts +22 -0
- package/dist/help.js +158 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.js +9 -2
- package/dist/manifest.d.ts +192 -0
- package/dist/manifest.js +55 -0
- package/dist/mcp.d.ts +40 -0
- package/dist/mcp.js +111 -0
- package/dist/names.d.ts +5 -0
- package/dist/names.js +6 -0
- package/dist/pkg.d.ts +5 -0
- package/dist/pkg.js +21 -0
- package/dist/precedence.d.ts +55 -0
- package/dist/precedence.js +100 -0
- package/dist/runtime.d.ts +27 -0
- package/dist/runtime.js +17 -0
- package/dist/schema.d.ts +71 -0
- package/dist/schema.js +108 -0
- package/dist/testing-helpers.d.ts +62 -0
- package/dist/testing-helpers.js +110 -0
- package/dist/testing.d.ts +10 -0
- package/dist/testing.js +3 -0
- package/dist/validate.d.ts +27 -0
- package/dist/validate.js +133 -0
- package/dist/yargs-burgee.d.ts +50 -0
- package/dist/yargs-burgee.js +104 -0
- package/dist/yargs-cliui.d.ts +56 -0
- package/dist/yargs-cliui.js +421 -0
- package/dist/yargs-command.d.ts +82 -0
- package/dist/yargs-command.js +414 -0
- package/dist/yargs-completion.d.ts +41 -0
- package/dist/yargs-completion.js +271 -0
- package/dist/yargs-factory.d.ts +193 -0
- package/dist/yargs-factory.js +1606 -0
- package/dist/yargs-helpers.d.ts +6 -0
- package/dist/yargs-helpers.js +2 -0
- package/dist/yargs-middleware.d.ts +32 -0
- package/dist/yargs-middleware.js +81 -0
- package/dist/yargs-parser.d.ts +41 -0
- package/dist/yargs-parser.js +929 -0
- package/dist/yargs-shim.d.ts +54 -0
- package/dist/yargs-shim.js +84 -0
- package/dist/yargs-usage.d.ts +42 -0
- package/dist/yargs-usage.js +479 -0
- package/dist/yargs-utils.d.ts +33 -0
- package/dist/yargs-utils.js +209 -0
- package/dist/yargs-validation.d.ts +26 -0
- package/dist/yargs-validation.js +261 -0
- package/dist/yargs-y18n.d.ts +21 -0
- package/dist/yargs-y18n.js +117 -0
- package/dist/yargs.d.ts +6 -0
- package/dist/yargs.js +8 -0
- package/locales/be.json +46 -0
- package/locales/cs.json +51 -0
- package/locales/de.json +46 -0
- package/locales/en.json +55 -0
- package/locales/es.json +46 -0
- package/locales/fi.json +49 -0
- package/locales/fr.json +53 -0
- package/locales/he.json +55 -0
- package/locales/hi.json +49 -0
- package/locales/hu.json +46 -0
- package/locales/id.json +50 -0
- package/locales/it.json +46 -0
- package/locales/ja.json +51 -0
- package/locales/ka.json +55 -0
- package/locales/ko.json +49 -0
- package/locales/nb.json +44 -0
- package/locales/nl.json +49 -0
- package/locales/nn.json +44 -0
- package/locales/pirate.json +13 -0
- package/locales/pl.json +49 -0
- package/locales/pt.json +45 -0
- package/locales/pt_BR.json +48 -0
- package/locales/ru.json +51 -0
- package/locales/th.json +46 -0
- package/locales/tr.json +48 -0
- package/locales/uk_UA.json +51 -0
- package/locales/uz.json +52 -0
- package/locales/zh_CN.json +48 -0
- package/locales/zh_TW.json +51 -0
- package/package.json +61 -8
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* yargs' small internal modules — yerror, parse-command, argsert, obj-filter, is-promise,
|
|
3
|
+
* levenshtein, maybe-async-result, set-blocking, apply-extends, process-argv — ported
|
|
4
|
+
* for `burgee/yargs`. Its suite imports four of these by their upstream file paths; the
|
|
5
|
+
* oracle shims those paths to this entry, so the names here are the upstream names.
|
|
6
|
+
*/
|
|
7
|
+
export declare class YError extends Error {
|
|
8
|
+
constructor(msg?: string | null);
|
|
9
|
+
}
|
|
10
|
+
export interface Positional {
|
|
11
|
+
cmd: string[];
|
|
12
|
+
variadic: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ParsedCommand {
|
|
15
|
+
cmd: string;
|
|
16
|
+
demanded: Positional[];
|
|
17
|
+
optional: Positional[];
|
|
18
|
+
}
|
|
19
|
+
export declare function parseCommand(cmd: string): ParsedCommand;
|
|
20
|
+
export declare function argsert(arg1: string | any[], arg2?: any, arg3?: number): void;
|
|
21
|
+
export declare function objFilter<T extends object>(original?: T, filter?: (k: string, v: any) => boolean): T;
|
|
22
|
+
export declare function isPromise(maybePromise: any): maybePromise is Promise<any>;
|
|
23
|
+
export declare function levenshtein(a: string, b: string): number;
|
|
24
|
+
export declare function maybeAsyncResult<T>(getResult: (() => T | Promise<T>) | T | Promise<T>, resultHandler: (result: T) => any, errorHandler?: (err: Error) => any): any;
|
|
25
|
+
export declare function setBlocking(blocking: boolean): void;
|
|
26
|
+
export declare function hideBin(argv: string[]): string[];
|
|
27
|
+
export declare function getProcessArgvBin(): string;
|
|
28
|
+
/**
|
|
29
|
+
* `extends` in a config object. The upstream resolves a bare specifier with
|
|
30
|
+
* `import.meta.resolve` and then loads it through `require`; both are done from here.
|
|
31
|
+
*/
|
|
32
|
+
export declare function applyExtends(config: Record<string, any>, cwd: string, mergeExtends?: boolean): Record<string, any>;
|
|
33
|
+
export declare function objectKeys<T extends object>(object: T): (keyof T)[];
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
export class YError extends Error {
|
|
5
|
+
constructor(msg) {
|
|
6
|
+
super(msg || 'yargs error');
|
|
7
|
+
this.name = 'YError';
|
|
8
|
+
if (Error.captureStackTrace)
|
|
9
|
+
Error.captureStackTrace(this, YError);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function parseCommand(cmd) {
|
|
13
|
+
const extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' ');
|
|
14
|
+
const splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/);
|
|
15
|
+
const bregex = /\.*[\][<>]/g;
|
|
16
|
+
const firstCommand = splitCommand.shift();
|
|
17
|
+
if (!firstCommand)
|
|
18
|
+
throw new Error(`No command found in: ${cmd}`);
|
|
19
|
+
const parsedCommand = { cmd: firstCommand.replace(bregex, ''), demanded: [], optional: [] };
|
|
20
|
+
splitCommand.forEach((c, i) => {
|
|
21
|
+
let variadic = false;
|
|
22
|
+
c = c.replace(/\s/g, '');
|
|
23
|
+
if (/\.+[\]>]/.test(c) && i === splitCommand.length - 1)
|
|
24
|
+
variadic = true;
|
|
25
|
+
if (/^\[/.test(c))
|
|
26
|
+
parsedCommand.optional.push({ cmd: c.replace(bregex, '').split('|'), variadic });
|
|
27
|
+
else
|
|
28
|
+
parsedCommand.demanded.push({ cmd: c.replace(bregex, '').split('|'), variadic });
|
|
29
|
+
});
|
|
30
|
+
return parsedCommand;
|
|
31
|
+
}
|
|
32
|
+
const positionName = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth'];
|
|
33
|
+
export function argsert(arg1, arg2, arg3) {
|
|
34
|
+
function parseArgs() {
|
|
35
|
+
return typeof arg1 === 'object' ? [{ cmd: '', demanded: [], optional: [] }, arg1, arg2] : [parseCommand(`cmd ${arg1}`), arg2, arg3];
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
let position = 0;
|
|
39
|
+
const [parsed, callerArguments, _length] = parseArgs();
|
|
40
|
+
const args = [].slice.call(callerArguments);
|
|
41
|
+
while (args.length && args.at(-1) === undefined)
|
|
42
|
+
args.pop();
|
|
43
|
+
const length = _length || args.length;
|
|
44
|
+
if (length < parsed.demanded.length) {
|
|
45
|
+
throw new YError(`Not enough arguments provided. Expected ${parsed.demanded.length} but received ${args.length}.`);
|
|
46
|
+
}
|
|
47
|
+
const totalCommands = parsed.demanded.length + parsed.optional.length;
|
|
48
|
+
if (length > totalCommands) {
|
|
49
|
+
throw new YError(`Too many arguments provided. Expected max ${totalCommands} but received ${length}.`);
|
|
50
|
+
}
|
|
51
|
+
parsed.demanded.forEach((demanded) => {
|
|
52
|
+
const arg = args.shift();
|
|
53
|
+
const observedType = guessType(arg);
|
|
54
|
+
const matchingTypes = demanded.cmd.filter((type) => type === observedType || type === '*');
|
|
55
|
+
if (matchingTypes.length === 0)
|
|
56
|
+
argumentTypeError(observedType, demanded.cmd, position);
|
|
57
|
+
position += 1;
|
|
58
|
+
});
|
|
59
|
+
parsed.optional.forEach((optional) => {
|
|
60
|
+
if (args.length === 0)
|
|
61
|
+
return;
|
|
62
|
+
const arg = args.shift();
|
|
63
|
+
const observedType = guessType(arg);
|
|
64
|
+
const matchingTypes = optional.cmd.filter((type) => type === observedType || type === '*');
|
|
65
|
+
if (matchingTypes.length === 0)
|
|
66
|
+
argumentTypeError(observedType, optional.cmd, position);
|
|
67
|
+
position += 1;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
console.warn(err.stack);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function guessType(arg) {
|
|
75
|
+
if (Array.isArray(arg))
|
|
76
|
+
return 'array';
|
|
77
|
+
if (arg === null)
|
|
78
|
+
return 'null';
|
|
79
|
+
return typeof arg;
|
|
80
|
+
}
|
|
81
|
+
function argumentTypeError(observedType, allowedTypes, position) {
|
|
82
|
+
throw new YError(`Invalid ${positionName[position] || 'manyith'} argument. Expected ${allowedTypes.join(' or ')} but received ${observedType}.`);
|
|
83
|
+
}
|
|
84
|
+
export function objFilter(original = {}, filter = () => true) {
|
|
85
|
+
const obj = {};
|
|
86
|
+
Object.keys(original).forEach((key) => {
|
|
87
|
+
if (filter(key, original[key]))
|
|
88
|
+
obj[key] = original[key];
|
|
89
|
+
});
|
|
90
|
+
return obj;
|
|
91
|
+
}
|
|
92
|
+
export function isPromise(maybePromise) {
|
|
93
|
+
return !!maybePromise && !!maybePromise.then && typeof maybePromise.then === 'function';
|
|
94
|
+
}
|
|
95
|
+
export function levenshtein(a, b) {
|
|
96
|
+
if (a.length === 0)
|
|
97
|
+
return b.length;
|
|
98
|
+
if (b.length === 0)
|
|
99
|
+
return a.length;
|
|
100
|
+
const matrix = [];
|
|
101
|
+
let i;
|
|
102
|
+
for (i = 0; i <= b.length; i++)
|
|
103
|
+
matrix[i] = [i];
|
|
104
|
+
let j;
|
|
105
|
+
for (j = 0; j <= a.length; j++)
|
|
106
|
+
matrix[0][j] = j;
|
|
107
|
+
for (i = 1; i <= b.length; i++) {
|
|
108
|
+
for (j = 1; j <= a.length; j++) {
|
|
109
|
+
const row = matrix[i];
|
|
110
|
+
const prev = matrix[i - 1];
|
|
111
|
+
if (b.charAt(i - 1) === a.charAt(j - 1))
|
|
112
|
+
row[j] = prev[j - 1];
|
|
113
|
+
else if (i > 1 && j > 1 && b.charAt(i - 2) === a.charAt(j - 1) && b.charAt(i - 1) === a.charAt(j - 2)) {
|
|
114
|
+
row[j] = matrix[i - 2][j - 2] + 1;
|
|
115
|
+
}
|
|
116
|
+
else
|
|
117
|
+
row[j] = Math.min(prev[j - 1] + 1, Math.min(row[j - 1] + 1, prev[j] + 1));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return matrix[b.length][a.length];
|
|
121
|
+
}
|
|
122
|
+
export function maybeAsyncResult(getResult, resultHandler, errorHandler = (err) => {
|
|
123
|
+
throw err;
|
|
124
|
+
}) {
|
|
125
|
+
try {
|
|
126
|
+
const result = typeof getResult === 'function' ? getResult() : getResult;
|
|
127
|
+
return isPromise(result) ? result.then((r) => resultHandler(r)) : resultHandler(result);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
return errorHandler(err);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export function setBlocking(blocking) {
|
|
134
|
+
if (typeof process === 'undefined')
|
|
135
|
+
return;
|
|
136
|
+
[process.stdout, process.stderr].forEach((_stream) => {
|
|
137
|
+
const stream = _stream;
|
|
138
|
+
if (stream._handle && stream.isTTY && typeof stream._handle.setBlocking === 'function')
|
|
139
|
+
stream._handle.setBlocking(blocking);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function getProcessArgvBinIndex() {
|
|
143
|
+
if (isBundledElectronApp())
|
|
144
|
+
return 0;
|
|
145
|
+
return 1;
|
|
146
|
+
}
|
|
147
|
+
function isBundledElectronApp() {
|
|
148
|
+
return isElectronApp() && !process.defaultApp;
|
|
149
|
+
}
|
|
150
|
+
function isElectronApp() {
|
|
151
|
+
return !!process.versions.electron;
|
|
152
|
+
}
|
|
153
|
+
export function hideBin(argv) {
|
|
154
|
+
return argv.slice(getProcessArgvBinIndex() + 1);
|
|
155
|
+
}
|
|
156
|
+
export function getProcessArgvBin() {
|
|
157
|
+
return process.argv[getProcessArgvBinIndex()];
|
|
158
|
+
}
|
|
159
|
+
const nodeRequire = createRequire(import.meta.url);
|
|
160
|
+
let previouslyVisitedConfigs = [];
|
|
161
|
+
export function applyExtends(config, cwd, mergeExtends) {
|
|
162
|
+
let defaultConfig = {};
|
|
163
|
+
if (Object.prototype.hasOwnProperty.call(config, 'extends')) {
|
|
164
|
+
if (typeof config.extends !== 'string')
|
|
165
|
+
return defaultConfig;
|
|
166
|
+
const isPath = /\.json|\..*rc$/.test(config.extends);
|
|
167
|
+
let pathToDefault;
|
|
168
|
+
if (!isPath) {
|
|
169
|
+
try {
|
|
170
|
+
pathToDefault = import.meta.resolve(config.extends);
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
return config;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else
|
|
177
|
+
pathToDefault = resolve(cwd, config.extends);
|
|
178
|
+
checkForCircularExtends(pathToDefault);
|
|
179
|
+
previouslyVisitedConfigs.push(pathToDefault);
|
|
180
|
+
defaultConfig = isPath ? JSON.parse(readFileSync(pathToDefault, 'utf8')) : nodeRequire(config.extends);
|
|
181
|
+
delete config.extends;
|
|
182
|
+
defaultConfig = applyExtends(defaultConfig, dirname(pathToDefault), mergeExtends);
|
|
183
|
+
}
|
|
184
|
+
previouslyVisitedConfigs = [];
|
|
185
|
+
return mergeExtends ? mergeDeep(defaultConfig, config) : Object.assign({}, defaultConfig, config);
|
|
186
|
+
}
|
|
187
|
+
function checkForCircularExtends(cfgPath) {
|
|
188
|
+
if (previouslyVisitedConfigs.indexOf(cfgPath) > -1)
|
|
189
|
+
throw new YError(`Circular extended configurations: '${cfgPath}'.`);
|
|
190
|
+
}
|
|
191
|
+
function mergeDeep(config1, config2) {
|
|
192
|
+
const target = {};
|
|
193
|
+
function isObject(obj) {
|
|
194
|
+
return obj && typeof obj === 'object' && !Array.isArray(obj);
|
|
195
|
+
}
|
|
196
|
+
Object.assign(target, config1);
|
|
197
|
+
for (const key of Object.keys(config2)) {
|
|
198
|
+
if (key === '__proto__')
|
|
199
|
+
continue;
|
|
200
|
+
if (isObject(config2[key]) && isObject(target[key]))
|
|
201
|
+
target[key] = mergeDeep(config1[key], config2[key]);
|
|
202
|
+
else
|
|
203
|
+
target[key] = config2[key];
|
|
204
|
+
}
|
|
205
|
+
return target;
|
|
206
|
+
}
|
|
207
|
+
export function objectKeys(object) {
|
|
208
|
+
return Object.keys(object);
|
|
209
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* yargs' validation — demanded options and commands, unknown arguments under strict
|
|
3
|
+
* modes, choices, implications, conflicts, and `recommendCommands` — ported for
|
|
4
|
+
* `burgee/yargs`. Every message is the upstream's through y18n.
|
|
5
|
+
*/
|
|
6
|
+
import type { PlatformShim } from './yargs-shim.js';
|
|
7
|
+
export interface ValidationInstance {
|
|
8
|
+
nonOptionCount: (argv: any) => void;
|
|
9
|
+
positionalCount: (required: number, observed: number) => void;
|
|
10
|
+
requiredArguments: (argv: any, demandedOptions: Record<string, string | undefined>) => void;
|
|
11
|
+
unknownArguments: (argv: any, aliases: Record<string, string[]>, positionalMap: any, isDefaultCommand: boolean, checkPositionals?: boolean) => void;
|
|
12
|
+
unknownCommands: (argv: any) => boolean;
|
|
13
|
+
isValidAndSomeAliasIsNotNew: (key: string, aliases: Record<string, string[]>) => boolean;
|
|
14
|
+
limitedChoices: (argv: any) => void;
|
|
15
|
+
implies: (key: string | Record<string, any>, value?: any) => void;
|
|
16
|
+
getImplied: () => Record<string, any[]>;
|
|
17
|
+
implications: (argv: any) => void;
|
|
18
|
+
conflicts: (key: string | Record<string, any>, value?: any) => void;
|
|
19
|
+
getConflicting: () => Record<string, any[]>;
|
|
20
|
+
conflicting: (argv: any) => void;
|
|
21
|
+
recommendCommands: (cmd: string, potentialCommands: string[]) => void;
|
|
22
|
+
reset: (localLookup: Record<string, boolean>) => ValidationInstance;
|
|
23
|
+
freeze: () => void;
|
|
24
|
+
unfreeze: () => void;
|
|
25
|
+
}
|
|
26
|
+
export declare function validation(yargs: any, usage: any, shim: PlatformShim): ValidationInstance;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { argsert, levenshtein as distance, objFilter } from './yargs-utils.js';
|
|
2
|
+
const specialKeys = ['$0', '--', '_'];
|
|
3
|
+
export function validation(yargs, usage, shim) {
|
|
4
|
+
const __ = shim.y18n.__;
|
|
5
|
+
const __n = shim.y18n.__n;
|
|
6
|
+
const self = {};
|
|
7
|
+
self.nonOptionCount = function nonOptionCount(argv) {
|
|
8
|
+
const demandedCommands = yargs.getDemandedCommands();
|
|
9
|
+
const positionalCount = argv._.length + (argv['--'] ? argv['--'].length : 0);
|
|
10
|
+
const _s = positionalCount - yargs.getInternalMethods().getContext().commands.length;
|
|
11
|
+
if (demandedCommands._ && (_s < demandedCommands._.min || _s > demandedCommands._.max)) {
|
|
12
|
+
if (_s < demandedCommands._.min) {
|
|
13
|
+
if (demandedCommands._.minMsg !== undefined) {
|
|
14
|
+
usage.fail(demandedCommands._.minMsg
|
|
15
|
+
? demandedCommands._.minMsg.replace(/\$0/g, _s.toString()).replace(/\$1/, demandedCommands._.min.toString())
|
|
16
|
+
: null);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
usage.fail(__n('Not enough non-option arguments: got %s, need at least %s', 'Not enough non-option arguments: got %s, need at least %s', _s, _s.toString(), demandedCommands._.min.toString()));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else if (_s > demandedCommands._.max) {
|
|
23
|
+
if (demandedCommands._.maxMsg !== undefined) {
|
|
24
|
+
usage.fail(demandedCommands._.maxMsg
|
|
25
|
+
? demandedCommands._.maxMsg.replace(/\$0/g, _s.toString()).replace(/\$1/, demandedCommands._.max.toString())
|
|
26
|
+
: null);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
usage.fail(__n('Too many non-option arguments: got %s, maximum of %s', 'Too many non-option arguments: got %s, maximum of %s', _s, _s.toString(), demandedCommands._.max.toString()));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
self.positionalCount = function positionalCount(required, observed) {
|
|
35
|
+
if (observed < required) {
|
|
36
|
+
usage.fail(__n('Not enough non-option arguments: got %s, need at least %s', 'Not enough non-option arguments: got %s, need at least %s', observed, `${observed}`, `${required}`));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
self.requiredArguments = function requiredArguments(argv, demandedOptions) {
|
|
40
|
+
let missing = null;
|
|
41
|
+
for (const key of Object.keys(demandedOptions)) {
|
|
42
|
+
if (!Object.prototype.hasOwnProperty.call(argv, key) || typeof argv[key] === 'undefined') {
|
|
43
|
+
missing = missing || {};
|
|
44
|
+
missing[key] = demandedOptions[key];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (missing) {
|
|
48
|
+
const customMsgs = [];
|
|
49
|
+
for (const key of Object.keys(missing)) {
|
|
50
|
+
const msg = missing[key];
|
|
51
|
+
if (msg && customMsgs.indexOf(msg) < 0)
|
|
52
|
+
customMsgs.push(msg);
|
|
53
|
+
}
|
|
54
|
+
const customMsg = customMsgs.length ? `\n${customMsgs.join('\n')}` : '';
|
|
55
|
+
usage.fail(__n('Missing required argument: %s', 'Missing required arguments: %s', Object.keys(missing).length, Object.keys(missing).join(', ') + customMsg));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
self.unknownArguments = function unknownArguments(argv, aliases, positionalMap, isDefaultCommand, checkPositionals = true) {
|
|
59
|
+
const commandKeys = yargs.getInternalMethods().getCommandInstance().getCommands();
|
|
60
|
+
const unknown = [];
|
|
61
|
+
const currentContext = yargs.getInternalMethods().getContext();
|
|
62
|
+
Object.keys(argv).forEach((key) => {
|
|
63
|
+
if (!specialKeys.includes(key) &&
|
|
64
|
+
!Object.prototype.hasOwnProperty.call(positionalMap, key) &&
|
|
65
|
+
!Object.prototype.hasOwnProperty.call(yargs.getInternalMethods().getParseContext(), key) &&
|
|
66
|
+
!self.isValidAndSomeAliasIsNotNew(key, aliases)) {
|
|
67
|
+
unknown.push(key);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
if (checkPositionals && (currentContext.commands.length > 0 || commandKeys.length > 0 || isDefaultCommand)) {
|
|
71
|
+
argv._.slice(currentContext.commands.length).forEach((key) => {
|
|
72
|
+
if (!commandKeys.includes(`${key}`))
|
|
73
|
+
unknown.push(`${key}`);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (checkPositionals) {
|
|
77
|
+
const demandedCommands = yargs.getDemandedCommands();
|
|
78
|
+
const maxNonOptDemanded = demandedCommands._?.max || 0;
|
|
79
|
+
const expected = currentContext.commands.length + maxNonOptDemanded;
|
|
80
|
+
if (expected < argv._.length) {
|
|
81
|
+
argv._.slice(expected).forEach((key) => {
|
|
82
|
+
key = String(key);
|
|
83
|
+
if (!currentContext.commands.includes(key) && !unknown.includes(key))
|
|
84
|
+
unknown.push(key);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (unknown.length) {
|
|
89
|
+
usage.fail(__n('Unknown argument: %s', 'Unknown arguments: %s', unknown.length, unknown.map((s) => (s.trim() ? s : `"${s}"`)).join(', ')));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
self.unknownCommands = function unknownCommands(argv) {
|
|
93
|
+
const commandKeys = yargs.getInternalMethods().getCommandInstance().getCommands();
|
|
94
|
+
const unknown = [];
|
|
95
|
+
const currentContext = yargs.getInternalMethods().getContext();
|
|
96
|
+
if (currentContext.commands.length > 0 || commandKeys.length > 0) {
|
|
97
|
+
argv._.slice(currentContext.commands.length).forEach((key) => {
|
|
98
|
+
if (!commandKeys.includes(`${key}`))
|
|
99
|
+
unknown.push(`${key}`);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (unknown.length > 0) {
|
|
103
|
+
usage.fail(__n('Unknown command: %s', 'Unknown commands: %s', unknown.length, unknown.join(', ')));
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
};
|
|
108
|
+
self.isValidAndSomeAliasIsNotNew = function isValidAndSomeAliasIsNotNew(key, aliases) {
|
|
109
|
+
if (!Object.prototype.hasOwnProperty.call(aliases, key))
|
|
110
|
+
return false;
|
|
111
|
+
const newAliases = yargs.parsed.newAliases;
|
|
112
|
+
return [key, ...aliases[key]].some((a) => !Object.prototype.hasOwnProperty.call(newAliases, a) || !newAliases[key]);
|
|
113
|
+
};
|
|
114
|
+
self.limitedChoices = function limitedChoices(argv) {
|
|
115
|
+
const options = yargs.getOptions();
|
|
116
|
+
const invalid = {};
|
|
117
|
+
if (!Object.keys(options.choices).length)
|
|
118
|
+
return;
|
|
119
|
+
Object.keys(argv).forEach((key) => {
|
|
120
|
+
if (specialKeys.indexOf(key) === -1 && Object.prototype.hasOwnProperty.call(options.choices, key)) {
|
|
121
|
+
[].concat(argv[key]).forEach((value) => {
|
|
122
|
+
if (options.choices[key].indexOf(value) === -1 && value !== undefined)
|
|
123
|
+
invalid[key] = (invalid[key] || []).concat(value);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
const invalidKeys = Object.keys(invalid);
|
|
128
|
+
if (!invalidKeys.length)
|
|
129
|
+
return;
|
|
130
|
+
let msg = __('Invalid values:');
|
|
131
|
+
invalidKeys.forEach((key) => {
|
|
132
|
+
msg += `\n ${__('Argument: %s, Given: %s, Choices: %s', key, usage.stringifiedValues(invalid[key]), usage.stringifiedValues(options.choices[key]))}`;
|
|
133
|
+
});
|
|
134
|
+
usage.fail(msg);
|
|
135
|
+
};
|
|
136
|
+
let implied = {};
|
|
137
|
+
self.implies = function implies(key, value) {
|
|
138
|
+
argsert('<string|object> [array|number|string]', [key, value], arguments.length);
|
|
139
|
+
if (typeof key === 'object') {
|
|
140
|
+
Object.keys(key).forEach((k) => {
|
|
141
|
+
self.implies(k, key[k]);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
yargs.global(key);
|
|
146
|
+
if (!implied[key])
|
|
147
|
+
implied[key] = [];
|
|
148
|
+
if (Array.isArray(value))
|
|
149
|
+
value.forEach((i) => self.implies(key, i));
|
|
150
|
+
else {
|
|
151
|
+
shim.assert.notStrictEqual(value, undefined);
|
|
152
|
+
implied[key].push(value);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
self.getImplied = function getImplied() {
|
|
157
|
+
return implied;
|
|
158
|
+
};
|
|
159
|
+
function keyExists(argv, val) {
|
|
160
|
+
const num = Number(val);
|
|
161
|
+
val = isNaN(num) ? val : num;
|
|
162
|
+
if (typeof val === 'number')
|
|
163
|
+
val = argv._.length >= val;
|
|
164
|
+
else if (/^--no-.+/.exec(val)) {
|
|
165
|
+
val = /^--no-(.+)/.exec(val)[1];
|
|
166
|
+
val = !Object.prototype.hasOwnProperty.call(argv, val);
|
|
167
|
+
}
|
|
168
|
+
else
|
|
169
|
+
val = Object.prototype.hasOwnProperty.call(argv, val);
|
|
170
|
+
return val;
|
|
171
|
+
}
|
|
172
|
+
self.implications = function implications(argv) {
|
|
173
|
+
const implyFail = [];
|
|
174
|
+
Object.keys(implied).forEach((key) => {
|
|
175
|
+
const origKey = key;
|
|
176
|
+
(implied[key] || []).forEach((value) => {
|
|
177
|
+
let k = origKey;
|
|
178
|
+
const origValue = value;
|
|
179
|
+
k = keyExists(argv, k);
|
|
180
|
+
value = keyExists(argv, value);
|
|
181
|
+
if (k && !value)
|
|
182
|
+
implyFail.push(` ${origKey} -> ${origValue}`);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
if (implyFail.length) {
|
|
186
|
+
let msg = `${__('Implications failed:')}\n`;
|
|
187
|
+
implyFail.forEach((value) => {
|
|
188
|
+
msg += value;
|
|
189
|
+
});
|
|
190
|
+
usage.fail(msg);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
let conflicting = {};
|
|
194
|
+
self.conflicts = function conflicts(key, value) {
|
|
195
|
+
argsert('<string|object> [array|string]', [key, value], arguments.length);
|
|
196
|
+
if (typeof key === 'object') {
|
|
197
|
+
Object.keys(key).forEach((k) => {
|
|
198
|
+
self.conflicts(k, key[k]);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
yargs.global(key);
|
|
203
|
+
if (!conflicting[key])
|
|
204
|
+
conflicting[key] = [];
|
|
205
|
+
if (Array.isArray(value))
|
|
206
|
+
value.forEach((i) => self.conflicts(key, i));
|
|
207
|
+
else
|
|
208
|
+
conflicting[key].push(value);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
self.getConflicting = () => conflicting;
|
|
212
|
+
self.conflicting = function conflictingFn(argv) {
|
|
213
|
+
Object.keys(argv).forEach((key) => {
|
|
214
|
+
if (conflicting[key]) {
|
|
215
|
+
conflicting[key].forEach((value) => {
|
|
216
|
+
if (value && argv[key] !== undefined && argv[value] !== undefined)
|
|
217
|
+
usage.fail(__('Arguments %s and %s are mutually exclusive', key, value));
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
if (yargs.getInternalMethods().getParserConfiguration()['strip-dashed']) {
|
|
222
|
+
Object.keys(conflicting).forEach((key) => {
|
|
223
|
+
conflicting[key].forEach((value) => {
|
|
224
|
+
if (value && argv[shim.Parser.camelCase(key)] !== undefined && argv[shim.Parser.camelCase(value)] !== undefined) {
|
|
225
|
+
usage.fail(__('Arguments %s and %s are mutually exclusive', key, value));
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
self.recommendCommands = function recommendCommands(cmd, potentialCommands) {
|
|
232
|
+
const threshold = 3;
|
|
233
|
+
potentialCommands = potentialCommands.sort((a, b) => b.length - a.length);
|
|
234
|
+
let recommended = null;
|
|
235
|
+
let bestDistance = Infinity;
|
|
236
|
+
for (let i = 0, candidate; (candidate = potentialCommands[i]) !== undefined; i++) {
|
|
237
|
+
const d = distance(cmd, candidate);
|
|
238
|
+
if (d <= threshold && d < bestDistance) {
|
|
239
|
+
bestDistance = d;
|
|
240
|
+
recommended = candidate;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (recommended)
|
|
244
|
+
usage.fail(__('Did you mean %s?', recommended));
|
|
245
|
+
};
|
|
246
|
+
self.reset = function reset(localLookup) {
|
|
247
|
+
implied = objFilter(implied, (k) => !localLookup[k]);
|
|
248
|
+
conflicting = objFilter(conflicting, (k) => !localLookup[k]);
|
|
249
|
+
return self;
|
|
250
|
+
};
|
|
251
|
+
const frozens = [];
|
|
252
|
+
self.freeze = function freeze() {
|
|
253
|
+
frozens.push({ implied, conflicting });
|
|
254
|
+
};
|
|
255
|
+
self.unfreeze = function unfreeze() {
|
|
256
|
+
const frozen = frozens.pop();
|
|
257
|
+
shim.assert.notStrictEqual(frozen, undefined);
|
|
258
|
+
({ implied, conflicting } = frozen);
|
|
259
|
+
};
|
|
260
|
+
return self;
|
|
261
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* y18n 5 — yargs' string table — ported for `burgee/yargs`. The 29 locales ship with
|
|
3
|
+
* burgee under `locales/`, read on first use of a locale, never written (yargs runs
|
|
4
|
+
* y18n with `updateFiles: false`).
|
|
5
|
+
*/
|
|
6
|
+
export interface Y18N {
|
|
7
|
+
__: (...args: any[]) => string;
|
|
8
|
+
__n: (...args: any[]) => string;
|
|
9
|
+
setLocale: (locale: string) => void;
|
|
10
|
+
getLocale: () => string;
|
|
11
|
+
updateLocale: (obj: Record<string, any>) => void;
|
|
12
|
+
locale: string;
|
|
13
|
+
}
|
|
14
|
+
interface Y18NOptions {
|
|
15
|
+
directory?: string;
|
|
16
|
+
updateFiles?: boolean;
|
|
17
|
+
locale?: string;
|
|
18
|
+
fallbackToLanguage?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function y18n(opts: Y18NOptions): Y18N;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { format } from 'node:util';
|
|
4
|
+
function fileExistsSync(file) {
|
|
5
|
+
try {
|
|
6
|
+
return statSync(file).isFile();
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class Table {
|
|
13
|
+
directory;
|
|
14
|
+
locale;
|
|
15
|
+
fallbackToLanguage;
|
|
16
|
+
cache = Object.create(null);
|
|
17
|
+
constructor(opts) {
|
|
18
|
+
this.directory = opts.directory || './locales';
|
|
19
|
+
this.locale = opts.locale || 'en';
|
|
20
|
+
this.fallbackToLanguage = typeof opts.fallbackToLanguage === 'boolean' ? opts.fallbackToLanguage : true;
|
|
21
|
+
}
|
|
22
|
+
__(...args) {
|
|
23
|
+
if (typeof args[0] !== 'string')
|
|
24
|
+
return this.taggedLiteral(args[0], ...args);
|
|
25
|
+
const str = args.shift();
|
|
26
|
+
let cb = function () { };
|
|
27
|
+
if (typeof args.at(-1) === 'function')
|
|
28
|
+
cb = args.pop();
|
|
29
|
+
if (!this.cache[this.locale])
|
|
30
|
+
this.readLocaleFile();
|
|
31
|
+
cb();
|
|
32
|
+
const table = this.cache[this.locale];
|
|
33
|
+
return format(...[table[str] || str].concat(args));
|
|
34
|
+
}
|
|
35
|
+
__n(...args) {
|
|
36
|
+
const singular = args.shift();
|
|
37
|
+
const plural = args.shift();
|
|
38
|
+
const quantity = args.shift();
|
|
39
|
+
let cb = function () { };
|
|
40
|
+
if (typeof args.at(-1) === 'function')
|
|
41
|
+
cb = args.pop();
|
|
42
|
+
if (!this.cache[this.locale])
|
|
43
|
+
this.readLocaleFile();
|
|
44
|
+
const table = this.cache[this.locale];
|
|
45
|
+
let str = quantity === 1 ? singular : plural;
|
|
46
|
+
if (table[singular]) {
|
|
47
|
+
const entry = table[singular];
|
|
48
|
+
str = entry[quantity === 1 ? 'one' : 'other'];
|
|
49
|
+
}
|
|
50
|
+
cb();
|
|
51
|
+
const values = [str];
|
|
52
|
+
if (~str.indexOf('%d'))
|
|
53
|
+
values.push(quantity);
|
|
54
|
+
return format(...values.concat(args));
|
|
55
|
+
}
|
|
56
|
+
setLocale(locale) {
|
|
57
|
+
this.locale = locale;
|
|
58
|
+
}
|
|
59
|
+
getLocale() {
|
|
60
|
+
return this.locale;
|
|
61
|
+
}
|
|
62
|
+
updateLocale(obj) {
|
|
63
|
+
if (!this.cache[this.locale])
|
|
64
|
+
this.readLocaleFile();
|
|
65
|
+
const table = this.cache[this.locale];
|
|
66
|
+
for (const key in obj) {
|
|
67
|
+
if (Object.prototype.hasOwnProperty.call(obj, key))
|
|
68
|
+
table[key] = obj[key];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
taggedLiteral(parts, ...args) {
|
|
72
|
+
let str = '';
|
|
73
|
+
parts.forEach((part, i) => {
|
|
74
|
+
const arg = args[i + 1];
|
|
75
|
+
str += part;
|
|
76
|
+
if (typeof arg !== 'undefined')
|
|
77
|
+
str += '%s';
|
|
78
|
+
});
|
|
79
|
+
return this.__(...[str].concat([].slice.call(args, 1)));
|
|
80
|
+
}
|
|
81
|
+
readLocaleFile() {
|
|
82
|
+
let localeLookup = {};
|
|
83
|
+
const languageFile = this.resolveLocaleFile(this.directory, this.locale);
|
|
84
|
+
try {
|
|
85
|
+
localeLookup = JSON.parse(readFileSync(languageFile, 'utf-8'));
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
if (err instanceof SyntaxError)
|
|
89
|
+
err.message = `syntax error in ${languageFile}`;
|
|
90
|
+
if (err.code === 'ENOENT')
|
|
91
|
+
localeLookup = {};
|
|
92
|
+
else
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
this.cache[this.locale] = localeLookup;
|
|
96
|
+
}
|
|
97
|
+
resolveLocaleFile(directory, locale) {
|
|
98
|
+
let file = resolve(directory, './', `${locale}.json`);
|
|
99
|
+
if (this.fallbackToLanguage && !fileExistsSync(file) && ~locale.lastIndexOf('_')) {
|
|
100
|
+
const languageFile = resolve(directory, './', `${locale.split('_')[0]}.json`);
|
|
101
|
+
if (fileExistsSync(languageFile))
|
|
102
|
+
file = languageFile;
|
|
103
|
+
}
|
|
104
|
+
return file;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export function y18n(opts) {
|
|
108
|
+
const table = new Table(opts);
|
|
109
|
+
return {
|
|
110
|
+
__: table.__.bind(table),
|
|
111
|
+
__n: table.__n.bind(table),
|
|
112
|
+
setLocale: table.setLocale.bind(table),
|
|
113
|
+
getLocale: table.getLocale.bind(table),
|
|
114
|
+
updateLocale: table.updateLocale.bind(table),
|
|
115
|
+
locale: table.locale,
|
|
116
|
+
};
|
|
117
|
+
}
|
package/dist/yargs.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { YargsInstance, isYargsInstance, type Options, type ParseCallback } from './yargs-factory.js';
|
|
2
|
+
export { Parser, camelCase, decamelize, looksLikeNumber, type DetailedArguments } from './yargs-parser.js';
|
|
3
|
+
export { applyExtends, argsert, hideBin, isPromise, objFilter, parseCommand, YError, type ParsedCommand } from './yargs-utils.js';
|
|
4
|
+
export { shim as platformShim, type PlatformShim } from './yargs-shim.js';
|
|
5
|
+
declare const Yargs: (processArgs?: string | string[], cwd?: string, parentRequire?: NodeJS.Require) => import("./yargs-factory.js").YargsInstance;
|
|
6
|
+
export default Yargs;
|
package/dist/yargs.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { YargsFactory } from './yargs-factory.js';
|
|
2
|
+
import { shim } from './yargs-shim.js';
|
|
3
|
+
export { YargsInstance, isYargsInstance } from './yargs-factory.js';
|
|
4
|
+
export { Parser, camelCase, decamelize, looksLikeNumber } from './yargs-parser.js';
|
|
5
|
+
export { applyExtends, argsert, hideBin, isPromise, objFilter, parseCommand, YError } from './yargs-utils.js';
|
|
6
|
+
export { shim as platformShim } from './yargs-shim.js';
|
|
7
|
+
const Yargs = YargsFactory(shim);
|
|
8
|
+
export default Yargs;
|