Acme.BookStore.HttpApi.Host/node_modules/yargs/lib/argsert.js
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
const command = require('./command')()
const YError = require('./yerror')
const positionName = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']
module.exports = function (expected, callerArguments, length) {
// TODO: should this eventually raise an exception.
try {
// preface the argument description with "cmd", so
// that we can run it through yargs' command parser.
var position = 0
var parsed = {demanded: [], optional: []}
if (typeof expected === 'object') {
length = callerArguments
callerArguments = expected
} else {
parsed = command.parseCommand('cmd ' + expected)
}
const args = [].slice.call(callerArguments)
while (args.length && args[args.length - 1] === undefined) args.pop()
length = length || args.length
if (length < parsed.demanded.length) {
throw new YError('Not enough arguments provided. Expected ' + parsed.demanded.length +
' but received ' + args.length + '.')
}
const totalCommands = parsed.demanded.length + parsed.optional.length
if (length > totalCommands) {
throw new YError('Too many arguments provided. Expected max ' + totalCommands +
' but received ' + length + '.')
}
parsed.demanded.forEach(function (demanded) {
const arg = args.shift()
const observedType = guessType(arg)
const matchingTypes = demanded.cmd.filter(function (type) {
return type === observedType || type === '*'
})
if (matchingTypes.length === 0) argumentTypeError(observedType, demanded.cmd, position, false)
position += 1
})
parsed.optional.forEach(function (optional) {
if (args.length === 0) return
const arg = args.shift()
const observedType = guessType(arg)
const matchingTypes = optional.cmd.filter(function (type) {
return type === observedType || type === '*'
})
if (matchingTypes.length === 0) argumentTypeError(observedType, optional.cmd, position, true)
position += 1
})
} catch (err) {
console.warn(err.stack)
}
}
function guessType (arg) {
后面还有 12 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
