+26
-19
@@ -6,6 +6,5 @@ import { assertNotStrictEqual, } from './typings/common-types.js'; | ||
| import { isYargsInstance, } from './yargs-factory.js'; | ||
| import { maybeAsyncResult } from './utils/maybe-async-result.js'; | ||
| import whichModule from './utils/which-module.js'; | ||
| const DEFAULT_MARKER = /(^\*)|(^\$0)/; | ||
| export function command(yargs, usage, validation, globalMiddleware, shim) { | ||
| export function command(yargs, usage, validation, globalMiddleware = [], shim) { | ||
| const self = {}; | ||
@@ -135,2 +134,4 @@ let handlers = {}; | ||
| const innerYargs = isYargsInstance(builderOutput) ? builderOutput : yargs; | ||
| if (!command) | ||
| innerYargs.getUsageInstance().unfreeze(); | ||
| if (shouldUpdateUsage(innerYargs)) { | ||
@@ -146,2 +147,4 @@ innerYargs | ||
| const innerYargs = yargs.reset(parsed.aliases); | ||
| if (!command) | ||
| innerYargs.getUsageInstance().unfreeze(); | ||
| if (shouldUpdateUsage(innerYargs)) { | ||
@@ -164,3 +167,2 @@ innerYargs | ||
| const middlewares = globalMiddleware | ||
| .getMiddleware() | ||
| .slice(0) | ||
@@ -171,8 +173,11 @@ .concat(commandHandler.middlewares); | ||
| const validation = yargs._runValidation(aliases, positionalMap, yargs.parsed.error, !command); | ||
| innerArgv = maybeAsyncResult(innerArgv, (err) => { | ||
| throw err; | ||
| }, result => { | ||
| validation(result); | ||
| return result; | ||
| }); | ||
| if (isPromise(innerArgv)) { | ||
| innerArgv = innerArgv.then(argv => { | ||
| validation(argv); | ||
| return argv; | ||
| }); | ||
| } | ||
| else { | ||
| validation(innerArgv); | ||
| } | ||
| } | ||
@@ -184,13 +189,15 @@ if (commandHandler.handler && !yargs._hasOutput()) { | ||
| innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false); | ||
| innerArgv = maybeAsyncResult(innerArgv, (err) => { | ||
| throw err; | ||
| }, result => { | ||
| const handlerResult = commandHandler.handler(result); | ||
| if (isPromise(innerArgv)) { | ||
| const innerArgvRef = innerArgv; | ||
| innerArgv = innerArgv | ||
| .then(argv => commandHandler.handler(argv)) | ||
| .then(() => innerArgvRef); | ||
| } | ||
| else { | ||
| const handlerResult = commandHandler.handler(innerArgv); | ||
| if (isPromise(handlerResult)) { | ||
| return handlerResult.then(() => result); | ||
| const innerArgvRef = innerArgv; | ||
| innerArgv = handlerResult.then(() => innerArgvRef); | ||
| } | ||
| else { | ||
| return result; | ||
| } | ||
| }); | ||
| } | ||
| yargs.getUsageInstance().cacheHelpMessage(); | ||
@@ -296,3 +303,3 @@ if (isPromise(innerArgv) && !yargs._hasParseCallback()) { | ||
| const config = Object.assign({}, options.configuration, { | ||
| 'populate--': false, | ||
| 'populate--': true, | ||
| }); | ||
@@ -299,0 +306,0 @@ const parsed = shim.Parser.detailed(unparsed, Object.assign({}, options, { |
@@ -114,3 +114,3 @@ import { isCommandBuilderCallback } from './command.js'; | ||
| else if (isFallbackCompletionFunction(this.customCompletionFunction)) { | ||
| return this.customCompletionFunction(current, argv, () => this.defaultCompletion(args, argv, current, done), completions => { | ||
| return this.customCompletionFunction(current, argv, (onCompleted = done) => this.defaultCompletion(args, argv, current, onCompleted), completions => { | ||
| done(null, completions); | ||
@@ -117,0 +117,0 @@ }); |
| import { argsert } from './argsert.js'; | ||
| import { isPromise } from './utils/is-promise.js'; | ||
| export class GlobalMiddleware { | ||
| constructor(yargs) { | ||
| this.globalMiddleware = []; | ||
| this.frozens = []; | ||
| this.yargs = yargs; | ||
| } | ||
| addMiddleware(callback, applyBeforeValidation, global = true) { | ||
| argsert('<array|function> [boolean] [boolean]', [callback, applyBeforeValidation, global], arguments.length); | ||
| export function globalMiddlewareFactory(globalMiddleware, context) { | ||
| return function (callback, applyBeforeValidation = false) { | ||
| argsert('<array|function> [boolean]', [callback, applyBeforeValidation], arguments.length); | ||
| if (Array.isArray(callback)) { | ||
@@ -16,42 +11,12 @@ for (let i = 0; i < callback.length; i++) { | ||
| } | ||
| const m = callback[i]; | ||
| m.applyBeforeValidation = applyBeforeValidation; | ||
| m.global = global; | ||
| callback[i].applyBeforeValidation = applyBeforeValidation; | ||
| } | ||
| Array.prototype.push.apply(this.globalMiddleware, callback); | ||
| Array.prototype.push.apply(globalMiddleware, callback); | ||
| } | ||
| else if (typeof callback === 'function') { | ||
| const m = callback; | ||
| m.applyBeforeValidation = applyBeforeValidation; | ||
| m.global = global; | ||
| this.globalMiddleware.push(callback); | ||
| callback.applyBeforeValidation = applyBeforeValidation; | ||
| globalMiddleware.push(callback); | ||
| } | ||
| return this.yargs; | ||
| } | ||
| addCoerceMiddleware(callback, option) { | ||
| const aliases = this.yargs.getAliases(); | ||
| this.globalMiddleware = this.globalMiddleware.filter(m => { | ||
| const toCheck = [...(aliases[option] ? aliases[option] : []), option]; | ||
| if (!m.option) | ||
| return true; | ||
| else | ||
| return !toCheck.includes(m.option); | ||
| }); | ||
| callback.option = option; | ||
| return this.addMiddleware(callback, true, true); | ||
| } | ||
| getMiddleware() { | ||
| return this.globalMiddleware; | ||
| } | ||
| freeze() { | ||
| this.frozens.push([...this.globalMiddleware]); | ||
| } | ||
| unfreeze() { | ||
| const frozen = this.frozens.pop(); | ||
| if (frozen !== undefined) | ||
| this.globalMiddleware = frozen; | ||
| } | ||
| reset() { | ||
| this.globalMiddleware = this.globalMiddleware.filter(m => m.global); | ||
| } | ||
| return context; | ||
| }; | ||
| } | ||
@@ -58,0 +23,0 @@ export function commandMiddlewareFactory(commandMiddleware) { |
@@ -1,2 +0,1 @@ | ||
| import { assertNotStrictEqual, } from './typings/common-types.js'; | ||
| import { objFilter } from './utils/obj-filter.js'; | ||
@@ -193,3 +192,3 @@ import { YError } from './yerror.js'; | ||
| } | ||
| if (commands.length) { | ||
| if (commands.length > 1 || (commands.length === 1 && !commands[0][2])) { | ||
| ui.div(__('Commands:')); | ||
@@ -537,3 +536,4 @@ const context = yargs.getContext(); | ||
| const frozen = frozens.pop(); | ||
| assertNotStrictEqual(frozen, undefined, shim); | ||
| if (!frozen) | ||
| return; | ||
| ({ | ||
@@ -540,0 +540,0 @@ failMessage, |
@@ -151,2 +151,28 @@ import { argsert } from './argsert.js'; | ||
| }; | ||
| let checks = []; | ||
| self.check = function check(f, global) { | ||
| checks.push({ | ||
| func: f, | ||
| global, | ||
| }); | ||
| }; | ||
| self.customChecks = function customChecks(argv, aliases) { | ||
| for (let i = 0, f; (f = checks[i]) !== undefined; i++) { | ||
| const func = f.func; | ||
| let result = null; | ||
| try { | ||
| result = func(argv, aliases); | ||
| } | ||
| catch (err) { | ||
| usage.fail(err.message ? err.message : err, err); | ||
| continue; | ||
| } | ||
| if (!result) { | ||
| usage.fail(__('Argument check failed: %s', func.toString())); | ||
| } | ||
| else if (typeof result === 'string' || result instanceof Error) { | ||
| usage.fail(result.toString(), result); | ||
| } | ||
| } | ||
| }; | ||
| let implied = {}; | ||
@@ -265,2 +291,3 @@ self.implies = function implies(key, value) { | ||
| conflicting = objFilter(conflicting, k => !localLookup[k]); | ||
| checks = checks.filter(c => c.global); | ||
| return self; | ||
@@ -272,2 +299,3 @@ }; | ||
| implied, | ||
| checks, | ||
| conflicting, | ||
@@ -279,5 +307,5 @@ }); | ||
| assertNotStrictEqual(frozen, undefined, shim); | ||
| ({ implied, conflicting } = frozen); | ||
| ({ implied, checks, conflicting } = frozen); | ||
| }; | ||
| return self; | ||
| } |
@@ -10,5 +10,4 @@ import { command as Command, } from './command.js'; | ||
| import { applyExtends } from './utils/apply-extends.js'; | ||
| import { applyMiddleware, GlobalMiddleware, } from './middleware.js'; | ||
| import { applyMiddleware, globalMiddlewareFactory, } from './middleware.js'; | ||
| import { isPromise } from './utils/is-promise.js'; | ||
| import { maybeAsyncResult } from './utils/maybe-async-result.js'; | ||
| import setBlocking from './utils/set-blocking.js'; | ||
@@ -25,8 +24,9 @@ let shim; | ||
| let groups = {}; | ||
| const globalMiddleware = []; | ||
| let output = ''; | ||
| const preservedGroups = {}; | ||
| const globalMiddleware = new GlobalMiddleware(self); | ||
| let usage; | ||
| let validation; | ||
| const y18n = shim.y18n; | ||
| self.middleware = globalMiddlewareFactory(globalMiddleware, self); | ||
| self.scriptName = function (scriptName) { | ||
@@ -126,2 +126,3 @@ self.customScriptName = true; | ||
| 'demandedCommands', | ||
| 'coerce', | ||
| 'deprecatedOptions', | ||
@@ -146,3 +147,2 @@ ]; | ||
| completion = Completion(self, usage, command, shim); | ||
| globalMiddleware.reset(); | ||
| completionCommand = null; | ||
@@ -177,3 +177,2 @@ output = ''; | ||
| command.freeze(); | ||
| globalMiddleware.freeze(); | ||
| } | ||
@@ -204,3 +203,2 @@ function unfreeze() { | ||
| command.unfreeze(); | ||
| globalMiddleware.unfreeze(); | ||
| } | ||
@@ -307,38 +305,3 @@ self.boolean = function (keys) { | ||
| argsert('<object|string|array> [function]', [keys, value], arguments.length); | ||
| if (Array.isArray(keys)) { | ||
| if (!value) { | ||
| throw new YError('coerce callback must be provided'); | ||
| } | ||
| for (const key of keys) { | ||
| self.coerce(key, value); | ||
| } | ||
| return self; | ||
| } | ||
| else if (typeof keys === 'object') { | ||
| for (const key of Object.keys(keys)) { | ||
| self.coerce(key, keys[key]); | ||
| } | ||
| return self; | ||
| } | ||
| if (!value) { | ||
| throw new YError('coerce callback must be provided'); | ||
| } | ||
| self.alias(keys, keys); | ||
| globalMiddleware.addCoerceMiddleware((argv, yargs) => { | ||
| let aliases; | ||
| return maybeAsyncResult(() => { | ||
| aliases = yargs.getAliases(); | ||
| return value(argv[keys]); | ||
| }, (err) => { | ||
| throw new YError(err.message); | ||
| }, (result) => { | ||
| argv[keys] = result; | ||
| if (aliases[keys]) { | ||
| for (const alias of aliases[keys]) { | ||
| argv[alias] = result; | ||
| } | ||
| } | ||
| return argv; | ||
| }); | ||
| }, keys); | ||
| populateParserHintSingleValueDictionary(self.coerce, 'coerce', keys, value); | ||
| return self; | ||
@@ -418,3 +381,3 @@ }; | ||
| }; | ||
| self.command = function (cmd, description, builder, handler, middlewares, deprecated) { | ||
| self.command = self.commands = function (cmd, description, builder, handler, middlewares, deprecated) { | ||
| argsert('<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]', [cmd, description, builder, handler, middlewares, deprecated], arguments.length); | ||
@@ -477,5 +440,2 @@ command.addHandler(cmd, description, builder, handler, middlewares, deprecated); | ||
| }; | ||
| self.getAliases = () => { | ||
| return self.parsed ? self.parsed.aliases : {}; | ||
| }; | ||
| self.getDemandedOptions = () => { | ||
@@ -537,25 +497,7 @@ argsert([], 0); | ||
| }; | ||
| self.check = function (f, global) { | ||
| argsert('<function> [boolean]', [f, global], arguments.length); | ||
| self.middleware((argv, yargs) => { | ||
| return maybeAsyncResult(() => { | ||
| return f(argv, yargs); | ||
| }, (err) => { | ||
| usage.fail(err.message ? err.message : err.toString(), err); | ||
| return argv; | ||
| }, (result) => { | ||
| if (!result) { | ||
| usage.fail(y18n.__('Argument check failed: %s', f.toString())); | ||
| } | ||
| else if (typeof result === 'string' || result instanceof Error) { | ||
| usage.fail(result.toString(), result); | ||
| } | ||
| return argv; | ||
| }); | ||
| }, false, global); | ||
| self.check = function (f, _global) { | ||
| argsert('<function> [boolean]', [f, _global], arguments.length); | ||
| validation.check(f, _global !== false); | ||
| return self; | ||
| }; | ||
| self.middleware = (callback, applyBeforeValidation, global = true) => { | ||
| return globalMiddleware.addMiddleware(callback, !!applyBeforeValidation, global); | ||
| }; | ||
| self.global = function global(globals, global) { | ||
@@ -1037,7 +979,9 @@ argsert('<string|array> [boolean]', [globals, global], arguments.length); | ||
| Object.defineProperty(self, 'argv', { | ||
| get: () => self._parseArgs(processArgs), | ||
| get: () => { | ||
| return self.parse(); | ||
| }, | ||
| enumerable: true, | ||
| }); | ||
| self._parseArgs = function parseArgs(args, shortCircuit, calledFromCommand, commandIndex = 0, helpOnly = false) { | ||
| let skipValidation = !!calledFromCommand; | ||
| let skipValidation = !!calledFromCommand || helpOnly; | ||
| args = args || processArgs; | ||
@@ -1079,5 +1023,3 @@ options.__ = y18n.__; | ||
| const requestCompletions = completion.completionKey in argv; | ||
| const skipRecommendation = argv[helpOpt] || requestCompletions; | ||
| const skipDefaultCommand = skipRecommendation && | ||
| (handlerKeys.length > 1 || handlerKeys[0] !== '$0'); | ||
| const skipRecommendation = argv[helpOpt] || requestCompletions || helpOnly; | ||
| if (argv._.length) { | ||
@@ -1097,3 +1039,3 @@ if (handlerKeys.length) { | ||
| } | ||
| if (command.hasDefaultCommand() && !skipDefaultCommand) { | ||
| if (command.hasDefaultCommand() && !skipRecommendation) { | ||
| const innerArgv = command.runCommand(null, self, parsed, 0, helpOnly); | ||
@@ -1115,3 +1057,3 @@ return self._postProcess(innerArgv, populateDoubleDash, !!calledFromCommand, false); | ||
| } | ||
| else if (command.hasDefaultCommand() && !skipDefaultCommand) { | ||
| else if (command.hasDefaultCommand() && !skipRecommendation) { | ||
| const innerArgv = command.runCommand(null, self, parsed, 0, helpOnly); | ||
@@ -1162,10 +1104,5 @@ return self._postProcess(innerArgv, populateDoubleDash, !!calledFromCommand, false); | ||
| if (!calledFromCommand) { | ||
| argvPromise = applyMiddleware(argv, self, globalMiddleware.getMiddleware(), true); | ||
| argvPromise = applyMiddleware(argv, self, globalMiddleware, true); | ||
| } | ||
| argvPromise = validateAsync(validation, argvPromise !== null && argvPromise !== void 0 ? argvPromise : argv); | ||
| if (isPromise(argvPromise) && !calledFromCommand) { | ||
| argvPromise = argvPromise.then(() => { | ||
| return applyMiddleware(argv, self, globalMiddleware.getMiddleware(), false); | ||
| }); | ||
| } | ||
| } | ||
@@ -1183,8 +1120,12 @@ } | ||
| function validateAsync(validation, argv) { | ||
| return maybeAsyncResult(argv, (err) => { | ||
| throw err; | ||
| }, result => { | ||
| validation(result); | ||
| return result; | ||
| }); | ||
| if (isPromise(argv)) { | ||
| argv = argv.then(argv => { | ||
| validation(argv); | ||
| return argv; | ||
| }); | ||
| } | ||
| else { | ||
| validation(argv); | ||
| } | ||
| return argv; | ||
| } | ||
@@ -1205,3 +1146,3 @@ self._postProcess = function (argv, populateDoubleDash, calledFromCommand, runGlobalMiddleware) { | ||
| if (runGlobalMiddleware) { | ||
| argv = applyMiddleware(argv, self, globalMiddleware.getMiddleware(), false); | ||
| argv = applyMiddleware(argv, self, globalMiddleware, false); | ||
| } | ||
@@ -1249,2 +1190,3 @@ return argv; | ||
| } | ||
| validation.customChecks(argv, aliases); | ||
| validation.limitedChoices(argv); | ||
@@ -1251,0 +1193,0 @@ validation.implications(argv); |
+3
-3
| { | ||
| "name": "yargs", | ||
| "version": "17.0.0-candidate.3", | ||
| "version": "17.0.0-candidate.4", | ||
| "description": "yargs the modern, pirate-themed, successor to optimist.", | ||
@@ -82,4 +82,4 @@ "main": "./index.cjs", | ||
| "posttest": "npm run check", | ||
| "test": "c8 mocha --enable-source-maps ./test/*.cjs --require ./test/before.cjs --timeout=12000 --check-leaks", | ||
| "test:esm": "c8 mocha --enable-source-maps ./test/esm/*.mjs --check-leaks", | ||
| "test": "c8 mocha ./test/*.cjs --require ./test/before.cjs --timeout=12000 --check-leaks", | ||
| "test:esm": "c8 mocha ./test/esm/*.mjs --check-leaks", | ||
| "coverage": "c8 report --check-coverage", | ||
@@ -86,0 +86,0 @@ "prepare": "npm run compile", |
| export declare function argsert(callerArguments: any[], length?: number): void; | ||
| export declare function argsert(expected: string, callerArguments: any[], length?: number): void; |
| import { Dictionary, RequireDirectoryOptions, PlatformShim } from './typings/common-types.js'; | ||
| import { GlobalMiddleware, Middleware } from './middleware.js'; | ||
| import { Positional } from './parse-command.js'; | ||
| import { UsageInstance } from './usage.js'; | ||
| import { ValidationInstance } from './validation.js'; | ||
| import { YargsInstance, Options, OptionDefinition, Context, Arguments, DetailedArguments } from './yargs-factory.js'; | ||
| export declare type DefinitionOrCommandName = string | CommandHandlerDefinition; | ||
| export declare function command(yargs: YargsInstance, usage: UsageInstance, validation: ValidationInstance, globalMiddleware: GlobalMiddleware, shim: PlatformShim): CommandInstance; | ||
| export interface CommandInstance { | ||
| addDirectory(dir: string, context: Context, req: Function, callerFile: string, opts?: RequireDirectoryOptions): void; | ||
| addHandler(cmd: string | CommandHandlerDefinition | DefinitionOrCommandName[], description?: CommandHandler['description'], builder?: CommandBuilderDefinition | CommandBuilder, handler?: CommandHandlerCallback, commandMiddleware?: Middleware[], deprecated?: boolean): void; | ||
| cmdToParseOptions(cmdString: string): Positionals; | ||
| freeze(): void; | ||
| getCommandHandlers(): Dictionary<CommandHandler>; | ||
| getCommands(): string[]; | ||
| hasDefaultCommand(): boolean; | ||
| reset(): CommandInstance; | ||
| runCommand(command: string | null, yargs: YargsInstance, parsed: DetailedArguments, commandIndex: number, helpOnly: boolean): Arguments | Promise<Arguments>; | ||
| runDefaultBuilderOn(yargs: YargsInstance): void; | ||
| unfreeze(): void; | ||
| } | ||
| export interface CommandHandlerDefinition extends Partial<Pick<CommandHandler, 'deprecated' | 'description' | 'handler' | 'middlewares'>> { | ||
| aliases?: string[]; | ||
| builder?: CommandBuilder | CommandBuilderDefinition; | ||
| command?: string | string[]; | ||
| desc?: CommandHandler['description']; | ||
| describe?: CommandHandler['description']; | ||
| } | ||
| export interface CommandBuilderDefinition { | ||
| builder?: CommandBuilder; | ||
| deprecated?: boolean; | ||
| handler: CommandHandlerCallback; | ||
| middlewares?: Middleware[]; | ||
| } | ||
| export declare function isCommandBuilderDefinition(builder?: CommandBuilder | CommandBuilderDefinition): builder is CommandBuilderDefinition; | ||
| export interface CommandHandlerCallback { | ||
| (argv: Arguments): any; | ||
| } | ||
| export interface CommandHandler { | ||
| builder: CommandBuilder; | ||
| demanded: Positional[]; | ||
| deprecated?: boolean; | ||
| description?: string | false; | ||
| handler: CommandHandlerCallback; | ||
| middlewares: Middleware[]; | ||
| optional: Positional[]; | ||
| original: string; | ||
| } | ||
| export declare type CommandBuilder = CommandBuilderCallback | Dictionary<OptionDefinition>; | ||
| interface CommandBuilderCallback { | ||
| (y: YargsInstance): YargsInstance | void; | ||
| } | ||
| export declare function isCommandBuilderCallback(builder: CommandBuilder): builder is CommandBuilderCallback; | ||
| export declare function isCommandHandlerDefinition(cmd: DefinitionOrCommandName | [DefinitionOrCommandName, ...string[]]): cmd is CommandHandlerDefinition; | ||
| interface Positionals extends Pick<Options, 'alias' | 'array' | 'default'> { | ||
| demand: Dictionary<boolean>; | ||
| } | ||
| export {}; |
| export declare const completionShTemplate = "###-begin-{{app_name}}-completions-###\n#\n# yargs command completion script\n#\n# Installation: {{app_path}} {{completion_command}} >> ~/.bashrc\n# or {{app_path}} {{completion_command}} >> ~/.bash_profile on OSX.\n#\n_yargs_completions()\n{\n local cur_word args type_list\n\n cur_word=\"${COMP_WORDS[COMP_CWORD]}\"\n args=(\"${COMP_WORDS[@]}\")\n\n # ask yargs to generate completions.\n type_list=$({{app_path}} --get-yargs-completions \"${args[@]}\")\n\n COMPREPLY=( $(compgen -W \"${type_list}\" -- ${cur_word}) )\n\n # if no match was found, fall back to filename completion\n if [ ${#COMPREPLY[@]} -eq 0 ]; then\n COMPREPLY=()\n fi\n\n return 0\n}\ncomplete -o default -F _yargs_completions {{app_name}}\n###-end-{{app_name}}-completions-###\n"; | ||
| export declare const completionZshTemplate = "#compdef {{app_name}}\n###-begin-{{app_name}}-completions-###\n#\n# yargs command completion script\n#\n# Installation: {{app_path}} {{completion_command}} >> ~/.zshrc\n# or {{app_path}} {{completion_command}} >> ~/.zsh_profile on OSX.\n#\n_{{app_name}}_yargs_completions()\n{\n local reply\n local si=$IFS\n IFS=$'\n' reply=($(COMP_CWORD=\"$((CURRENT-1))\" COMP_LINE=\"$BUFFER\" COMP_POINT=\"$CURSOR\" {{app_path}} --get-yargs-completions \"${words[@]}\"))\n IFS=$si\n _describe 'values' reply\n}\ncompdef _{{app_name}}_yargs_completions {{app_name}}\n###-end-{{app_name}}-completions-###\n"; |
| import { CommandInstance } from './command.js'; | ||
| import { PlatformShim } from './typings/common-types.js'; | ||
| import { UsageInstance } from './usage.js'; | ||
| import { YargsInstance } from './yargs-factory.js'; | ||
| import { Arguments, DetailedArguments } from './typings/yargs-parser-types.js'; | ||
| declare type CompletionCallback = (err: Error | null, completions: string[] | undefined) => void; | ||
| export interface CompletionInstance { | ||
| completionKey: string; | ||
| generateCompletionScript($0: string, cmd: string): string; | ||
| getCompletion(args: string[], done: (err: Error | null, completions: string[] | undefined) => void): any; | ||
| registerFunction(fn: CompletionFunction): void; | ||
| setParsed(parsed: DetailedArguments): void; | ||
| } | ||
| export declare class Completion implements CompletionInstance { | ||
| private readonly yargs; | ||
| private readonly usage; | ||
| private readonly command; | ||
| private readonly shim; | ||
| completionKey: string; | ||
| private aliases; | ||
| private customCompletionFunction; | ||
| private readonly zshShell; | ||
| constructor(yargs: YargsInstance, usage: UsageInstance, command: CommandInstance, shim: PlatformShim); | ||
| private defaultCompletion; | ||
| private commandCompletions; | ||
| private optionCompletions; | ||
| private argsContainKey; | ||
| private completeOptionKey; | ||
| private customCompletion; | ||
| getCompletion(args: string[], done: CompletionCallback): any; | ||
| generateCompletionScript($0: string, cmd: string): string; | ||
| registerFunction(fn: CompletionFunction): void; | ||
| setParsed(parsed: DetailedArguments): void; | ||
| } | ||
| export declare function completion(yargs: YargsInstance, usage: UsageInstance, command: CommandInstance, shim: PlatformShim): CompletionInstance; | ||
| export declare type CompletionFunction = SyncCompletionFunction | AsyncCompletionFunction | FallbackCompletionFunction; | ||
| interface SyncCompletionFunction { | ||
| (current: string, argv: Arguments): string[] | Promise<string[]>; | ||
| } | ||
| interface AsyncCompletionFunction { | ||
| (current: string, argv: Arguments, done: (completions: string[]) => any): any; | ||
| } | ||
| interface FallbackCompletionFunction { | ||
| (current: string, argv: Arguments, defaultCompletion: () => any, done: (completions: string[]) => any): any; | ||
| } | ||
| export {}; |
| import { YargsInstance, Arguments } from './yargs-factory.js'; | ||
| export declare class GlobalMiddleware { | ||
| globalMiddleware: Middleware[]; | ||
| yargs: YargsInstance; | ||
| frozens: Array<Middleware[]>; | ||
| constructor(yargs: YargsInstance); | ||
| addMiddleware(callback: MiddlewareCallback | MiddlewareCallback[], applyBeforeValidation: boolean, global?: boolean): YargsInstance; | ||
| addCoerceMiddleware(callback: MiddlewareCallback, option: string): YargsInstance; | ||
| getMiddleware(): Middleware[]; | ||
| freeze(): void; | ||
| unfreeze(): void; | ||
| reset(): void; | ||
| } | ||
| export declare function commandMiddlewareFactory(commandMiddleware?: MiddlewareCallback[]): Middleware[]; | ||
| export declare function applyMiddleware(argv: Arguments | Promise<Arguments>, yargs: YargsInstance, middlewares: Middleware[], beforeValidation: boolean): Arguments | Promise<Arguments>; | ||
| export interface MiddlewareCallback { | ||
| (argv: Arguments, yargs: YargsInstance): Partial<Arguments> | Promise<Partial<Arguments>>; | ||
| } | ||
| export interface Middleware extends MiddlewareCallback { | ||
| applyBeforeValidation: boolean; | ||
| global: boolean; | ||
| option?: string; | ||
| } |
| import { NotEmptyArray } from './typings/common-types.js'; | ||
| export declare function parseCommand(cmd: string): ParsedCommand; | ||
| export interface ParsedCommand { | ||
| cmd: string; | ||
| demanded: Positional[]; | ||
| optional: Positional[]; | ||
| } | ||
| export interface Positional { | ||
| cmd: NotEmptyArray<string>; | ||
| variadic: boolean; | ||
| } |
| import { Parser } from './yargs-parser-types.js'; | ||
| export declare type Dictionary<T = any> = { | ||
| [key: string]: T; | ||
| }; | ||
| export declare type DictionaryKeyof<T, U = any> = Exclude<KeyOf<T, Dictionary<U>>, KeyOf<T, any[]>>; | ||
| export declare type KeyOf<T, U> = Exclude<{ | ||
| [K in keyof T]: T[K] extends U ? K : never; | ||
| }[keyof T], undefined>; | ||
| export declare type NotEmptyArray<T = any> = [T, ...T[]]; | ||
| export declare type ValueOf<T> = T extends (infer U)[] ? U : T[keyof T]; | ||
| export declare function assertNotStrictEqual<N, T>(actual: T | N, expected: N, shim: PlatformShim, message?: string | Error): asserts actual is Exclude<T, N>; | ||
| export declare function assertSingleKey(actual: string | string[] | Dictionary, shim: PlatformShim): asserts actual is string; | ||
| export declare function objectKeys<T>(object: T): (keyof T)[]; | ||
| export interface RequireDirectoryOptions { | ||
| extensions?: ReadonlyArray<string>; | ||
| visit?: (commandObject: any, pathToFile: string, filename?: string) => any; | ||
| recurse?: boolean; | ||
| } | ||
| export interface PlatformShim { | ||
| assert: { | ||
| notStrictEqual: (expected: any, observed: any, message?: string | Error) => void; | ||
| strictEqual: (expected: any, observed: any, message?: string | Error) => void; | ||
| }; | ||
| findUp: (startDir: string, fn: (dir: string[], names: string[]) => string | undefined) => string; | ||
| getCallerFile: () => string; | ||
| getEnv: (key: string) => string | undefined; | ||
| getProcessArgvBin: () => string; | ||
| inspect: (obj: object) => string; | ||
| mainFilename: string; | ||
| requireDirectory: Function; | ||
| stringWidth: (str: string) => number; | ||
| cliui: Function; | ||
| Parser: Parser; | ||
| path: { | ||
| basename: (p1: string, p2?: string) => string; | ||
| extname: (path: string) => string; | ||
| dirname: (path: string) => string; | ||
| relative: (p1: string, p2: string) => string; | ||
| resolve: (p1: string, p2: string) => string; | ||
| }; | ||
| process: { | ||
| argv: () => string[]; | ||
| cwd: () => string; | ||
| execPath: () => string; | ||
| exit: (code: number) => void; | ||
| nextTick: (cb: Function) => void; | ||
| stdColumns: number | null; | ||
| }; | ||
| readFileSync: (path: string, encoding: string) => string; | ||
| require: RequireType; | ||
| y18n: Y18N; | ||
| } | ||
| export interface RequireType { | ||
| (path: string): Function; | ||
| main: MainType; | ||
| } | ||
| export interface MainType { | ||
| filename: string; | ||
| children: MainType[]; | ||
| } | ||
| export interface Y18N { | ||
| __(str: string, ...args: string[]): string; | ||
| __n(str: string, ...args: (string | number)[]): string; | ||
| getLocale(): string; | ||
| setLocale(locale: string): void; | ||
| updateLocale(obj: { | ||
| [key: string]: string; | ||
| }): void; | ||
| } |
| import type { Dictionary, ValueOf } from './common-types.js'; | ||
| declare type KeyOf<T> = { | ||
| [K in keyof T]: string extends K ? never : number extends K ? never : K; | ||
| } extends { | ||
| [_ in keyof T]: infer U; | ||
| } ? U : never; | ||
| export declare type ArgsInput = string | any[]; | ||
| export declare type ArgsOutput = (string | number)[]; | ||
| export interface Arguments { | ||
| _: ArgsOutput; | ||
| '--'?: ArgsOutput; | ||
| [argName: string]: any; | ||
| } | ||
| export interface DetailedArguments { | ||
| argv: Arguments; | ||
| error: Error | null; | ||
| aliases: Dictionary<string[]>; | ||
| newAliases: Dictionary<boolean>; | ||
| defaulted: Dictionary<boolean>; | ||
| configuration: Configuration; | ||
| } | ||
| export interface Configuration { | ||
| 'boolean-negation': boolean; | ||
| 'camel-case-expansion': boolean; | ||
| 'combine-arrays': boolean; | ||
| 'dot-notation': boolean; | ||
| 'duplicate-arguments-array': boolean; | ||
| 'flatten-duplicate-arrays': boolean; | ||
| 'greedy-arrays': boolean; | ||
| 'halt-at-non-option': boolean; | ||
| 'nargs-eats-options': boolean; | ||
| 'negation-prefix': string; | ||
| 'parse-positional-numbers': boolean; | ||
| 'parse-numbers': boolean; | ||
| 'populate--': boolean; | ||
| 'set-placeholder-key': boolean; | ||
| 'short-option-groups': boolean; | ||
| 'strip-aliased': boolean; | ||
| 'strip-dashed': boolean; | ||
| 'unknown-options-as-args': boolean; | ||
| } | ||
| export declare type ArrayOption = string | { | ||
| key: string; | ||
| boolean?: boolean; | ||
| string?: boolean; | ||
| number?: boolean; | ||
| integer?: boolean; | ||
| }; | ||
| export declare type CoerceCallback = (arg: any) => any; | ||
| export declare type ConfigCallback = (configPath: string) => { | ||
| [key: string]: any; | ||
| } | Error; | ||
| export interface Options { | ||
| alias: Dictionary<string | string[]>; | ||
| array: ArrayOption | ArrayOption[]; | ||
| boolean: string | string[]; | ||
| config: string | string[] | Dictionary<boolean | ConfigCallback>; | ||
| configObjects: Dictionary<any>[]; | ||
| configuration: Partial<Configuration>; | ||
| coerce: Dictionary<CoerceCallback>; | ||
| count: string | string[]; | ||
| default: Dictionary<any>; | ||
| envPrefix?: string; | ||
| narg: Dictionary<number>; | ||
| normalize: string | string[]; | ||
| string: string | string[]; | ||
| number: string | string[]; | ||
| __: (format: any, ...param: any[]) => string; | ||
| key: Dictionary<any>; | ||
| } | ||
| export interface PlatformShim { | ||
| cwd: Function; | ||
| format: Function; | ||
| normalize: Function; | ||
| require: Function; | ||
| resolve: Function; | ||
| env: Function; | ||
| } | ||
| export declare type OptionsDefault = ValueOf<Pick<Required<Options>, 'default'>>; | ||
| export interface Parser { | ||
| (args: ArgsInput, opts?: Partial<Options>): Arguments; | ||
| detailed(args: ArgsInput, opts?: Partial<Options>): DetailedArguments; | ||
| camelCase(str: string): string; | ||
| decamelize(str: string, joinString?: string): string; | ||
| looksLikeNumber(x: null | undefined | number | string): boolean; | ||
| } | ||
| export declare type StringFlag = Dictionary<string[]>; | ||
| export declare type BooleanFlag = Dictionary<boolean>; | ||
| export declare type NumberFlag = Dictionary<number>; | ||
| export declare type ConfigsFlag = Dictionary<string | string[] | boolean | ConfigCallback>; | ||
| export declare type CoercionsFlag = Dictionary<CoerceCallback>; | ||
| export declare type KeysFlag = string[]; | ||
| export interface Flags { | ||
| aliases: StringFlag; | ||
| arrays: BooleanFlag; | ||
| bools: BooleanFlag; | ||
| strings: BooleanFlag; | ||
| numbers: BooleanFlag; | ||
| counts: BooleanFlag; | ||
| normalize: BooleanFlag; | ||
| configs: ConfigsFlag; | ||
| nargs: NumberFlag; | ||
| coercions: CoercionsFlag; | ||
| keys: KeysFlag; | ||
| } | ||
| export declare type Flag = ValueOf<Omit<Flags, 'keys'>>; | ||
| export declare type FlagValue = ValueOf<Flag>; | ||
| export declare type FlagsKey = KeyOf<Omit<Flags, 'keys'>>; | ||
| export declare type ArrayFlagsKey = Extract<FlagsKey, 'bools' | 'strings' | 'numbers'>; | ||
| export interface DefaultValuesForType { | ||
| boolean: boolean; | ||
| string: string; | ||
| number: undefined; | ||
| array: any[]; | ||
| } | ||
| export declare type DefaultValuesForTypeKey = KeyOf<DefaultValuesForType>; | ||
| export {}; |
| import { Dictionary, PlatformShim, Y18N } from './typings/common-types.js'; | ||
| import { YargsInstance } from './yargs-factory.js'; | ||
| import { YError } from './yerror.js'; | ||
| export declare function usage(yargs: YargsInstance, y18n: Y18N, shim: PlatformShim): UsageInstance; | ||
| export interface UsageInstance { | ||
| cacheHelpMessage(): void; | ||
| clearCachedHelpMessage(): void; | ||
| hasCachedHelpMessage(): boolean; | ||
| command(cmd: string, description: string | undefined, isDefault: boolean, aliases: string[], deprecated?: boolean): void; | ||
| deferY18nLookup(str: string): string; | ||
| describe(keys: string | string[] | Dictionary<string>, desc?: string): void; | ||
| epilog(msg: string): void; | ||
| example(cmd: string, description?: string): void; | ||
| fail(msg?: string | null, err?: YError | string): void; | ||
| failFn(f: FailureFunction | boolean): void; | ||
| freeze(): void; | ||
| functionDescription(fn: { | ||
| name?: string; | ||
| }): string; | ||
| getCommands(): [string, string, boolean, string[], boolean][]; | ||
| getDescriptions(): Dictionary<string | undefined>; | ||
| getPositionalGroupName(): string; | ||
| getUsage(): [string, string][]; | ||
| getUsageDisabled(): boolean; | ||
| help(): string; | ||
| reset(localLookup: Dictionary<boolean>): UsageInstance; | ||
| showHelp(level: 'error' | 'log' | ((message: string) => void)): void; | ||
| showHelpOnFail(enabled?: boolean | string, message?: string): UsageInstance; | ||
| showVersion(): void; | ||
| stringifiedValues(values?: any[], separator?: string): string; | ||
| unfreeze(): void; | ||
| usage(msg: string | null, description?: string | false): UsageInstance; | ||
| version(ver: any): void; | ||
| wrap(cols: number | null | undefined): void; | ||
| } | ||
| export interface FailureFunction { | ||
| (msg: string | undefined | null, err: YError | string | undefined, usage: UsageInstance): void; | ||
| } | ||
| export interface FrozenUsageInstance { | ||
| failMessage: string | undefined | null; | ||
| failureOutput: boolean; | ||
| usages: [string, string][]; | ||
| usageDisabled: boolean; | ||
| epilogs: string[]; | ||
| examples: [string, string][]; | ||
| commands: [string, string, boolean, string[], boolean][]; | ||
| descriptions: Dictionary<string | undefined>; | ||
| } |
| import { Dictionary, PlatformShim } from '../typings/common-types.js'; | ||
| export declare function applyExtends(config: Dictionary, cwd: string, mergeExtends: boolean, _shim: PlatformShim): Dictionary; |
| export declare function isPromise<T>(maybePromise: T | Promise<T>): maybePromise is Promise<T>; |
| export declare function levenshtein(a: string, b: string): number; |
| export declare function maybeAsyncResult<T>(getResult: (() => T | Promise<T>) | T | Promise<T>, errorHandler: (err: Error) => T, resultHandler: (result: T) => T | Promise<T>): T | Promise<T>; |
| import { isPromise } from './is-promise.js'; | ||
| export function maybeAsyncResult(getResult, errorHandler, resultHandler) { | ||
| try { | ||
| const result = isFunction(getResult) ? getResult() : getResult; | ||
| if (isPromise(result)) { | ||
| return result.then((result) => { | ||
| return resultHandler(result); | ||
| }); | ||
| } | ||
| else { | ||
| return resultHandler(result); | ||
| } | ||
| } | ||
| catch (err) { | ||
| return errorHandler(err); | ||
| } | ||
| } | ||
| function isFunction(arg) { | ||
| return typeof arg === 'function'; | ||
| } |
| export declare function objFilter<T extends object>(original?: T, filter?: (k: keyof T, v: T[keyof T]) => boolean): T; |
| export declare function hideBin(argv: string[]): string[]; | ||
| export declare function getProcessArgvBin(): string; |
| export default function setBlocking(blocking: boolean): void; |
| /// <reference types="node" /> | ||
| export default function whichModule(exported: object): NodeModule | null | undefined; |
| import { Dictionary, Y18N, PlatformShim } from './typings/common-types.js'; | ||
| import { UsageInstance } from './usage.js'; | ||
| import { YargsInstance, Arguments } from './yargs-factory.js'; | ||
| import { DetailedArguments } from './typings/yargs-parser-types.js'; | ||
| export declare function validation(yargs: YargsInstance, usage: UsageInstance, y18n: Y18N, shim: PlatformShim): ValidationInstance; | ||
| export interface ValidationInstance { | ||
| conflicting(argv: Arguments): void; | ||
| conflicts(key: string | Dictionary<string | string[]>, value?: string | string[]): void; | ||
| freeze(): void; | ||
| getConflicting(): Dictionary<(string | undefined)[]>; | ||
| getImplied(): Dictionary<KeyOrPos[]>; | ||
| implications(argv: Arguments): void; | ||
| implies(key: string | Dictionary<KeyOrPos | KeyOrPos[]>, value?: KeyOrPos | KeyOrPos[]): void; | ||
| isValidAndSomeAliasIsNotNew(key: string, aliases: DetailedArguments['aliases']): boolean; | ||
| limitedChoices(argv: Arguments): void; | ||
| nonOptionCount(argv: Arguments): void; | ||
| positionalCount(required: number, observed: number): void; | ||
| recommendCommands(cmd: string, potentialCommands: string[]): void; | ||
| requiredArguments(argv: Arguments, demandedOptions: Dictionary<string | undefined>): void; | ||
| reset(localLookup: Dictionary): ValidationInstance; | ||
| unfreeze(): void; | ||
| unknownArguments(argv: Arguments, aliases: DetailedArguments['aliases'], positionalMap: Dictionary, isDefaultCommand: boolean, checkPositionals?: boolean): void; | ||
| unknownCommands(argv: Arguments): boolean; | ||
| } | ||
| export declare type KeyOrPos = string | number; |
| import { CommandInstance, CommandHandler, CommandBuilderDefinition, CommandBuilder, CommandHandlerCallback, CommandHandlerDefinition } from './command.js'; | ||
| import type { Dictionary, RequireDirectoryOptions, PlatformShim, RequireType } from './typings/common-types.js'; | ||
| import { ArgsOutput, DetailedArguments as ParserDetailedArguments, Configuration as ParserConfiguration, Options as ParserOptions, ConfigCallback, CoerceCallback } from './typings/yargs-parser-types.js'; | ||
| import { YError } from './yerror.js'; | ||
| import { UsageInstance, FailureFunction } from './usage.js'; | ||
| import { CompletionFunction } from './completion.js'; | ||
| import { ValidationInstance, KeyOrPos } from './validation.js'; | ||
| import { MiddlewareCallback, Middleware } from './middleware.js'; | ||
| export declare function YargsWithShim(_shim: PlatformShim): typeof Yargs; | ||
| declare function Yargs(processArgs?: string | string[], cwd?: string, parentRequire?: RequireType): YargsInstance; | ||
| export interface RebaseFunction { | ||
| (base: string, dir: string): string; | ||
| } | ||
| export declare const rebase: RebaseFunction; | ||
| export interface YargsInstance { | ||
| $0: string; | ||
| argv: Arguments; | ||
| customScriptName: boolean; | ||
| parsed: DetailedArguments | false; | ||
| _postProcess<T extends Arguments | Promise<Arguments>>(argv: T, populateDoubleDash: boolean, calledFromCommand: boolean, runGlobalMiddleware: boolean): T; | ||
| _copyDoubleDash<T extends Arguments>(argv: T): T; | ||
| _parsePositionalNumbers<T extends Arguments>(argv: T): T; | ||
| _getLoggerInstance(): LoggerInstance; | ||
| _getParseContext(): Object; | ||
| _hasOutput(): boolean; | ||
| _hasParseCallback(): boolean; | ||
| _parseArgs: { | ||
| (args: string | string[] | null, shortCircuit?: boolean, calledFromCommand?: boolean, commandIndex?: number, helpOnly?: boolean): Arguments | Promise<Arguments>; | ||
| (args: string | string[], shortCircuit?: boolean): Arguments | Promise<Arguments>; | ||
| }; | ||
| _runValidation(aliases: Dictionary<string[]>, positionalMap: Dictionary<string[]>, parseErrors: Error | null, isDefaultCommand?: boolean): (argv: Arguments) => void; | ||
| _setHasOutput(): void; | ||
| addHelpOpt: { | ||
| (opt?: string | false): YargsInstance; | ||
| (opt?: string, msg?: string): YargsInstance; | ||
| }; | ||
| addShowHiddenOpt: { | ||
| (opt?: string | false): YargsInstance; | ||
| (opt?: string, msg?: string): YargsInstance; | ||
| }; | ||
| alias: { | ||
| (keys: string | string[], aliases: string | string[]): YargsInstance; | ||
| (keyAliases: Dictionary<string | string[]>): YargsInstance; | ||
| }; | ||
| array(keys: string | string[]): YargsInstance; | ||
| boolean(keys: string | string[]): YargsInstance; | ||
| check(f: (argv: Arguments, yargs: YargsInstance) => any, global?: boolean): YargsInstance; | ||
| choices: { | ||
| (keys: string | string[], choices: string | string[]): YargsInstance; | ||
| (keyChoices: Dictionary<string | string[]>): YargsInstance; | ||
| }; | ||
| coerce: { | ||
| (keys: string | string[], coerceCallback: CoerceCallback): YargsInstance; | ||
| (keyCoerceCallbacks: Dictionary<CoerceCallback>): YargsInstance; | ||
| }; | ||
| command(handler: CommandHandlerDefinition): YargsInstance; | ||
| command(cmd: string | string[], description: CommandHandler['description'], builder?: CommandBuilderDefinition | CommandBuilder, handler?: CommandHandlerCallback, commandMiddleware?: Middleware[], deprecated?: boolean): YargsInstance; | ||
| commandDir(dir: string, opts?: RequireDirectoryOptions): YargsInstance; | ||
| completion: { | ||
| (cmd?: string, fn?: CompletionFunction): YargsInstance; | ||
| (cmd?: string, desc?: string | false, fn?: CompletionFunction): YargsInstance; | ||
| }; | ||
| config: { | ||
| (config: Dictionary): YargsInstance; | ||
| (keys?: string | string[], configCallback?: ConfigCallback): YargsInstance; | ||
| (keys?: string | string[], msg?: string, configCallback?: ConfigCallback): YargsInstance; | ||
| }; | ||
| conflicts: { | ||
| (key: string, conflictsWith: string | string[]): YargsInstance; | ||
| (keyConflicts: Dictionary<string | string[]>): YargsInstance; | ||
| }; | ||
| count(keys: string | string[]): YargsInstance; | ||
| default: { | ||
| (key: string, value: any, defaultDescription?: string): YargsInstance; | ||
| (keys: string[], value: Exclude<any, Function>): YargsInstance; | ||
| (keys: Dictionary<any>): YargsInstance; | ||
| }; | ||
| defaults: YargsInstance['default']; | ||
| demand: { | ||
| (min: number, max?: number | string, msg?: string): YargsInstance; | ||
| (keys: string | string[], msg?: string | true): YargsInstance; | ||
| (keys: string | string[], max: string[], msg?: string | true): YargsInstance; | ||
| (keyMsgs: Dictionary<string | undefined>): YargsInstance; | ||
| (keyMsgs: Dictionary<string | undefined>, max: string[], msg?: string): YargsInstance; | ||
| }; | ||
| demandCommand(): YargsInstance; | ||
| demandCommand(min: number, minMsg?: string): YargsInstance; | ||
| demandCommand(min: number, max: number, minMsg?: string | null, maxMsg?: string | null): YargsInstance; | ||
| demandOption: { | ||
| (keys: string | string[], msg?: string): YargsInstance; | ||
| (keyMsgs: Dictionary<string | undefined>): YargsInstance; | ||
| }; | ||
| deprecateOption(option: string, message?: string | boolean): YargsInstance; | ||
| describe: { | ||
| (keys: string | string[], description?: string): YargsInstance; | ||
| (keyDescriptions: Dictionary<string>): YargsInstance; | ||
| }; | ||
| detectLocale(detect: boolean): YargsInstance; | ||
| env(prefix?: string | false): YargsInstance; | ||
| epilog: YargsInstance['epilogue']; | ||
| epilogue(msg: string): YargsInstance; | ||
| example(cmd: string | [string, string?][], description?: string): YargsInstance; | ||
| exit(code: number, err?: YError | string): void; | ||
| exitProcess(enabled: boolean): YargsInstance; | ||
| fail(f: FailureFunction | boolean): YargsInstance; | ||
| getCommandInstance(): CommandInstance; | ||
| getCompletion(args: string[], done?: (err: Error | null, completions: string[] | undefined) => void): Promise<string[] | void> | any; | ||
| getHelp(): Promise<string>; | ||
| getContext(): Context; | ||
| getAliases(): Dictionary<string[]>; | ||
| getDemandedCommands(): Options['demandedCommands']; | ||
| getDemandedOptions(): Options['demandedOptions']; | ||
| getDeprecatedOptions(): Options['deprecatedOptions']; | ||
| getDetectLocale(): boolean; | ||
| getExitProcess(): boolean; | ||
| getGroups(): Dictionary<string[]>; | ||
| getOptions(): Options; | ||
| getParserConfiguration(): Configuration; | ||
| getStrict(): boolean; | ||
| getStrictCommands(): boolean; | ||
| getStrictOptions(): boolean; | ||
| getUsageInstance(): UsageInstance; | ||
| getValidationInstance(): ValidationInstance; | ||
| global(keys: string | string[], global?: boolean): YargsInstance; | ||
| group(keys: string | string[], groupName: string): YargsInstance; | ||
| help: YargsInstance['addHelpOpt']; | ||
| hide(key: string): YargsInstance; | ||
| implies: { | ||
| (key: string, implication: KeyOrPos | KeyOrPos[]): YargsInstance; | ||
| (keyImplications: Dictionary<KeyOrPos | KeyOrPos[]>): YargsInstance; | ||
| }; | ||
| locale: { | ||
| (): string; | ||
| (locale: string): YargsInstance; | ||
| }; | ||
| middleware(callback: MiddlewareCallback | MiddlewareCallback[], applyBeforeValidation?: boolean, global?: boolean): YargsInstance; | ||
| nargs: { | ||
| (keys: string | string[], nargs: number): YargsInstance; | ||
| (keyNargs: Dictionary<number>): YargsInstance; | ||
| }; | ||
| normalize(keys: string | string[]): YargsInstance; | ||
| number(keys: string | string[]): YargsInstance; | ||
| option: { | ||
| (key: string, optionDefinition: OptionDefinition): YargsInstance; | ||
| (keyOptionDefinitions: Dictionary<OptionDefinition>): YargsInstance; | ||
| }; | ||
| options: YargsInstance['option']; | ||
| parse: { | ||
| (): Arguments | Promise<Arguments>; | ||
| (args: string | string[]): Arguments | Promise<Arguments>; | ||
| (args: string | string[], context: object, parseCallback?: ParseCallback): Arguments | Promise<Arguments>; | ||
| (args: string | string[], parseCallback: ParseCallback): Arguments | Promise<Arguments>; | ||
| (args: string | string[], shortCircuit: boolean): Arguments | Promise<Arguments>; | ||
| }; | ||
| parserConfiguration(config: Configuration): YargsInstance; | ||
| pkgConf(key: string, rootPath?: string): YargsInstance; | ||
| positional(key: string, positionalDefinition: PositionalDefinition): YargsInstance; | ||
| recommendCommands(recommend: boolean): YargsInstance; | ||
| require: YargsInstance['demand']; | ||
| required: YargsInstance['demand']; | ||
| requiresArg(keys: string | string[] | Dictionary): YargsInstance; | ||
| reset(aliases?: DetailedArguments['aliases']): YargsInstance; | ||
| resetOptions(aliases?: DetailedArguments['aliases']): YargsInstance; | ||
| scriptName(scriptName: string): YargsInstance; | ||
| showCompletionScript($0?: string, cmd?: string): YargsInstance; | ||
| showHelp(level: 'error' | 'log' | ((message: string) => void)): YargsInstance; | ||
| showHelpOnFail: { | ||
| (message?: string): YargsInstance; | ||
| (enabled: boolean, message: string): YargsInstance; | ||
| }; | ||
| showHidden: YargsInstance['addShowHiddenOpt']; | ||
| skipValidation(keys: string | string[]): YargsInstance; | ||
| strict(enable?: boolean): YargsInstance; | ||
| strictCommands(enable?: boolean): YargsInstance; | ||
| strictOptions(enable?: boolean): YargsInstance; | ||
| string(key: string | string[]): YargsInstance; | ||
| terminalWidth(): number | null; | ||
| updateStrings(obj: Dictionary<string>): YargsInstance; | ||
| updateLocale: YargsInstance['updateStrings']; | ||
| usage: { | ||
| (msg: string | null): YargsInstance; | ||
| (msg: string, description: CommandHandler['description'], builder?: CommandBuilderDefinition | CommandBuilder, handler?: CommandHandlerCallback): YargsInstance; | ||
| }; | ||
| version: { | ||
| (ver?: string | false): YargsInstance; | ||
| (key?: string, ver?: string): YargsInstance; | ||
| (key?: string, msg?: string, ver?: string): YargsInstance; | ||
| }; | ||
| wrap(cols: number | null | undefined): YargsInstance; | ||
| } | ||
| export declare function isYargsInstance(y: YargsInstance | void): y is YargsInstance; | ||
| export interface Context { | ||
| commands: string[]; | ||
| files: string[]; | ||
| fullCommands: string[]; | ||
| } | ||
| interface LoggerInstance { | ||
| error: Function; | ||
| log: Function; | ||
| } | ||
| export interface Options extends ParserOptions { | ||
| __: (format: any, ...param: any[]) => string; | ||
| alias: Dictionary<string[]>; | ||
| array: string[]; | ||
| boolean: string[]; | ||
| choices: Dictionary<string[]>; | ||
| config: Dictionary<ConfigCallback | boolean>; | ||
| configObjects: Dictionary[]; | ||
| configuration: Configuration; | ||
| count: string[]; | ||
| defaultDescription: Dictionary<string | undefined>; | ||
| demandedCommands: Dictionary<{ | ||
| min: number; | ||
| max: number; | ||
| minMsg?: string | null; | ||
| maxMsg?: string | null; | ||
| }>; | ||
| demandedOptions: Dictionary<string | undefined>; | ||
| deprecatedOptions: Dictionary<string | boolean | undefined>; | ||
| hiddenOptions: string[]; | ||
| key: Dictionary<boolean | string>; | ||
| local: string[]; | ||
| normalize: string[]; | ||
| number: string[]; | ||
| showHiddenOpt: string; | ||
| skipValidation: string[]; | ||
| string: string[]; | ||
| } | ||
| export interface Configuration extends Partial<ParserConfiguration> { | ||
| 'deep-merge-config'?: boolean; | ||
| 'sort-commands'?: boolean; | ||
| } | ||
| export interface OptionDefinition { | ||
| alias?: string | string[]; | ||
| array?: boolean; | ||
| boolean?: boolean; | ||
| choices?: string | string[]; | ||
| coerce?: CoerceCallback; | ||
| config?: boolean; | ||
| configParser?: ConfigCallback; | ||
| conflicts?: string | string[]; | ||
| count?: boolean; | ||
| default?: any; | ||
| defaultDescription?: string; | ||
| deprecate?: string | boolean; | ||
| deprecated?: OptionDefinition['deprecate']; | ||
| desc?: string; | ||
| describe?: OptionDefinition['desc']; | ||
| description?: OptionDefinition['desc']; | ||
| demand?: string | true; | ||
| demandOption?: OptionDefinition['demand']; | ||
| global?: boolean; | ||
| group?: string; | ||
| hidden?: boolean; | ||
| implies?: string | number | KeyOrPos[]; | ||
| nargs?: number; | ||
| normalize?: boolean; | ||
| number?: boolean; | ||
| require?: OptionDefinition['demand']; | ||
| required?: OptionDefinition['demand']; | ||
| requiresArg?: boolean; | ||
| skipValidation?: boolean; | ||
| string?: boolean; | ||
| type?: 'array' | 'boolean' | 'count' | 'number' | 'string'; | ||
| } | ||
| interface PositionalDefinition extends Pick<OptionDefinition, 'alias' | 'array' | 'coerce' | 'choices' | 'conflicts' | 'default' | 'defaultDescription' | 'demand' | 'desc' | 'describe' | 'description' | 'implies' | 'normalize'> { | ||
| type?: 'boolean' | 'number' | 'string'; | ||
| } | ||
| interface ParseCallback { | ||
| (err: YError | string | undefined | null, argv: Arguments | Promise<Arguments>, output: string): void; | ||
| } | ||
| export interface Arguments { | ||
| $0: string; | ||
| _: ArgsOutput; | ||
| '--'?: ArgsOutput; | ||
| [argName: string]: any; | ||
| } | ||
| export interface DetailedArguments extends ParserDetailedArguments { | ||
| argv: Arguments; | ||
| aliases: Dictionary<string[]>; | ||
| } | ||
| export {}; |
| export declare class YError extends Error { | ||
| name: string; | ||
| constructor(msg?: string | null); | ||
| } |
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
293899
-11.47%57
-26.92%7281
-10.49%