yargs
Advanced tools
Comparing version 16.0.4-candidate.0 to 16.1.0
@@ -8,11 +8,15 @@ import { YError } from './yerror.js'; | ||
? [{ demanded: [], optional: [] }, arg1, arg2] | ||
: [parseCommand(`cmd ${arg1}`), arg2, arg3]; | ||
: [ | ||
parseCommand(`cmd ${arg1}`), | ||
arg2, | ||
arg3, | ||
]; | ||
} | ||
try { | ||
let position = 0; | ||
let [parsed, callerArguments, length] = parseArgs(); | ||
const [parsed, callerArguments, _length] = parseArgs(); | ||
const args = [].slice.call(callerArguments); | ||
while (args.length && args[args.length - 1] === undefined) | ||
args.pop(); | ||
length = length || args.length; | ||
const length = _length || args.length; | ||
if (length < parsed.demanded.length) { | ||
@@ -25,3 +29,3 @@ throw new YError(`Not enough arguments provided. Expected ${parsed.demanded.length} but received ${args.length}.`); | ||
} | ||
parsed.demanded.forEach((demanded) => { | ||
parsed.demanded.forEach(demanded => { | ||
const arg = args.shift(); | ||
@@ -34,3 +38,3 @@ const observedType = guessType(arg); | ||
}); | ||
parsed.optional.forEach((optional) => { | ||
parsed.optional.forEach(optional => { | ||
if (args.length === 0) | ||
@@ -37,0 +41,0 @@ return; |
@@ -1,6 +0,6 @@ | ||
import { assertNotStrictEqual } from './typings/common-types.js'; | ||
import { assertNotStrictEqual, } from './typings/common-types.js'; | ||
import { isPromise } from './utils/is-promise.js'; | ||
import { applyMiddleware, commandMiddlewareFactory } from './middleware.js'; | ||
import { applyMiddleware, commandMiddlewareFactory, } from './middleware.js'; | ||
import { parseCommand } from './parse-command.js'; | ||
import { isYargsInstance } from './yargs-factory.js'; | ||
import { isYargsInstance, } from './yargs-factory.js'; | ||
import whichModule from './utils/which-module.js'; | ||
@@ -22,3 +22,5 @@ const DEFAULT_MARKER = /(^\*)|(^\$0)/; | ||
else if (isCommandHandlerDefinition(cmd)) { | ||
let command = (Array.isArray(cmd.command) || typeof cmd.command === 'string') ? cmd.command : moduleName(cmd); | ||
let command = Array.isArray(cmd.command) || typeof cmd.command === 'string' | ||
? cmd.command | ||
: moduleName(cmd); | ||
if (cmd.aliases) | ||
@@ -36,3 +38,3 @@ command = [].concat(command).concat(cmd.aliases); | ||
let isDefault = false; | ||
const parsedAliases = [parsedCommand.cmd].concat(aliases).filter((c) => { | ||
const parsedAliases = [parsedCommand.cmd].concat(aliases).filter(c => { | ||
if (DEFAULT_MARKER.test(c)) { | ||
@@ -51,3 +53,3 @@ isDefault = true; | ||
} | ||
aliases.forEach((alias) => { | ||
aliases.forEach(alias => { | ||
aliasMap[alias] = parsedCommand.cmd; | ||
@@ -66,3 +68,3 @@ }); | ||
demanded: parsedCommand.demanded, | ||
optional: parsedCommand.optional | ||
optional: parsedCommand.optional, | ||
}; | ||
@@ -100,3 +102,3 @@ if (isDefault) | ||
} | ||
function extractDesc({ describe, description, desc }) { | ||
function extractDesc({ describe, description, desc, }) { | ||
for (const test of [describe, description, desc]) { | ||
@@ -129,3 +131,5 @@ if (typeof test === 'string' || test === false) | ||
if (shouldUpdateUsage(innerYargs)) { | ||
innerYargs.getUsageInstance().usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description); | ||
innerYargs | ||
.getUsageInstance() | ||
.usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description); | ||
} | ||
@@ -138,5 +142,7 @@ innerArgv = innerYargs._parseArgs(null, null, true, commandIndex); | ||
if (shouldUpdateUsage(innerYargs)) { | ||
innerYargs.getUsageInstance().usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description); | ||
innerYargs | ||
.getUsageInstance() | ||
.usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description); | ||
} | ||
Object.keys(commandHandler.builder).forEach((key) => { | ||
Object.keys(commandHandler.builder).forEach(key => { | ||
innerYargs.option(key, builder[key]); | ||
@@ -150,3 +156,5 @@ }); | ||
} | ||
const middlewares = globalMiddleware.slice(0).concat(commandHandler.middlewares); | ||
const middlewares = globalMiddleware | ||
.slice(0) | ||
.concat(commandHandler.middlewares); | ||
applyMiddleware(innerArgv, yargs, middlewares, true); | ||
@@ -204,8 +212,12 @@ if (!yargs._hasOutput()) { | ||
function shouldUpdateUsage(yargs) { | ||
return !yargs.getUsageInstance().getUsageDisabled() && | ||
yargs.getUsageInstance().getUsage().length === 0; | ||
return (!yargs.getUsageInstance().getUsageDisabled() && | ||
yargs.getUsageInstance().getUsage().length === 0); | ||
} | ||
function usageFromParentCommandsCommandHandler(parentCommands, commandHandler) { | ||
const c = DEFAULT_MARKER.test(commandHandler.original) ? commandHandler.original.replace(DEFAULT_MARKER, '').trim() : commandHandler.original; | ||
const pc = parentCommands.filter((c) => { return !DEFAULT_MARKER.test(c); }); | ||
const c = DEFAULT_MARKER.test(commandHandler.original) | ||
? commandHandler.original.replace(DEFAULT_MARKER, '').trim() | ||
: commandHandler.original; | ||
const pc = parentCommands.filter(c => { | ||
return !DEFAULT_MARKER.test(c); | ||
}); | ||
pc.push(c); | ||
@@ -218,3 +230,4 @@ return `$0 ${pc.join(' ')}`; | ||
const commandString = DEFAULT_MARKER.test(defaultCommand.original) | ||
? defaultCommand.original : defaultCommand.original.replace(/^[^[\]<>]*/, '$0 '); | ||
? defaultCommand.original | ||
: defaultCommand.original.replace(/^[^[\]<>]*/, '$0 '); | ||
yargs.getUsageInstance().usage(commandString, defaultCommand.description); | ||
@@ -227,3 +240,3 @@ } | ||
else { | ||
Object.keys(builder).forEach((key) => { | ||
Object.keys(builder).forEach(key => { | ||
yargs.option(key, builder[key]); | ||
@@ -270,4 +283,4 @@ }); | ||
const unparsed = []; | ||
Object.keys(positionalMap).forEach((key) => { | ||
positionalMap[key].map((value) => { | ||
Object.keys(positionalMap).forEach(key => { | ||
positionalMap[key].map(value => { | ||
if (options.configuration['unknown-options-as-args']) | ||
@@ -282,6 +295,6 @@ options.key[key] = true; | ||
const config = Object.assign({}, options.configuration, { | ||
'populate--': true | ||
'populate--': true, | ||
}); | ||
const parsed = shim.Parser.detailed(unparsed, Object.assign({}, options, { | ||
configuration: config | ||
configuration: config, | ||
})); | ||
@@ -293,6 +306,6 @@ if (parsed.error) { | ||
const positionalKeys = Object.keys(positionalMap); | ||
Object.keys(positionalMap).forEach((key) => { | ||
Object.keys(positionalMap).forEach(key => { | ||
positionalKeys.push(...parsed.aliases[key]); | ||
}); | ||
Object.keys(parsed.argv).forEach((key) => { | ||
Object.keys(parsed.argv).forEach(key => { | ||
if (positionalKeys.indexOf(key) !== -1) { | ||
@@ -311,6 +324,6 @@ if (!positionalMap[key]) | ||
alias: {}, | ||
demand: {} | ||
demand: {}, | ||
}; | ||
const parsed = parseCommand(cmdString); | ||
parsed.demanded.forEach((d) => { | ||
parsed.demanded.forEach(d => { | ||
const [cmd, ...aliases] = d.cmd; | ||
@@ -324,3 +337,3 @@ if (d.variadic) { | ||
}); | ||
parsed.optional.forEach((o) => { | ||
parsed.optional.forEach(o => { | ||
const [cmd, ...aliases] = o.cmd; | ||
@@ -346,3 +359,3 @@ if (o.variadic) { | ||
aliasMap, | ||
defaultCommand | ||
defaultCommand, | ||
}); | ||
@@ -353,7 +366,3 @@ }; | ||
assertNotStrictEqual(frozen, undefined, shim); | ||
({ | ||
handlers, | ||
aliasMap, | ||
defaultCommand | ||
} = frozen); | ||
({ handlers, aliasMap, defaultCommand } = frozen); | ||
}; | ||
@@ -366,5 +375,5 @@ return self; | ||
export function isCommandBuilderDefinition(builder) { | ||
return typeof builder === 'object' && | ||
return (typeof builder === 'object' && | ||
!!builder.builder && | ||
typeof builder.handler === 'function'; | ||
typeof builder.handler === 'function'); | ||
} | ||
@@ -371,0 +380,0 @@ export function isCommandBuilderCallback(builder) { |
@@ -8,3 +8,3 @@ import { isCommandBuilderCallback } from './command.js'; | ||
const self = { | ||
completionKey: 'get-yargs-completions' | ||
completionKey: 'get-yargs-completions', | ||
}; | ||
@@ -27,6 +27,12 @@ let aliases; | ||
if (isPromise(result)) { | ||
return result.then((list) => { | ||
shim.process.nextTick(() => { done(list); }); | ||
}).catch((err) => { | ||
shim.process.nextTick(() => { throw err; }); | ||
return result | ||
.then(list => { | ||
shim.process.nextTick(() => { | ||
done(list); | ||
}); | ||
}) | ||
.catch(err => { | ||
shim.process.nextTick(() => { | ||
throw err; | ||
}); | ||
}); | ||
@@ -37,3 +43,3 @@ } | ||
else { | ||
return completionFunction(current, argv, (completions) => { | ||
return completionFunction(current, argv, completions => { | ||
done(completions); | ||
@@ -44,3 +50,5 @@ }); | ||
if (completionFunction) { | ||
return isPromise(argv) ? argv.then(runCompletionFunction) : runCompletionFunction(argv); | ||
return isPromise(argv) | ||
? argv.then(runCompletionFunction) | ||
: runCompletionFunction(argv); | ||
} | ||
@@ -58,4 +66,5 @@ const handlers = command.getCommandHandlers(); | ||
} | ||
if (!current.match(/^-/) && parentCommands[parentCommands.length - 1] !== current) { | ||
usage.getCommands().forEach((usageCommand) => { | ||
if (!current.match(/^-/) && | ||
parentCommands[parentCommands.length - 1] !== current) { | ||
usage.getCommands().forEach(usageCommand => { | ||
const commandName = parseCommand(usageCommand[0]).cmd; | ||
@@ -76,4 +85,5 @@ if (args.indexOf(commandName) === -1) { | ||
const options = yargs.getOptions(); | ||
Object.keys(options.key).forEach((key) => { | ||
const negable = !!options.configuration['boolean-negation'] && options.boolean.includes(key); | ||
Object.keys(options.key).forEach(key => { | ||
const negable = !!options.configuration['boolean-negation'] && | ||
options.boolean.includes(key); | ||
let keyAndAliases = [key].concat(aliases[key] || []); | ||
@@ -93,3 +103,4 @@ if (negable) | ||
const desc = descs[key] || ''; | ||
completions.push(dashes + `${key.replace(/:/g, '\\:')}:${desc.replace('__yargsString__:', '')}`); | ||
completions.push(dashes + | ||
`${key.replace(/:/g, '\\:')}:${desc.replace('__yargsString__:', '')}`); | ||
} | ||
@@ -106,3 +117,5 @@ } | ||
self.generateCompletionScript = function generateCompletionScript($0, cmd) { | ||
let script = zshShell ? templates.completionZshTemplate : templates.completionShTemplate; | ||
let script = zshShell | ||
? templates.completionZshTemplate | ||
: templates.completionShTemplate; | ||
const name = shim.path.basename($0); | ||
@@ -116,3 +129,3 @@ if ($0.match(/\.js$/)) | ||
let completionFunction = null; | ||
self.registerFunction = (fn) => { | ||
self.registerFunction = fn => { | ||
completionFunction = fn; | ||
@@ -119,0 +132,0 @@ }; |
@@ -32,4 +32,3 @@ import { argsert } from './argsert.js'; | ||
const beforeValidationError = new Error('middleware cannot return a promise when applyBeforeValidation is true'); | ||
return middlewares | ||
.reduce((acc, middleware) => { | ||
return middlewares.reduce((acc, middleware) => { | ||
if (middleware.applyBeforeValidation !== beforeValidation) { | ||
@@ -40,3 +39,6 @@ return acc; | ||
return acc | ||
.then(initialObj => Promise.all([initialObj, middleware(initialObj, yargs)])) | ||
.then(initialObj => Promise.all([ | ||
initialObj, | ||
middleware(initialObj, yargs), | ||
])) | ||
.then(([initialObj, middlewareObj]) => Object.assign(initialObj, middlewareObj)); | ||
@@ -43,0 +45,0 @@ } |
@@ -11,3 +11,3 @@ export function parseCommand(cmd) { | ||
demanded: [], | ||
optional: [] | ||
optional: [], | ||
}; | ||
@@ -22,3 +22,3 @@ splitCommand.forEach((cmd, i) => { | ||
cmd: cmd.replace(bregex, '').split('|'), | ||
variadic | ||
variadic, | ||
}); | ||
@@ -29,3 +29,3 @@ } | ||
cmd: cmd.replace(bregex, '').split('|'), | ||
variadic | ||
variadic, | ||
}); | ||
@@ -32,0 +32,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { assertNotStrictEqual } from './typings/common-types.js'; | ||
import { assertNotStrictEqual, } from './typings/common-types.js'; | ||
import { objFilter } from './utils/obj-filter.js'; | ||
@@ -88,3 +88,3 @@ import { YError } from './yerror.js'; | ||
if (isDefault) { | ||
commands = commands.map((cmdArray) => { | ||
commands = commands.map(cmdArray => { | ||
cmdArray[2] = false; | ||
@@ -100,3 +100,3 @@ return cmdArray; | ||
if (Array.isArray(keyOrKeys)) { | ||
keyOrKeys.forEach((k) => { | ||
keyOrKeys.forEach(k => { | ||
self.describe(k, desc); | ||
@@ -106,3 +106,3 @@ }); | ||
else if (typeof keyOrKeys === 'object') { | ||
Object.keys(keyOrKeys).forEach((k) => { | ||
Object.keys(keyOrKeys).forEach(k => { | ||
self.describe(k, keyOrKeys[k]); | ||
@@ -117,3 +117,3 @@ }); | ||
let epilogs = []; | ||
self.epilog = (msg) => { | ||
self.epilog = msg => { | ||
epilogs.push(msg); | ||
@@ -123,3 +123,3 @@ }; | ||
let wrap; | ||
self.wrap = (cols) => { | ||
self.wrap = cols => { | ||
wrapSet = true; | ||
@@ -141,3 +141,5 @@ wrap = cols; | ||
normalizeAliases(); | ||
const base$0 = yargs.customScriptName ? yargs.$0 : shim.path.basename(yargs.$0); | ||
const base$0 = yargs.customScriptName | ||
? yargs.$0 | ||
: shim.path.basename(yargs.$0); | ||
const demandedOptions = yargs.getDemandedOptions(); | ||
@@ -162,7 +164,7 @@ const demandedCommands = yargs.getDemandedCommands(); | ||
width: theWrap, | ||
wrap: !!theWrap | ||
wrap: !!theWrap, | ||
}); | ||
if (!usageDisabled) { | ||
if (usages.length) { | ||
usages.forEach((usage) => { | ||
usages.forEach(usage => { | ||
ui.div(`${usage[0].replace(/\$0/g, base$0)}`); | ||
@@ -189,7 +191,9 @@ if (usage[1]) { | ||
const context = yargs.getContext(); | ||
const parentCommands = context.commands.length ? `${context.commands.join(' ')} ` : ''; | ||
const parentCommands = context.commands.length | ||
? `${context.commands.join(' ')} ` | ||
: ''; | ||
if (yargs.getParserConfiguration()['sort-commands'] === true) { | ||
commands = commands.sort((a, b) => a[0].localeCompare(b[0])); | ||
} | ||
commands.forEach((command) => { | ||
commands.forEach(command => { | ||
const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}`; | ||
@@ -199,3 +203,3 @@ ui.span({ | ||
padding: [0, 2, 0, 2], | ||
width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4 | ||
width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4, | ||
}, { text: command[1] }); | ||
@@ -217,3 +221,7 @@ const hints = []; | ||
if (hints.length) { | ||
ui.div({ text: hints.join(' '), padding: [0, 0, 0, 2], align: 'right' }); | ||
ui.div({ | ||
text: hints.join(' '), | ||
padding: [0, 0, 0, 2], | ||
align: 'right', | ||
}); | ||
} | ||
@@ -226,5 +234,5 @@ else { | ||
} | ||
const aliasKeys = (Object.keys(options.alias) || []) | ||
.concat(Object.keys(yargs.parsed.newAliases) || []); | ||
keys = keys.filter(key => !yargs.parsed.newAliases[key] && aliasKeys.every(alias => (options.alias[alias] || []).indexOf(key) === -1)); | ||
const aliasKeys = (Object.keys(options.alias) || []).concat(Object.keys(yargs.parsed.newAliases) || []); | ||
keys = keys.filter(key => !yargs.parsed.newAliases[key] && | ||
aliasKeys.every(alias => (options.alias[alias] || []).indexOf(key) === -1)); | ||
const defaultGroup = __('Options:'); | ||
@@ -238,3 +246,5 @@ if (!groups[defaultGroup]) | ||
.map(groupName => { | ||
const normalizedKeys = groups[groupName].filter(filterHiddenOptions).map((key) => { | ||
const normalizedKeys = groups[groupName] | ||
.filter(filterHiddenOptions) | ||
.map(key => { | ||
if (~aliasKeys.indexOf(key)) | ||
@@ -253,3 +263,4 @@ return key; | ||
const switches = normalizedKeys.reduce((acc, key) => { | ||
acc[key] = [key].concat(options.alias[key] || []) | ||
acc[key] = [key] | ||
.concat(options.alias[key] || []) | ||
.map(sw => { | ||
@@ -259,8 +270,16 @@ if (groupName === self.getPositionalGroupName()) | ||
else { | ||
return (/^[0-9]$/.test(sw) | ||
? ~options.boolean.indexOf(key) ? '-' : '--' | ||
: sw.length > 1 ? '--' : '-') + sw; | ||
return ((/^[0-9]$/.test(sw) | ||
? ~options.boolean.indexOf(key) | ||
? '-' | ||
: '--' | ||
: sw.length > 1 | ||
? '--' | ||
: '-') + sw); | ||
} | ||
}) | ||
.sort((sw1, sw2) => isLongSwitch(sw1) === isLongSwitch(sw2) ? 0 : (isLongSwitch(sw1) ? 1 : -1)) | ||
.sort((sw1, sw2) => isLongSwitch(sw1) === isLongSwitch(sw2) | ||
? 0 | ||
: isLongSwitch(sw1) | ||
? 1 | ||
: -1) | ||
.join(', '); | ||
@@ -287,3 +306,3 @@ return acc; | ||
ui.div(groupName); | ||
normalizedKeys.forEach((key) => { | ||
normalizedKeys.forEach(key => { | ||
const kswitch = switches[key]; | ||
@@ -310,9 +329,19 @@ let desc = descriptions[key] || ''; | ||
const extra = [ | ||
(key in deprecatedOptions) ? deprecatedExtra(deprecatedOptions[key]) : null, | ||
key in deprecatedOptions | ||
? deprecatedExtra(deprecatedOptions[key]) | ||
: null, | ||
type, | ||
(key in demandedOptions) ? `[${__('required')}]` : null, | ||
options.choices && options.choices[key] ? `[${__('choices:')} ${self.stringifiedValues(options.choices[key])}]` : null, | ||
defaultString(options.default[key], options.defaultDescription[key]) | ||
].filter(Boolean).join(' '); | ||
ui.span({ text: getText(kswitch), padding: [0, 2, 0, 2 + getIndentation(kswitch)], width: maxWidth(switches, theWrap) + 4 }, desc); | ||
key in demandedOptions ? `[${__('required')}]` : null, | ||
options.choices && options.choices[key] | ||
? `[${__('choices:')} ${self.stringifiedValues(options.choices[key])}]` | ||
: null, | ||
defaultString(options.default[key], options.defaultDescription[key]), | ||
] | ||
.filter(Boolean) | ||
.join(' '); | ||
ui.span({ | ||
text: getText(kswitch), | ||
padding: [0, 2, 0, 2 + getIndentation(kswitch)], | ||
width: maxWidth(switches, theWrap) + 4, | ||
}, desc); | ||
if (extra) | ||
@@ -327,10 +356,10 @@ ui.div({ text: extra, padding: [0, 0, 0, 2], align: 'right' }); | ||
ui.div(__('Examples:')); | ||
examples.forEach((example) => { | ||
examples.forEach(example => { | ||
example[0] = example[0].replace(/\$0/g, base$0); | ||
}); | ||
examples.forEach((example) => { | ||
examples.forEach(example => { | ||
if (example[1] === '') { | ||
ui.div({ | ||
text: example[0], | ||
padding: [0, 2, 0, 2] | ||
padding: [0, 2, 0, 2], | ||
}); | ||
@@ -342,5 +371,5 @@ } | ||
padding: [0, 2, 0, 2], | ||
width: maxWidth(examples, theWrap) + 4 | ||
width: maxWidth(examples, theWrap) + 4, | ||
}, { | ||
text: example[1] | ||
text: example[1], | ||
}); | ||
@@ -352,3 +381,5 @@ } | ||
if (epilogs.length > 0) { | ||
const e = epilogs.map(epilog => epilog.replace(/\$0/g, base$0)).join('\n'); | ||
const e = epilogs | ||
.map(epilog => epilog.replace(/\$0/g, base$0)) | ||
.join('\n'); | ||
ui.div(`${e}\n`); | ||
@@ -363,3 +394,3 @@ } | ||
} | ||
table.forEach((v) => { | ||
table.forEach(v => { | ||
width = Math.max(shim.stringWidth(modifier ? `${modifier} ${getText(v[0])}` : getText(v[0])) + getIndentation(v[0]), width); | ||
@@ -374,4 +405,4 @@ }); | ||
const options = yargs.getOptions(); | ||
(Object.keys(options.alias) || []).forEach((key) => { | ||
options.alias[key].forEach((alias) => { | ||
(Object.keys(options.alias) || []).forEach(key => { | ||
options.alias[key].forEach(alias => { | ||
if (descriptions[alias]) | ||
@@ -406,6 +437,6 @@ self.describe(key, descriptions[alias]); | ||
let toCheck = null; | ||
Object.keys(groups).forEach((group) => { | ||
Object.keys(groups).forEach(group => { | ||
groupedKeys = groupedKeys.concat(groups[group]); | ||
}); | ||
keys.forEach((key) => { | ||
keys.forEach(key => { | ||
toCheck = [key].concat(aliases[key]); | ||
@@ -419,3 +450,4 @@ if (!toCheck.some(k => groupedKeys.indexOf(k) !== -1)) { | ||
function filterHiddenOptions(key) { | ||
return yargs.getOptions().hiddenOptions.indexOf(key) < 0 || yargs.parsed.argv[yargs.getOptions().showHiddenOpt]; | ||
return (yargs.getOptions().hiddenOptions.indexOf(key) < 0 || | ||
yargs.parsed.argv[yargs.getOptions().showHiddenOpt]); | ||
} | ||
@@ -429,4 +461,6 @@ self.showHelp = (level) => { | ||
}; | ||
self.functionDescription = (fn) => { | ||
const description = fn.name ? shim.Parser.decamelize(fn.name, '-') : __('generated-value'); | ||
self.functionDescription = fn => { | ||
const description = fn.name | ||
? shim.Parser.decamelize(fn.name, '-') | ||
: __('generated-value'); | ||
return ['(', description, ')'].join(''); | ||
@@ -440,3 +474,3 @@ }; | ||
return string; | ||
array.forEach((value) => { | ||
array.forEach(value => { | ||
if (string.length) | ||
@@ -479,3 +513,3 @@ string += sep; | ||
let version = null; | ||
self.version = (ver) => { | ||
self.version = ver => { | ||
version = ver; | ||
@@ -508,3 +542,3 @@ }; | ||
commands, | ||
descriptions | ||
descriptions, | ||
}); | ||
@@ -523,3 +557,3 @@ }; | ||
commands, | ||
descriptions | ||
descriptions, | ||
} = frozen); | ||
@@ -526,0 +560,0 @@ }; |
@@ -16,3 +16,4 @@ import { YError } from '../yerror.js'; | ||
} | ||
catch (err) { | ||
catch (_err) { | ||
return config; | ||
} | ||
@@ -23,9 +24,7 @@ } | ||
} | ||
if (!pathToDefault && !isPath) | ||
return config; | ||
if (!pathToDefault) | ||
throw new YError(`Unable to find extended config '${config.extends}' in '${cwd}'.`); | ||
checkForCircularExtends(pathToDefault); | ||
previouslyVisitedConfigs.push(pathToDefault); | ||
defaultConfig = isPath ? JSON.parse(shim.readFileSync(pathToDefault, 'utf8')) : require(config.extends); | ||
defaultConfig = isPath | ||
? JSON.parse(shim.readFileSync(pathToDefault, 'utf8')) | ||
: require(config.extends); | ||
delete config.extends; | ||
@@ -35,3 +34,5 @@ defaultConfig = applyExtends(defaultConfig, shim.path.dirname(pathToDefault), mergeExtends, shim); | ||
previouslyVisitedConfigs = []; | ||
return mergeExtends ? mergeDeep(defaultConfig, config) : Object.assign({}, defaultConfig, config); | ||
return mergeExtends | ||
? mergeDeep(defaultConfig, config) | ||
: Object.assign({}, defaultConfig, config); | ||
} | ||
@@ -38,0 +39,0 @@ function checkForCircularExtends(cfgPath) { |
export function isPromise(maybePromise) { | ||
return !!maybePromise && | ||
return (!!maybePromise && | ||
!!maybePromise.then && | ||
(typeof maybePromise.then === 'function'); | ||
typeof maybePromise.then === 'function'); | ||
} |
import { objectKeys } from '../typings/common-types.js'; | ||
export function objFilter(original = {}, filter = () => true) { | ||
const obj = {}; | ||
objectKeys(original).forEach((key) => { | ||
objectKeys(original).forEach(key => { | ||
if (filter(key, original[key])) { | ||
@@ -6,0 +6,0 @@ obj[key] = original[key]; |
export default function setBlocking(blocking) { | ||
if (typeof process === 'undefined') | ||
return; | ||
[process.stdout, process.stderr].forEach((_stream) => { | ||
[process.stdout, process.stderr].forEach(_stream => { | ||
const stream = _stream; | ||
if (stream._handle && stream.isTTY && typeof stream._handle.setBlocking === 'function') { | ||
if (stream._handle && | ||
stream.isTTY && | ||
typeof stream._handle.setBlocking === 'function') { | ||
stream._handle.setBlocking(blocking); | ||
@@ -8,0 +10,0 @@ } |
export default function whichModule(exported) { | ||
if (typeof require === 'undefined') | ||
return null; | ||
for (var i = 0, files = Object.keys(require.cache), mod; i < files.length; i++) { | ||
for (let i = 0, files = Object.keys(require.cache), mod; i < files.length; i++) { | ||
mod = require.cache[files[i]]; | ||
@@ -6,0 +6,0 @@ if (mod.exports === exported) |
import { argsert } from './argsert.js'; | ||
import { assertNotStrictEqual } from './typings/common-types.js'; | ||
import { assertNotStrictEqual, } from './typings/common-types.js'; | ||
import { levenshtein as distance } from './utils/levenshtein.js'; | ||
@@ -14,7 +14,10 @@ import { objFilter } from './utils/obj-filter.js'; | ||
const _s = positionalCount - yargs.getContext().commands.length; | ||
if (demandedCommands._ && (_s < demandedCommands._.min || _s > demandedCommands._.max)) { | ||
if (demandedCommands._ && | ||
(_s < demandedCommands._.min || _s > demandedCommands._.max)) { | ||
if (_s < demandedCommands._.min) { | ||
if (demandedCommands._.minMsg !== undefined) { | ||
usage.fail(demandedCommands._.minMsg | ||
? demandedCommands._.minMsg.replace(/\$0/g, _s.toString()).replace(/\$1/, demandedCommands._.min.toString()) | ||
? demandedCommands._.minMsg | ||
.replace(/\$0/g, _s.toString()) | ||
.replace(/\$1/, demandedCommands._.min.toString()) | ||
: null); | ||
@@ -29,3 +32,5 @@ } | ||
usage.fail(demandedCommands._.maxMsg | ||
? demandedCommands._.maxMsg.replace(/\$0/g, _s.toString()).replace(/\$1/, demandedCommands._.max.toString()) | ||
? demandedCommands._.maxMsg | ||
.replace(/\$0/g, _s.toString()) | ||
.replace(/\$1/, demandedCommands._.max.toString()) | ||
: null); | ||
@@ -48,3 +53,4 @@ } | ||
for (const key of Object.keys(demandedOptions)) { | ||
if (!Object.prototype.hasOwnProperty.call(argv, key) || typeof argv[key] === 'undefined') { | ||
if (!Object.prototype.hasOwnProperty.call(argv, key) || | ||
typeof argv[key] === 'undefined') { | ||
missing = missing || {}; | ||
@@ -70,3 +76,3 @@ missing[key] = demandedOptions[key]; | ||
const currentContext = yargs.getContext(); | ||
Object.keys(argv).forEach((key) => { | ||
Object.keys(argv).forEach(key => { | ||
if (specialKeys.indexOf(key) === -1 && | ||
@@ -79,4 +85,7 @@ !Object.prototype.hasOwnProperty.call(positionalMap, key) && | ||
}); | ||
if (checkPositionals && ((currentContext.commands.length > 0) || (commandKeys.length > 0) || isDefaultCommand)) { | ||
argv._.slice(currentContext.commands.length).forEach((key) => { | ||
if (checkPositionals && | ||
(currentContext.commands.length > 0 || | ||
commandKeys.length > 0 || | ||
isDefaultCommand)) { | ||
argv._.slice(currentContext.commands.length).forEach(key => { | ||
if (commandKeys.indexOf('' + key) === -1) { | ||
@@ -95,4 +104,4 @@ unknown.push('' + key); | ||
const currentContext = yargs.getContext(); | ||
if ((currentContext.commands.length > 0) || (commandKeys.length > 0)) { | ||
argv._.slice(currentContext.commands.length).forEach((key) => { | ||
if (currentContext.commands.length > 0 || commandKeys.length > 0) { | ||
argv._.slice(currentContext.commands.length).forEach(key => { | ||
if (commandKeys.indexOf('' + key) === -1) { | ||
@@ -117,3 +126,4 @@ unknown.push('' + key); | ||
for (const a of [key, ...aliases[key]]) { | ||
if (!Object.prototype.hasOwnProperty.call(newAliases, a) || !newAliases[key]) { | ||
if (!Object.prototype.hasOwnProperty.call(newAliases, a) || | ||
!newAliases[key]) { | ||
return true; | ||
@@ -129,6 +139,6 @@ } | ||
return; | ||
Object.keys(argv).forEach((key) => { | ||
Object.keys(argv).forEach(key => { | ||
if (specialKeys.indexOf(key) === -1 && | ||
Object.prototype.hasOwnProperty.call(options.choices, key)) { | ||
[].concat(argv[key]).forEach((value) => { | ||
[].concat(argv[key]).forEach(value => { | ||
if (options.choices[key].indexOf(value) === -1 && | ||
@@ -145,3 +155,3 @@ value !== undefined) { | ||
let msg = __('Invalid values:'); | ||
invalidKeys.forEach((key) => { | ||
invalidKeys.forEach(key => { | ||
msg += `\n ${__('Argument: %s, Given: %s, Choices: %s', key, usage.stringifiedValues(invalid[key]), usage.stringifiedValues(options.choices[key]))}`; | ||
@@ -155,3 +165,3 @@ }); | ||
func: f, | ||
global | ||
global, | ||
}); | ||
@@ -182,3 +192,3 @@ }; | ||
if (typeof key === 'object') { | ||
Object.keys(key).forEach((k) => { | ||
Object.keys(key).forEach(k => { | ||
self.implies(k, key[k]); | ||
@@ -193,3 +203,3 @@ }); | ||
if (Array.isArray(value)) { | ||
value.forEach((i) => self.implies(key, i)); | ||
value.forEach(i => self.implies(key, i)); | ||
} | ||
@@ -222,5 +232,5 @@ else { | ||
const implyFail = []; | ||
Object.keys(implied).forEach((key) => { | ||
Object.keys(implied).forEach(key => { | ||
const origKey = key; | ||
(implied[key] || []).forEach((value) => { | ||
(implied[key] || []).forEach(value => { | ||
let key = origKey; | ||
@@ -237,4 +247,4 @@ const origValue = value; | ||
let msg = `${__('Implications failed:')}\n`; | ||
implyFail.forEach((value) => { | ||
msg += (value); | ||
implyFail.forEach(value => { | ||
msg += value; | ||
}); | ||
@@ -248,3 +258,3 @@ usage.fail(msg); | ||
if (typeof key === 'object') { | ||
Object.keys(key).forEach((k) => { | ||
Object.keys(key).forEach(k => { | ||
self.conflicts(k, key[k]); | ||
@@ -259,3 +269,3 @@ }); | ||
if (Array.isArray(value)) { | ||
value.forEach((i) => self.conflicts(key, i)); | ||
value.forEach(i => self.conflicts(key, i)); | ||
} | ||
@@ -269,5 +279,5 @@ else { | ||
self.conflicting = function conflictingFn(argv) { | ||
Object.keys(argv).forEach((key) => { | ||
Object.keys(argv).forEach(key => { | ||
if (conflicting[key]) { | ||
conflicting[key].forEach((value) => { | ||
conflicting[key].forEach(value => { | ||
if (value && argv[key] !== undefined && argv[value] !== undefined) { | ||
@@ -306,3 +316,3 @@ usage.fail(__('Arguments %s and %s are mutually exclusive', key, value)); | ||
checks, | ||
conflicting | ||
conflicting, | ||
}); | ||
@@ -313,9 +323,5 @@ }; | ||
assertNotStrictEqual(frozen, undefined, shim); | ||
({ | ||
implied, | ||
checks, | ||
conflicting | ||
} = frozen); | ||
({ implied, checks, conflicting } = frozen); | ||
}; | ||
return self; | ||
} |
@@ -1,11 +0,11 @@ | ||
import { command as Command } from './command.js'; | ||
import { assertNotStrictEqual, objectKeys, assertSingleKey } from './typings/common-types.js'; | ||
import { command as Command, } from './command.js'; | ||
import { assertNotStrictEqual, objectKeys, assertSingleKey, } from './typings/common-types.js'; | ||
import { YError } from './yerror.js'; | ||
import { usage as Usage } from './usage.js'; | ||
import { argsert } from './argsert.js'; | ||
import { completion as Completion } from './completion.js'; | ||
import { validation as Validation } from './validation.js'; | ||
import { completion as Completion, } from './completion.js'; | ||
import { validation as Validation, } from './validation.js'; | ||
import { objFilter } from './utils/obj-filter.js'; | ||
import { applyExtends } from './utils/apply-extends.js'; | ||
import { globalMiddlewareFactory } from './middleware.js'; | ||
import { globalMiddlewareFactory, } from './middleware.js'; | ||
import { isPromise } from './utils/is-promise.js'; | ||
@@ -48,8 +48,35 @@ import setBlocking from './utils/set-blocking.js'; | ||
}) | ||
.join(' ').trim(); | ||
.join(' ') | ||
.trim(); | ||
if (shim.getEnv('_') && shim.getProcessArgvBin() === shim.getEnv('_')) { | ||
self.$0 = shim.getEnv('_').replace(`${shim.path.dirname(shim.process.execPath())}/`, ''); | ||
self.$0 = shim | ||
.getEnv('_') | ||
.replace(`${shim.path.dirname(shim.process.execPath())}/`, ''); | ||
} | ||
const context = { resets: -1, commands: [], fullCommands: [], files: [] }; | ||
self.getContext = () => context; | ||
let hasOutput = false; | ||
let exitError = null; | ||
self.exit = (code, err) => { | ||
hasOutput = true; | ||
exitError = err; | ||
if (exitProcess) | ||
shim.process.exit(code); | ||
}; | ||
let completionCommand = null; | ||
self.completion = function (cmd, desc, fn) { | ||
argsert('[string] [string|boolean|function] [function]', [cmd, desc, fn], arguments.length); | ||
if (typeof desc === 'function') { | ||
fn = desc; | ||
desc = undefined; | ||
} | ||
completionCommand = cmd || completionCommand || 'completion'; | ||
if (!desc && desc !== false) { | ||
desc = 'generate completion script'; | ||
} | ||
self.command(completionCommand, desc); | ||
if (fn) | ||
completion.registerFunction(fn); | ||
return self; | ||
}; | ||
let options; | ||
@@ -61,7 +88,9 @@ self.resetOptions = self.reset = function resetOptions(aliases = {}) { | ||
tmpOptions.local = options.local ? options.local : []; | ||
tmpOptions.configObjects = options.configObjects ? options.configObjects : []; | ||
tmpOptions.configObjects = options.configObjects | ||
? options.configObjects | ||
: []; | ||
const localLookup = {}; | ||
tmpOptions.local.forEach((l) => { | ||
tmpOptions.local.forEach(l => { | ||
localLookup[l] = true; | ||
(aliases[l] || []).forEach((a) => { | ||
(aliases[l] || []).forEach(a => { | ||
localLookup[a] = true; | ||
@@ -79,10 +108,23 @@ }); | ||
const arrayOptions = [ | ||
'array', 'boolean', 'string', 'skipValidation', | ||
'count', 'normalize', 'number', | ||
'hiddenOptions' | ||
'array', | ||
'boolean', | ||
'string', | ||
'skipValidation', | ||
'count', | ||
'normalize', | ||
'number', | ||
'hiddenOptions', | ||
]; | ||
const objectOptions = [ | ||
'narg', 'key', 'alias', 'default', 'defaultDescription', | ||
'config', 'choices', 'demandedOptions', 'demandedCommands', 'coerce', | ||
'deprecatedOptions' | ||
'narg', | ||
'key', | ||
'alias', | ||
'default', | ||
'defaultDescription', | ||
'config', | ||
'choices', | ||
'demandedOptions', | ||
'demandedCommands', | ||
'coerce', | ||
'deprecatedOptions', | ||
]; | ||
@@ -98,4 +140,8 @@ arrayOptions.forEach(k => { | ||
usage = usage ? usage.reset(localLookup) : Usage(self, y18n, shim); | ||
validation = validation ? validation.reset(localLookup) : Validation(self, usage, y18n, shim); | ||
command = command ? command.reset() : Command(self, usage, validation, globalMiddleware, shim); | ||
validation = validation | ||
? validation.reset(localLookup) | ||
: Validation(self, usage, y18n, shim); | ||
command = command | ||
? command.reset() | ||
: Command(self, usage, validation, globalMiddleware, shim); | ||
if (!completion) | ||
@@ -128,3 +174,3 @@ completion = Completion(self, usage, command, shim); | ||
parseContext, | ||
handlerFinishCommand | ||
handlerFinishCommand, | ||
}); | ||
@@ -154,3 +200,3 @@ usage.freeze(); | ||
parseContext, | ||
handlerFinishCommand | ||
handlerFinishCommand, | ||
} = frozen); | ||
@@ -209,3 +255,3 @@ options.configObjects = configObjects; | ||
keys = [].concat(keys); | ||
keys.forEach((key) => { | ||
keys.forEach(key => { | ||
key = sanitizeKey(key); | ||
@@ -278,3 +324,3 @@ options[type].push(key); | ||
if (Array.isArray(key)) { | ||
key.forEach((k) => { | ||
key.forEach(k => { | ||
builder(k, value); | ||
@@ -314,3 +360,3 @@ }); | ||
argsert('[object|string] [string|function] [function]', [key, msg, parseFn], arguments.length); | ||
if ((typeof key === 'object') && !Array.isArray(key)) { | ||
if (typeof key === 'object' && !Array.isArray(key)) { | ||
key = applyExtends(key, cwd, self.getParserConfiguration()['deep-merge-config'] || false, shim); | ||
@@ -325,3 +371,3 @@ options.configObjects = (options.configObjects || []).concat(key); | ||
self.describe(key, msg || usage.deferY18nLookup('Path to JSON config file')); | ||
(Array.isArray(key) ? key : [key]).forEach((k) => { | ||
(Array.isArray(key) ? key : [key]).forEach(k => { | ||
options.config[k] = parseFn || true; | ||
@@ -334,3 +380,3 @@ }); | ||
if (Array.isArray(cmd)) { | ||
cmd.forEach((exampleParams) => self.example(...exampleParams)); | ||
cmd.forEach(exampleParams => self.example(...exampleParams)); | ||
} | ||
@@ -355,3 +401,3 @@ else { | ||
if (Array.isArray(max)) { | ||
max.forEach((key) => { | ||
max.forEach(key => { | ||
assertNotStrictEqual(msg, true, shim); | ||
@@ -371,3 +417,3 @@ demandOption(key, msg); | ||
else if (Array.isArray(keys)) { | ||
keys.forEach((key) => { | ||
keys.forEach(key => { | ||
assertNotStrictEqual(msg, true, shim); | ||
@@ -398,3 +444,3 @@ demandOption(key, msg); | ||
minMsg, | ||
maxMsg | ||
maxMsg, | ||
}; | ||
@@ -474,3 +520,3 @@ return self; | ||
else { | ||
globals.forEach((g) => { | ||
globals.forEach(g => { | ||
if (options.local.indexOf(g) === -1) | ||
@@ -514,3 +560,3 @@ options.local.push(g); | ||
} | ||
catch (noop) { } | ||
catch (_noop) { } | ||
pkgs[npath] = obj || {}; | ||
@@ -555,3 +601,3 @@ return pkgs[npath]; | ||
if (typeof key === 'object') { | ||
Object.keys(key).forEach((k) => { | ||
Object.keys(key).forEach(k => { | ||
self.options(k, key[k]); | ||
@@ -654,5 +700,16 @@ }); | ||
} | ||
const supportedOpts = ['default', 'defaultDescription', 'implies', 'normalize', | ||
'choices', 'conflicts', 'coerce', 'type', 'describe', | ||
'desc', 'description', 'alias']; | ||
const supportedOpts = [ | ||
'default', | ||
'defaultDescription', | ||
'implies', | ||
'normalize', | ||
'choices', | ||
'conflicts', | ||
'coerce', | ||
'type', | ||
'describe', | ||
'desc', | ||
'description', | ||
'alias', | ||
]; | ||
opts = objFilter(opts, (k, v) => { | ||
@@ -665,9 +722,11 @@ let accept = supportedOpts.indexOf(k) !== -1; | ||
const fullCommand = context.fullCommands[context.fullCommands.length - 1]; | ||
const parseOptions = fullCommand ? command.cmdToParseOptions(fullCommand) : { | ||
array: [], | ||
alias: {}, | ||
default: {}, | ||
demand: {} | ||
}; | ||
objectKeys(parseOptions).forEach((pk) => { | ||
const parseOptions = fullCommand | ||
? command.cmdToParseOptions(fullCommand) | ||
: { | ||
array: [], | ||
alias: {}, | ||
default: {}, | ||
demand: {}, | ||
}; | ||
objectKeys(parseOptions).forEach(pk => { | ||
const parseOption = parseOptions[pk]; | ||
@@ -693,3 +752,3 @@ if (Array.isArray(parseOption)) { | ||
const seen = {}; | ||
groups[groupName] = (existing || []).concat(opts).filter((key) => { | ||
groups[groupName] = (existing || []).concat(opts).filter(key => { | ||
if (seen[key]) | ||
@@ -830,3 +889,3 @@ return false; | ||
}; | ||
var exitProcess = true; | ||
let exitProcess = true; | ||
self.exitProcess = function (enabled = true) { | ||
@@ -838,18 +897,2 @@ argsert('[boolean]', [enabled], arguments.length); | ||
self.getExitProcess = () => exitProcess; | ||
var completionCommand = null; | ||
self.completion = function (cmd, desc, fn) { | ||
argsert('[string] [string|boolean|function] [function]', [cmd, desc, fn], arguments.length); | ||
if (typeof desc === 'function') { | ||
fn = desc; | ||
desc = undefined; | ||
} | ||
completionCommand = cmd || completionCommand || 'completion'; | ||
if (!desc && desc !== false) { | ||
desc = 'generate completion script'; | ||
} | ||
self.command(completionCommand, desc); | ||
if (fn) | ||
completion.registerFunction(fn); | ||
return self; | ||
}; | ||
self.showCompletionScript = function ($0, cmd) { | ||
@@ -888,10 +931,2 @@ argsert('[string] [string]', [$0, cmd], arguments.length); | ||
self.getDetectLocale = () => detectLocale; | ||
var hasOutput = false; | ||
var exitError = null; | ||
self.exit = (code, err) => { | ||
hasOutput = true; | ||
exitError = err; | ||
if (exitProcess) | ||
shim.process.exit(code); | ||
}; | ||
const _logger = { | ||
@@ -913,3 +948,3 @@ log(...args) { | ||
output += args.join(' '); | ||
} | ||
}, | ||
}; | ||
@@ -936,3 +971,3 @@ self._getLoggerInstance = () => _logger; | ||
get: () => self._parseArgs(processArgs), | ||
enumerable: true | ||
enumerable: true, | ||
}); | ||
@@ -946,6 +981,6 @@ self._parseArgs = function parseArgs(args, shortCircuit, _calledFromCommand, commandIndex) { | ||
const config = Object.assign({}, options.configuration, { | ||
'populate--': true | ||
'populate--': true, | ||
}); | ||
const parsed = shim.Parser.detailed(args, Object.assign({}, options, { | ||
configuration: Object.assign({ 'parse-positional-numbers': false }, config) | ||
configuration: Object.assign({ 'parse-positional-numbers': false }, config), | ||
})); | ||
@@ -975,7 +1010,8 @@ let argv = parsed.argv; | ||
const skipRecommendation = argv[helpOpt] || requestCompletions; | ||
const skipDefaultCommand = skipRecommendation && (handlerKeys.length > 1 || handlerKeys[0] !== '$0'); | ||
const skipDefaultCommand = skipRecommendation && | ||
(handlerKeys.length > 1 || handlerKeys[0] !== '$0'); | ||
if (argv._.length) { | ||
if (handlerKeys.length) { | ||
let firstUnknownCommand; | ||
for (let i = (commandIndex || 0), cmd; argv._[i] !== undefined; i++) { | ||
for (let i = commandIndex || 0, cmd; argv._[i] !== undefined; i++) { | ||
cmd = String(argv._[i]); | ||
@@ -999,3 +1035,5 @@ if (~handlerKeys.indexOf(cmd) && cmd !== completionCommand) { | ||
} | ||
if (completionCommand && ~argv._.indexOf(completionCommand) && !requestCompletions) { | ||
if (completionCommand && | ||
~argv._.indexOf(completionCommand) && | ||
!requestCompletions) { | ||
if (exitProcess) | ||
@@ -1016,5 +1054,4 @@ setBlocking(true); | ||
const completionArgs = args.slice(args.indexOf(`--${completion.completionKey}`) + 1); | ||
completion.getCompletion(completionArgs, (completions) => { | ||
; | ||
(completions || []).forEach((completion) => { | ||
completion.getCompletion(completionArgs, completions => { | ||
(completions || []).forEach(completion => { | ||
_logger.log(completion); | ||
@@ -1027,3 +1064,3 @@ }); | ||
if (!hasOutput) { | ||
Object.keys(argv).forEach((key) => { | ||
Object.keys(argv).forEach(key => { | ||
if (key === helpOpt && argv[key]) { | ||
@@ -1072,3 +1109,4 @@ if (exitProcess) | ||
} | ||
const parsePositionalNumbers = self.getParserConfiguration()['parse-positional-numbers'] || self.getParserConfiguration()['parse-positional-numbers'] === undefined; | ||
const parsePositionalNumbers = self.getParserConfiguration()['parse-positional-numbers'] || | ||
self.getParserConfiguration()['parse-positional-numbers'] === undefined; | ||
if (parsePositionalNumbers) { | ||
@@ -1090,5 +1128,6 @@ argv = self._parsePositionalNumbers(argv); | ||
self._parsePositionalNumbers = function (argv) { | ||
const args = argv['--'] ? argv['--'] : argv['_']; | ||
const args = argv['--'] ? argv['--'] : argv._; | ||
for (let i = 0, arg; (arg = args[i]) !== undefined; i++) { | ||
if (shim.Parser.looksLikeNumber(arg) && Number.isSafeInteger(Math.floor(parseFloat(`${arg}`)))) { | ||
if (shim.Parser.looksLikeNumber(arg) && | ||
Number.isSafeInteger(Math.floor(parseFloat(`${arg}`)))) { | ||
args[i] = Number(arg); | ||
@@ -1122,3 +1161,7 @@ } | ||
return; | ||
const locale = shim.getEnv('LC_ALL') || shim.getEnv('LC_MESSAGES') || shim.getEnv('LANG') || shim.getEnv('LANGUAGE') || 'en_US'; | ||
const locale = shim.getEnv('LC_ALL') || | ||
shim.getEnv('LC_MESSAGES') || | ||
shim.getEnv('LANG') || | ||
shim.getEnv('LANGUAGE') || | ||
'en_US'; | ||
self.locale(locale.replace(/[.:].*/, '')); | ||
@@ -1132,3 +1175,3 @@ } | ||
export function isYargsInstance(y) { | ||
return !!y && (typeof y._parseArgs === 'function'); | ||
return !!y && typeof y._parseArgs === 'function'; | ||
} |
@@ -5,2 +5,18 @@ # Changelog | ||
## [16.1.0](https://www.github.com/yargs/yargs/compare/v16.0.3...v16.1.0) (2020-10-15) | ||
### Features | ||
* expose hideBin helper for CJS ([#1768](https://www.github.com/yargs/yargs/issues/1768)) ([63e1173](https://www.github.com/yargs/yargs/commit/63e1173bb47dc651c151973a16ef659082a9ae66)) | ||
### Bug Fixes | ||
* **deno:** update types for deno ^1.4.0 ([#1772](https://www.github.com/yargs/yargs/issues/1772)) ([0801752](https://www.github.com/yargs/yargs/commit/080175207d281be63edf90adfe4f0568700b0bf5)) | ||
* **exports:** node 13.0-13.6 require a string fallback ([#1776](https://www.github.com/yargs/yargs/issues/1776)) ([b45c43a](https://www.github.com/yargs/yargs/commit/b45c43a5f64b565c3794f9792150eaeec4e00b69)) | ||
* **modules:** module path was incorrect ([#1759](https://www.github.com/yargs/yargs/issues/1759)) ([95a4a0a](https://www.github.com/yargs/yargs/commit/95a4a0ac573cfe158e6e4bc8c8682ebd1644a198)) | ||
* **positional:** positional strings no longer drop decimals ([#1761](https://www.github.com/yargs/yargs/issues/1761)) ([e1a300f](https://www.github.com/yargs/yargs/commit/e1a300f1293ad821c900284616337f080b207980)) | ||
* make positionals in -- count towards validation ([#1752](https://www.github.com/yargs/yargs/issues/1752)) ([eb2b29d](https://www.github.com/yargs/yargs/commit/eb2b29d34f1a41e0fd6c4e841960e5bfc329dc3c)) | ||
### [16.0.3](https://www.github.com/yargs/yargs/compare/v16.0.2...v16.0.3) (2020-09-10) | ||
@@ -7,0 +23,0 @@ |
{ | ||
"name": "yargs", | ||
"version": "16.0.4-candidate.0", | ||
"version": "16.1.0", | ||
"description": "yargs the modern, pirate-themed, successor to optimist.", | ||
"main": "./index.cjs", | ||
"exports": { | ||
".": { | ||
"import": "./index.mjs", | ||
"require": "./index.cjs" | ||
}, | ||
".": [ | ||
{ | ||
"import": "./index.mjs", | ||
"require": "./index.cjs" | ||
}, | ||
"./index.cjs" | ||
], | ||
"./helpers": { | ||
"import": "./helpers.mjs" | ||
"import": "./helpers.mjs", | ||
"require": "./yargs" | ||
}, | ||
"./yargs": { | ||
"require": "./yargs" | ||
} | ||
"./yargs": [ | ||
{ | ||
"require": "./yargs" | ||
}, | ||
"./yargs" | ||
] | ||
}, | ||
"type": "module", | ||
"module": "./build/index.mjs", | ||
"module": "./index.mjs", | ||
"contributors": [ | ||
@@ -39,9 +46,9 @@ { | ||
"dependencies": { | ||
"cliui": "^7.0.0", | ||
"escalade": "^3.0.2", | ||
"cliui": "^7.0.2", | ||
"escalade": "^3.1.1", | ||
"get-caller-file": "^2.0.5", | ||
"require-directory": "^2.1.1", | ||
"string-width": "^4.2.0", | ||
"y18n": "^5.0.1", | ||
"yargs-parser": "^20.2.0" | ||
"y18n": "^5.0.2", | ||
"yargs-parser": "^20.2.2" | ||
}, | ||
@@ -51,5 +58,3 @@ "devDependencies": { | ||
"@types/mocha": "^8.0.0", | ||
"@types/node": "^14.0.27", | ||
"@typescript-eslint/eslint-plugin": "^3.0.0", | ||
"@typescript-eslint/parser": "^3.0.0", | ||
"@types/node": "^14.11.2", | ||
"@wessberg/rollup-plugin-ts": "^1.3.2", | ||
@@ -63,6 +68,3 @@ "c8": "^7.0.0", | ||
"cross-spawn": "^7.0.0", | ||
"eslint": "^6.8.0", | ||
"eslint-plugin-import": "^2.20.1", | ||
"eslint-plugin-node": "^11.0.0", | ||
"gts": "^2.0.0-alpha.4", | ||
"gts": "^3.0.0", | ||
"hashish": "0.0.4", | ||
@@ -79,4 +81,4 @@ "mocha": "^8.0.0", | ||
"scripts": { | ||
"check": "standardx './*.ts' && standardx '**/*.ts'", | ||
"fix": "standardx --fix './*.ts' && standardx --fix '**/*.ts'", | ||
"fix": "gts fix && npm run fix:js", | ||
"fix:js": "standardx --fix '**/*.mjs' && standardx --fix '**/*.cjs' && standardx --fix './*.mjs' && standardx --fix './*.cjs'", | ||
"posttest": "npm run check", | ||
@@ -91,3 +93,6 @@ "test": "c8 mocha ./test/*.cjs --require ./test/before.cjs --timeout=12000 --check-leaks", | ||
"build:cjs": "rollup -c rollup.config.cjs", | ||
"postbuild:cjs": "rimraf ./build/index.cjs.d.ts" | ||
"postbuild:cjs": "rimraf ./build/index.cjs.d.ts", | ||
"check": "gts lint && npm run check:js", | ||
"check:js": "standardx '**/*.mjs' && standardx '**/*.cjs' && standardx './*.mjs' && standardx './*.cjs'", | ||
"clean": "gts clean" | ||
}, | ||
@@ -102,3 +107,4 @@ "repository": { | ||
"build", | ||
"**/example/**" | ||
"**/example/**", | ||
"**/platform-shims/esm.mjs" | ||
] | ||
@@ -105,0 +111,0 @@ }, |
@@ -24,6 +24,19 @@ <p align="center"> | ||
* commands and (grouped) options (`my-program.js serve --port=5000`). | ||
* a dynamically generated help menu based on your arguments. | ||
* a dynamically generated help menu based on your arguments: | ||
> <img width="400" src="https://raw.githubusercontent.com/yargs/yargs/master/screen.png"> | ||
``` | ||
mocha [spec..] | ||
Run tests with Mocha | ||
Commands | ||
mocha inspect [spec..] Run tests with Mocha [default] | ||
mocha init <path> create a client-side Mocha setup at <path> | ||
Rules & Behavior | ||
--allow-uncaught Allow uncaught errors to propagate [boolean] | ||
--async-only, -A Require all tests to use a callback (async) or | ||
return a Promise [boolean] | ||
``` | ||
* bash-completion shortcuts for commands and options. | ||
@@ -50,3 +63,5 @@ * and [tons more](/docs/api.md). | ||
#!/usr/bin/env node | ||
const {argv} = require('yargs') | ||
const yargs = require('yargs/yargs') | ||
const { hideBin } = require('yargs/helpers') | ||
const argv = yargs(hideBin(process.argv)).argv | ||
@@ -72,3 +87,6 @@ if (argv.ships > 3 && argv.distance < 53.5) { | ||
#!/usr/bin/env node | ||
require('yargs') // eslint-disable-line | ||
const yargs = require('yargs/yargs') | ||
const { hideBin } = require('yargs/helpers') | ||
yargs(hideBin(process.argv)) | ||
.command('serve [port]', 'start the server', (yargs) => { | ||
@@ -114,3 +132,3 @@ yargs | ||
yargs() | ||
yargs(Deno.args) | ||
.command('download <files...>', 'download a list of files', (yargs: YargsType) => { | ||
@@ -125,3 +143,3 @@ return yargs.positional('files', { | ||
.demandCommand(1) | ||
.parse(Deno.args) | ||
.argv | ||
``` | ||
@@ -170,2 +188,3 @@ | ||
* [Customizing Yargs' Parser](/docs/advanced.md#customizing) | ||
* [Bundling yargs](/docs/bundling.md) | ||
* [Contributing](/contributing.md) | ||
@@ -172,0 +191,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
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
302787
21
7027
0
203
Updatedcliui@^7.0.2
Updatedescalade@^3.1.1
Updatedy18n@^5.0.2
Updatedyargs-parser@^20.2.2