Comparing version 16.2.0 to 17.0.0-candidate.0
@@ -117,3 +117,3 @@ import { assertNotStrictEqual, } from './typings/common-types.js'; | ||
self.hasDefaultCommand = () => !!defaultCommand; | ||
self.runCommand = function runCommand(command, yargs, parsed, commandIndex) { | ||
self.runCommand = function runCommand(command, yargs, parsed, commandIndex = 0, helpOnly = false) { | ||
let aliases = parsed.aliases; | ||
@@ -139,3 +139,3 @@ const commandHandler = handlers[command] || handlers[aliasMap[command]] || defaultCommand; | ||
} | ||
innerArgv = innerYargs._parseArgs(null, null, true, commandIndex); | ||
innerArgv = innerYargs._parseArgs(null, undefined, true, commandIndex, helpOnly); | ||
aliases = innerYargs.parsed.aliases; | ||
@@ -153,3 +153,3 @@ } | ||
}); | ||
innerArgv = innerYargs._parseArgs(null, null, true, commandIndex); | ||
innerArgv = innerYargs._parseArgs(null, undefined, true, commandIndex, helpOnly); | ||
aliases = innerYargs.parsed.aliases; | ||
@@ -160,2 +160,4 @@ } | ||
} | ||
if (helpOnly) | ||
return innerArgv; | ||
const middlewares = globalMiddleware | ||
@@ -173,33 +175,27 @@ .slice(0) | ||
innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false); | ||
let handlerResult; | ||
if (isPromise(innerArgv)) { | ||
handlerResult = innerArgv.then(argv => commandHandler.handler(argv)); | ||
const innerArgvRef = innerArgv; | ||
innerArgv = innerArgv | ||
.then(argv => commandHandler.handler(argv)) | ||
.then(() => innerArgvRef); | ||
} | ||
else { | ||
handlerResult = commandHandler.handler(innerArgv); | ||
const handlerResult = commandHandler.handler(innerArgv); | ||
if (isPromise(handlerResult)) { | ||
const innerArgvRef = innerArgv; | ||
innerArgv = handlerResult.then(() => innerArgvRef); | ||
} | ||
} | ||
const handlerFinishCommand = yargs.getHandlerFinishCommand(); | ||
if (isPromise(handlerResult)) { | ||
if (isPromise(innerArgv) && !yargs._hasParseCallback()) { | ||
yargs.getUsageInstance().cacheHelpMessage(); | ||
handlerResult | ||
.then(value => { | ||
if (handlerFinishCommand) { | ||
handlerFinishCommand(value); | ||
} | ||
}) | ||
.catch(error => { | ||
innerArgv.catch(error => { | ||
try { | ||
yargs.getUsageInstance().fail(null, error); | ||
} | ||
catch (err) { | ||
catch (_err) { | ||
} | ||
}) | ||
.then(() => { | ||
yargs.getUsageInstance().clearCachedHelpMessage(); | ||
}); | ||
} | ||
else { | ||
if (handlerFinishCommand) { | ||
handlerFinishCommand(handlerResult); | ||
} | ||
else if (isPromise(innerArgv)) { | ||
yargs.getUsageInstance().cacheHelpMessage(); | ||
} | ||
@@ -206,0 +202,0 @@ } |
@@ -29,3 +29,3 @@ import { isCommandBuilderCallback } from './command.js'; | ||
shim.process.nextTick(() => { | ||
done(list); | ||
done(null, list); | ||
}); | ||
@@ -35,11 +35,11 @@ }) | ||
shim.process.nextTick(() => { | ||
throw err; | ||
done(err, undefined); | ||
}); | ||
}); | ||
} | ||
return done(result); | ||
return done(null, result); | ||
} | ||
else { | ||
return completionFunction(current, argv, completions => { | ||
done(completions); | ||
done(null, completions); | ||
}); | ||
@@ -109,3 +109,3 @@ } | ||
} | ||
done(completions); | ||
done(null, completions); | ||
}; | ||
@@ -112,0 +112,0 @@ self.generateCompletionScript = function generateCompletionScript($0, cmd) { |
@@ -5,2 +5,5 @@ import { assertNotStrictEqual, } from './typings/common-types.js'; | ||
import setBlocking from './utils/set-blocking.js'; | ||
function isBoolean(fail) { | ||
return typeof fail === 'boolean'; | ||
} | ||
export function usage(yargs, y18n, shim) { | ||
@@ -29,3 +32,9 @@ const __ = y18n.__; | ||
for (let i = fails.length - 1; i >= 0; --i) { | ||
fails[i](msg, err, self); | ||
const fail = fails[i]; | ||
if (isBoolean(fail)) { | ||
throw err; | ||
} | ||
else { | ||
fail(msg, err, self); | ||
} | ||
} | ||
@@ -415,2 +424,5 @@ } | ||
}; | ||
self.hasCachedHelpMessage = function () { | ||
return !!cachedHelpMessage; | ||
}; | ||
function addUngroupedKeys(keys, aliases, groups, defaultGroup) { | ||
@@ -417,0 +429,0 @@ let groupedKeys = []; |
@@ -28,3 +28,2 @@ import { command as Command, } from './command.js'; | ||
let validation; | ||
let handlerFinishCommand = null; | ||
const y18n = shim.y18n; | ||
@@ -171,3 +170,2 @@ self.middleware = globalMiddlewareFactory(globalMiddleware, self); | ||
parseContext, | ||
handlerFinishCommand, | ||
}); | ||
@@ -197,3 +195,2 @@ usage.freeze(); | ||
parseContext, | ||
handlerFinishCommand, | ||
} = frozen); | ||
@@ -487,12 +484,9 @@ options.configObjects = configObjects; | ||
self.fail = function (f) { | ||
argsert('<function>', [f], arguments.length); | ||
argsert('<function|boolean>', [f], arguments.length); | ||
if (typeof f === 'boolean' && f !== false) { | ||
throw new YError("Invalid first argument. Expected function or boolean 'false'"); | ||
} | ||
usage.failFn(f); | ||
return self; | ||
}; | ||
self.onFinishCommand = function (f) { | ||
argsert('<function>', [f], arguments.length); | ||
handlerFinishCommand = f; | ||
return self; | ||
}; | ||
self.getHandlerFinishCommand = () => handlerFinishCommand; | ||
self.check = function (f, _global) { | ||
@@ -786,9 +780,26 @@ argsert('<function> [boolean]', [f, _global], arguments.length); | ||
self.getParserConfiguration = () => parserConfig; | ||
self.getHelp = async function () { | ||
hasOutput = true; | ||
if (!usage.hasCachedHelpMessage()) { | ||
if (!self.parsed) { | ||
self._parseArgs(processArgs, undefined, undefined, 0, true); | ||
} | ||
if (command.hasDefaultCommand()) { | ||
context.resets++; | ||
command.runDefaultBuilderOn(self); | ||
} | ||
} | ||
return usage.help(); | ||
}; | ||
self.showHelp = function (level) { | ||
argsert('[string|function]', [level], arguments.length); | ||
if (!self.parsed) | ||
self._parseArgs(processArgs); | ||
if (command.hasDefaultCommand()) { | ||
context.resets++; | ||
command.runDefaultBuilderOn(self); | ||
hasOutput = true; | ||
if (!usage.hasCachedHelpMessage()) { | ||
if (!self.parsed) { | ||
self._parseArgs(processArgs, undefined, undefined, 0, true); | ||
} | ||
if (command.hasDefaultCommand()) { | ||
context.resets++; | ||
command.runDefaultBuilderOn(self); | ||
} | ||
} | ||
@@ -887,5 +898,17 @@ usage.showHelp(level); | ||
}; | ||
self.getCompletion = function (args, done) { | ||
argsert('<array> <function>', [args, done], arguments.length); | ||
completion.getCompletion(args, done); | ||
self.getCompletion = async function (args, done) { | ||
argsert('<array> [function]', [args, done], arguments.length); | ||
if (!done) { | ||
return new Promise((resolve, reject) => { | ||
completion.getCompletion(args, (err, completions) => { | ||
if (err) | ||
reject(err); | ||
else | ||
resolve(completions); | ||
}); | ||
}); | ||
} | ||
else { | ||
return completion.getCompletion(args, done); | ||
} | ||
}; | ||
@@ -955,3 +978,3 @@ self.locale = function (locale) { | ||
}); | ||
self._parseArgs = function parseArgs(args, shortCircuit, _calledFromCommand, commandIndex) { | ||
self._parseArgs = function parseArgs(args, shortCircuit, _calledFromCommand, commandIndex = 0, helpOnly = false) { | ||
let skipValidation = !!_calledFromCommand; | ||
@@ -974,2 +997,5 @@ args = args || processArgs; | ||
self.parsed = parsed; | ||
if (!_calledFromCommand) { | ||
usage.clearCachedHelpMessage(); | ||
} | ||
try { | ||
@@ -1000,3 +1026,3 @@ guessLocale(); | ||
if (~handlerKeys.indexOf(cmd) && cmd !== completionCommand) { | ||
const innerArgv = command.runCommand(cmd, self, parsed, i + 1); | ||
const innerArgv = command.runCommand(cmd, self, parsed, i + 1, helpOnly); | ||
return self._postProcess(innerArgv, populateDoubleDash); | ||
@@ -1010,3 +1036,3 @@ } | ||
if (command.hasDefaultCommand() && !skipDefaultCommand) { | ||
const innerArgv = command.runCommand(null, self, parsed); | ||
const innerArgv = command.runCommand(null, self, parsed, 0, helpOnly); | ||
return self._postProcess(innerArgv, populateDoubleDash); | ||
@@ -1028,3 +1054,3 @@ } | ||
else if (command.hasDefaultCommand() && !skipDefaultCommand) { | ||
const innerArgv = command.runCommand(null, self, parsed); | ||
const innerArgv = command.runCommand(null, self, parsed, 0, helpOnly); | ||
return self._postProcess(innerArgv, populateDoubleDash); | ||
@@ -1037,3 +1063,5 @@ } | ||
const completionArgs = args.slice(args.indexOf(`--${completion.completionKey}`) + 1); | ||
completion.getCompletion(completionArgs, completions => { | ||
completion.getCompletion(completionArgs, (err, completions) => { | ||
if (err) | ||
throw new YError(err.message); | ||
(completions || []).forEach(completion => { | ||
@@ -1040,0 +1068,0 @@ _logger.log(completion); |
{ | ||
"name": "yargs", | ||
"version": "16.2.0", | ||
"version": "17.0.0-candidate.0", | ||
"description": "yargs the modern, pirate-themed, successor to optimist.", | ||
@@ -74,3 +74,3 @@ "main": "./index.cjs", | ||
"rollup-plugin-cleanup": "^3.1.1", | ||
"standardx": "^5.0.0", | ||
"standardx": "^7.0.0", | ||
"typescript": "^4.0.2", | ||
@@ -82,3 +82,3 @@ "which": "^2.0.0", | ||
"fix": "gts fix && npm run fix:js", | ||
"fix:js": "standardx --fix '**/*.mjs' && standardx --fix '**/*.cjs' && standardx --fix './*.mjs' && standardx --fix './*.cjs'", | ||
"fix:js": "standardx --fix **/*.mjs && standardx --fix **/*.cjs && standardx --fix ./*.mjs && standardx --fix ./*.cjs", | ||
"posttest": "npm run check", | ||
@@ -95,3 +95,3 @@ "test": "c8 mocha ./test/*.cjs --require ./test/before.cjs --timeout=12000 --check-leaks", | ||
"check": "gts lint && npm run check:js", | ||
"check:js": "standardx '**/*.mjs' && standardx '**/*.cjs' && standardx './*.mjs' && standardx './*.cjs'", | ||
"check:js": "standardx **/*.mjs && standardx **/*.cjs && standardx ./*.mjs && standardx ./*.cjs", | ||
"clean": "gts clean" | ||
@@ -98,0 +98,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
320144
76
7813
1