Comparing version 15.4.1 to 16.0.0-alpha.0
@@ -1,17 +0,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.argsert = void 0; | ||
const yerror_1 = require("./yerror"); | ||
const parse_command_1 = require("./parse-command"); | ||
import { YError } from './yerror.js'; | ||
import { parseCommand } from './parse-command.js'; | ||
const positionName = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']; | ||
function argsert(arg1, arg2, arg3) { | ||
export function argsert(arg1, arg2, arg3) { | ||
function parseArgs() { | ||
return typeof arg1 === 'object' | ||
? [{ demanded: [], optional: [] }, arg1, arg2] | ||
: [parse_command_1.parseCommand(`cmd ${arg1}`), arg2, arg3]; | ||
: [parseCommand(`cmd ${arg1}`), arg2, arg3]; | ||
} | ||
// TODO: should this eventually raise an exception. | ||
try { | ||
// preface the argument description with "cmd", so | ||
// that we can run it through yargs' command parser. | ||
let position = 0; | ||
@@ -24,7 +18,7 @@ let [parsed, callerArguments, length] = parseArgs(); | ||
if (length < parsed.demanded.length) { | ||
throw new yerror_1.YError(`Not enough arguments provided. Expected ${parsed.demanded.length} but received ${args.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_1.YError(`Too many arguments provided. Expected max ${totalCommands} but received ${length}.`); | ||
throw new YError(`Too many arguments provided. Expected max ${totalCommands} but received ${length}.`); | ||
} | ||
@@ -54,3 +48,2 @@ parsed.demanded.forEach((demanded) => { | ||
} | ||
exports.argsert = argsert; | ||
function guessType(arg) { | ||
@@ -66,3 +59,3 @@ if (Array.isArray(arg)) { | ||
function argumentTypeError(observedType, allowedTypes, position) { | ||
throw new yerror_1.YError(`Invalid ${positionName[position] || 'manyith'} argument. Expected ${allowedTypes.join(' or ')} but received ${observedType}.`); | ||
throw new YError(`Invalid ${positionName[position] || 'manyith'} argument. Expected ${allowedTypes.join(' or ')} but received ${observedType}.`); | ||
} |
@@ -1,19 +0,9 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isCommandBuilderCallback = exports.isCommandBuilderDefinition = exports.isCommandHandlerDefinition = exports.command = void 0; | ||
const common_types_1 = require("./common-types"); | ||
const is_promise_1 = require("./is-promise"); | ||
const middleware_1 = require("./middleware"); | ||
const parse_command_1 = require("./parse-command"); | ||
const path = require("path"); | ||
const util_1 = require("util"); | ||
const yargs_1 = require("./yargs"); | ||
const requireDirectory = require("require-directory"); | ||
const whichModule = require("which-module"); | ||
const Parser = require("yargs-parser"); | ||
import { assertNotStrictEqual } from './typings/common-types.js'; | ||
import { isPromise } from './utils/is-promise.js'; | ||
import { applyMiddleware, commandMiddlewareFactory } from './middleware.js'; | ||
import { parseCommand } from './parse-command.js'; | ||
import { isYargsInstance } from './yargs-factory.js'; | ||
import whichModule from './utils/which-module.js'; | ||
const DEFAULT_MARKER = /(^\*)|(^\$0)/; | ||
// handles parsing positional arguments, | ||
// and populating argv with said positional | ||
// arguments. | ||
function command(yargs, usage, validation, globalMiddleware = []) { | ||
export function command(yargs, usage, validation, globalMiddleware = [], shim) { | ||
const self = {}; | ||
@@ -25,3 +15,3 @@ let handlers = {}; | ||
let aliases = []; | ||
const middlewares = middleware_1.commandMiddlewareFactory(commandMiddleware); | ||
const middlewares = commandMiddlewareFactory(commandMiddleware); | ||
handler = handler || (() => { }); | ||
@@ -39,3 +29,2 @@ if (Array.isArray(cmd)) { | ||
} | ||
// allow a module to be provided instead of separate builder and handler | ||
if (isCommandBuilderDefinition(builder)) { | ||
@@ -45,7 +34,4 @@ self.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler, builder.middlewares, builder.deprecated); | ||
} | ||
// parse positionals out of cmd string | ||
const parsedCommand = parse_command_1.parseCommand(cmd); | ||
// remove positional args from aliases only | ||
aliases = aliases.map(alias => parse_command_1.parseCommand(alias).cmd); | ||
// check for default and filter out '*'' | ||
const parsedCommand = parseCommand(cmd); | ||
aliases = aliases.map(alias => parseCommand(alias).cmd); | ||
let isDefault = false; | ||
@@ -59,6 +45,4 @@ const parsedAliases = [parsedCommand.cmd].concat(aliases).filter((c) => { | ||
}); | ||
// standardize on $0 for default command. | ||
if (parsedAliases.length === 0 && isDefault) | ||
parsedAliases.push('$0'); | ||
// shift cmd and aliases after filtering out '*' | ||
if (isDefault) { | ||
@@ -69,3 +53,2 @@ parsedCommand.cmd = parsedAliases[0]; | ||
} | ||
// populate aliasMap | ||
aliases.forEach((alias) => { | ||
@@ -92,20 +75,12 @@ aliasMap[alias] = parsedCommand.cmd; | ||
opts = opts || {}; | ||
// disable recursion to support nested directories of subcommands | ||
if (typeof opts.recurse !== 'boolean') | ||
opts.recurse = false; | ||
// exclude 'json', 'coffee' from require-directory defaults | ||
if (!Array.isArray(opts.extensions)) | ||
opts.extensions = ['js']; | ||
// allow consumer to define their own visitor function | ||
const parentVisit = typeof opts.visit === 'function' ? opts.visit : (o) => o; | ||
// call addHandler via visitor function | ||
opts.visit = function visit(obj, joined, filename) { | ||
const visited = parentVisit(obj, joined, filename); | ||
// allow consumer to skip modules with their own visitor | ||
if (visited) { | ||
// check for cyclic reference | ||
// each command file path should only be seen once per execution | ||
if (~context.files.indexOf(joined)) | ||
return visited; | ||
// keep track of visited files in context.files | ||
context.files.push(joined); | ||
@@ -116,15 +91,12 @@ self.addHandler(visited); | ||
}; | ||
requireDirectory({ require: req, filename: callerFile }, dir, opts); | ||
shim.requireDirectory({ require: req, filename: callerFile }, dir, opts); | ||
}; | ||
// lookup module object from require()d command and derive name | ||
// if module was not require()d and no name given, throw error | ||
function moduleName(obj) { | ||
const mod = whichModule(obj); | ||
if (!mod) | ||
throw new Error(`No command name given for module: ${util_1.inspect(obj)}`); | ||
throw new Error(`No command name given for module: ${shim.inspect(obj)}`); | ||
return commandFromFilename(mod.filename); | ||
} | ||
// derive command name from filename | ||
function commandFromFilename(filename) { | ||
return path.basename(filename, path.extname(filename)); | ||
return shim.path.basename(filename, shim.path.extname(filename)); | ||
} | ||
@@ -135,3 +107,3 @@ function extractDesc({ describe, description, desc }) { | ||
return test; | ||
common_types_1.assertNotStrictEqual(test, true); | ||
assertNotStrictEqual(test, true, shim); | ||
} | ||
@@ -149,3 +121,2 @@ return false; | ||
const parentCommands = currentContext.commands.slice(); | ||
// what does yargs look like after the builder is run? | ||
let innerArgv = parsed.argv; | ||
@@ -159,6 +130,4 @@ let positionalMap = {}; | ||
if (isCommandBuilderCallback(builder)) { | ||
// a function can be provided, which builds | ||
// up a yargs chain and possibly returns it. | ||
const builderOutput = builder(yargs.reset(parsed.aliases)); | ||
const innerYargs = yargs_1.isYargsInstance(builderOutput) ? builderOutput : yargs; | ||
const innerYargs = isYargsInstance(builderOutput) ? builderOutput : yargs; | ||
if (shouldUpdateUsage(innerYargs)) { | ||
@@ -171,4 +140,2 @@ innerYargs.getUsageInstance().usage(usageFromParentCommandsCommandHandler(parentCommands, commandHandler), commandHandler.description); | ||
else if (isCommandBuilderOptionDefinitions(builder)) { | ||
// as a short hand, an object can instead be provided, specifying | ||
// the options that a command takes. | ||
const innerYargs = yargs.reset(parsed.aliases); | ||
@@ -188,5 +155,3 @@ if (shouldUpdateUsage(innerYargs)) { | ||
const middlewares = globalMiddleware.slice(0).concat(commandHandler.middlewares); | ||
middleware_1.applyMiddleware(innerArgv, yargs, middlewares, true); | ||
// we apply validation post-hoc, so that custom | ||
// checks get passed populated positional arguments. | ||
applyMiddleware(innerArgv, yargs, middlewares, true); | ||
if (!yargs._hasOutput()) { | ||
@@ -197,10 +162,8 @@ yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error, !command); | ||
yargs._setHasOutput(); | ||
// to simplify the parsing of positionals in commands, | ||
// we temporarily populate '--' rather than _, with arguments | ||
const populateDoubleDash = !!yargs.getOptions().configuration['populate--']; | ||
if (!populateDoubleDash) | ||
yargs._copyDoubleDash(innerArgv); | ||
innerArgv = middleware_1.applyMiddleware(innerArgv, yargs, middlewares, false); | ||
innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false); | ||
let handlerResult; | ||
if (is_promise_1.isPromise(innerArgv)) { | ||
if (isPromise(innerArgv)) { | ||
handlerResult = innerArgv.then(argv => commandHandler.handler(argv)); | ||
@@ -212,3 +175,3 @@ } | ||
const handlerFinishCommand = yargs.getHandlerFinishCommand(); | ||
if (is_promise_1.isPromise(handlerResult)) { | ||
if (isPromise(handlerResult)) { | ||
yargs.getUsageInstance().cacheHelpMessage(); | ||
@@ -226,3 +189,2 @@ handlerResult | ||
catch (err) { | ||
// fail's throwing would cause an unhandled rejection. | ||
} | ||
@@ -260,5 +222,4 @@ }) | ||
self.runDefaultBuilderOn = function (yargs) { | ||
common_types_1.assertNotStrictEqual(defaultCommand, undefined); | ||
assertNotStrictEqual(defaultCommand, undefined, shim); | ||
if (shouldUpdateUsage(yargs)) { | ||
// build the root-level command string from the default string. | ||
const commandString = DEFAULT_MARKER.test(defaultCommand.original) | ||
@@ -278,6 +239,4 @@ ? defaultCommand.original : defaultCommand.original.replace(/^[^[\]<>]*/, '$0 '); | ||
}; | ||
// transcribe all positional arguments "command <foo> <bar> [apple]" | ||
// onto argv. | ||
function populatePositionals(commandHandler, argv, context) { | ||
argv._ = argv._.slice(context.commands.length); // nuke the current commands | ||
argv._ = argv._.slice(context.commands.length); | ||
const demanded = commandHandler.demanded.slice(0); | ||
@@ -295,3 +254,3 @@ const optional = commandHandler.optional.slice(0); | ||
} | ||
argv._ = context.commands.concat(argv._); | ||
argv._ = context.commands.concat(argv._.map(a => '' + a)); | ||
postProcessPositionals(argv, positionalMap, self.cmdToParseOptions(commandHandler.original)); | ||
@@ -310,7 +269,3 @@ return positionalMap; | ||
} | ||
// we run yargs-parser against the positional arguments | ||
// applying the same parsing logic used for flags. | ||
function postProcessPositionals(argv, positionalMap, parseOptions) { | ||
// combine the parsing hints we've inferred from the command | ||
// string with explicitly configured parsing hints. | ||
const options = Object.assign({}, yargs.getOptions()); | ||
@@ -322,3 +277,3 @@ options.default = Object.assign(parseOptions.default, options.default); | ||
options.array = options.array.concat(parseOptions.array); | ||
delete options.config; // don't load config when processing positionals. | ||
delete options.config; | ||
const unparsed = []; | ||
@@ -333,3 +288,2 @@ Object.keys(positionalMap).forEach((key) => { | ||
}); | ||
// short-circuit parse. | ||
if (!unparsed.length) | ||
@@ -340,3 +294,3 @@ return; | ||
}); | ||
const parsed = Parser.detailed(unparsed, Object.assign({}, options, { | ||
const parsed = shim.Parser.detailed(unparsed, Object.assign({}, options, { | ||
configuration: config | ||
@@ -348,4 +302,2 @@ })); | ||
else { | ||
// only copy over positional keys (don't overwrite | ||
// flag arguments that were already parsed). | ||
const positionalKeys = Object.keys(positionalMap); | ||
@@ -357,4 +309,2 @@ Object.keys(positionalMap).forEach((key) => { | ||
if (positionalKeys.indexOf(key) !== -1) { | ||
// any new aliases need to be placed in positionalMap, which | ||
// is used for validation. | ||
if (!positionalMap[key]) | ||
@@ -374,3 +324,3 @@ positionalMap[key] = parsed.argv[key]; | ||
}; | ||
const parsed = parse_command_1.parseCommand(cmdString); | ||
const parsed = parseCommand(cmdString); | ||
parsed.demanded.forEach((d) => { | ||
@@ -401,6 +351,2 @@ const [cmd, ...aliases] = d.cmd; | ||
}; | ||
// used by yargs.parse() to freeze | ||
// the state of commands such that | ||
// we can apply .parse() multiple times | ||
// with the same yargs instance. | ||
const frozens = []; | ||
@@ -416,3 +362,3 @@ self.freeze = () => { | ||
const frozen = frozens.pop(); | ||
common_types_1.assertNotStrictEqual(frozen, undefined); | ||
assertNotStrictEqual(frozen, undefined, shim); | ||
({ | ||
@@ -426,8 +372,6 @@ handlers, | ||
} | ||
exports.command = command; | ||
function isCommandHandlerDefinition(cmd) { | ||
export function isCommandHandlerDefinition(cmd) { | ||
return typeof cmd === 'object'; | ||
} | ||
exports.isCommandHandlerDefinition = isCommandHandlerDefinition; | ||
function isCommandBuilderDefinition(builder) { | ||
export function isCommandBuilderDefinition(builder) { | ||
return typeof builder === 'object' && | ||
@@ -437,9 +381,7 @@ !!builder.builder && | ||
} | ||
exports.isCommandBuilderDefinition = isCommandBuilderDefinition; | ||
function isCommandBuilderCallback(builder) { | ||
export function isCommandBuilderCallback(builder) { | ||
return typeof builder === 'function'; | ||
} | ||
exports.isCommandBuilderCallback = isCommandBuilderCallback; | ||
function isCommandBuilderOptionDefinitions(builder) { | ||
return typeof builder === 'object'; | ||
} |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.completionZshTemplate = exports.completionShTemplate = void 0; | ||
exports.completionShTemplate = `###-begin-{{app_name}}-completions-### | ||
export const completionShTemplate = `###-begin-{{app_name}}-completions-### | ||
# | ||
@@ -33,3 +30,3 @@ # yargs command completion script | ||
`; | ||
exports.completionZshTemplate = `###-begin-{{app_name}}-completions-### | ||
export const completionZshTemplate = `###-begin-{{app_name}}-completions-### | ||
# | ||
@@ -36,0 +33,0 @@ # yargs command completion script |
@@ -1,13 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.completion = void 0; | ||
const command_1 = require("./command"); | ||
const templates = require("./completion-templates"); | ||
const is_promise_1 = require("./is-promise"); | ||
const parse_command_1 = require("./parse-command"); | ||
const path = require("path"); | ||
const common_types_1 = require("./common-types"); | ||
// add bash completions to your | ||
// yargs-powered applications. | ||
function completion(yargs, usage, command) { | ||
import { isCommandBuilderCallback } from './command.js'; | ||
import { assertNotStrictEqual } from './typings/common-types.js'; | ||
import * as templates from './completion-templates.js'; | ||
import { isPromise } from './utils/is-promise.js'; | ||
import { parseCommand } from './parse-command.js'; | ||
export function completion(yargs, usage, command, shim) { | ||
const self = { | ||
@@ -20,6 +14,4 @@ completionKey: 'get-yargs-completions' | ||
}; | ||
const zshShell = (process.env.SHELL && process.env.SHELL.indexOf('zsh') !== -1) || | ||
(process.env.ZSH_NAME && process.env.ZSH_NAME.indexOf('zsh') !== -1); | ||
// get a list of completion commands. | ||
// 'args' is the array of strings from the line to be completed | ||
const zshShell = (shim.getEnv('SHELL') && shim.getEnv('SHELL').indexOf('zsh') !== -1) || | ||
(shim.getEnv('ZSH_NAME') && shim.getEnv('ZSH_NAME').indexOf('zsh') !== -1); | ||
self.getCompletion = function getCompletion(args, done) { | ||
@@ -30,21 +22,16 @@ const completions = []; | ||
const parentCommands = yargs.getContext().commands; | ||
// a custom completion function can be provided | ||
// to completion(). | ||
function runCompletionFunction(argv) { | ||
common_types_1.assertNotStrictEqual(completionFunction, null); | ||
assertNotStrictEqual(completionFunction, null, shim); | ||
if (isSyncCompletionFunction(completionFunction)) { | ||
const result = completionFunction(current, argv); | ||
// promise based completion function. | ||
if (is_promise_1.isPromise(result)) { | ||
if (isPromise(result)) { | ||
return result.then((list) => { | ||
process.nextTick(() => { done(list); }); | ||
shim.process.nextTick(() => { done(list); }); | ||
}).catch((err) => { | ||
process.nextTick(() => { throw err; }); | ||
shim.process.nextTick(() => { throw err; }); | ||
}); | ||
} | ||
// synchronous completion function. | ||
return done(result); | ||
} | ||
else { | ||
// asynchronous completion function | ||
return completionFunction(current, argv, (completions) => { | ||
@@ -56,3 +43,3 @@ done(completions); | ||
if (completionFunction) { | ||
return is_promise_1.isPromise(argv) ? argv.then(runCompletionFunction) : runCompletionFunction(argv); | ||
return isPromise(argv) ? argv.then(runCompletionFunction) : runCompletionFunction(argv); | ||
} | ||
@@ -63,3 +50,3 @@ const handlers = command.getCommandHandlers(); | ||
const builder = handlers[args[i]].builder; | ||
if (command_1.isCommandBuilderCallback(builder)) { | ||
if (isCommandBuilderCallback(builder)) { | ||
const y = yargs.reset(); | ||
@@ -73,3 +60,3 @@ builder(y); | ||
usage.getCommands().forEach((usageCommand) => { | ||
const commandName = parse_command_1.parseCommand(usageCommand[0]).cmd; | ||
const commandName = parseCommand(usageCommand[0]).cmd; | ||
if (args.indexOf(commandName) === -1) { | ||
@@ -91,3 +78,2 @@ if (!zshShell) { | ||
const negable = !!options.configuration['boolean-negation'] && options.boolean.includes(key); | ||
// If the key and its aliases aren't in 'args', add the key to 'completions' | ||
let keyAndAliases = [key].concat(aliases[key] || []); | ||
@@ -118,7 +104,5 @@ if (negable) | ||
}; | ||
// generate the completion script to add to your .bashrc. | ||
self.generateCompletionScript = function generateCompletionScript($0, cmd) { | ||
let script = zshShell ? templates.completionZshTemplate : templates.completionShTemplate; | ||
const name = path.basename($0); | ||
// add ./to applications not yet installed as bin. | ||
const name = shim.path.basename($0); | ||
if ($0.match(/\.js$/)) | ||
@@ -130,5 +114,2 @@ $0 = `./${$0}`; | ||
}; | ||
// register a function to perform your own custom | ||
// completions., this function can be either | ||
// synchrnous or asynchronous. | ||
let completionFunction = null; | ||
@@ -140,5 +121,4 @@ self.registerFunction = (fn) => { | ||
} | ||
exports.completion = completion; | ||
function isSyncCompletionFunction(completionFunction) { | ||
return completionFunction.length < 3; | ||
} |
@@ -1,9 +0,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.applyMiddleware = exports.commandMiddlewareFactory = exports.globalMiddlewareFactory = void 0; | ||
const argsert_1 = require("./argsert"); | ||
const is_promise_1 = require("./is-promise"); | ||
function globalMiddlewareFactory(globalMiddleware, context) { | ||
import { argsert } from './argsert.js'; | ||
import { isPromise } from './utils/is-promise.js'; | ||
export function globalMiddlewareFactory(globalMiddleware, context) { | ||
return function (callback, applyBeforeValidation = false) { | ||
argsert_1.argsert('<array|function> [boolean]', [callback, applyBeforeValidation], arguments.length); | ||
argsert('<array|function> [boolean]', [callback, applyBeforeValidation], arguments.length); | ||
if (Array.isArray(callback)) { | ||
@@ -25,4 +22,3 @@ for (let i = 0; i < callback.length; i++) { | ||
} | ||
exports.globalMiddlewareFactory = globalMiddlewareFactory; | ||
function commandMiddlewareFactory(commandMiddleware) { | ||
export function commandMiddlewareFactory(commandMiddleware) { | ||
if (!commandMiddleware) | ||
@@ -35,4 +31,3 @@ return []; | ||
} | ||
exports.commandMiddlewareFactory = commandMiddlewareFactory; | ||
function applyMiddleware(argv, yargs, middlewares, beforeValidation) { | ||
export function applyMiddleware(argv, yargs, middlewares, beforeValidation) { | ||
const beforeValidationError = new Error('middleware cannot return a promise when applyBeforeValidation is true'); | ||
@@ -44,3 +39,3 @@ return middlewares | ||
} | ||
if (is_promise_1.isPromise(acc)) { | ||
if (isPromise(acc)) { | ||
return acc | ||
@@ -52,5 +47,5 @@ .then(initialObj => Promise.all([initialObj, middleware(initialObj, yargs)])) | ||
const result = middleware(acc, yargs); | ||
if (beforeValidation && is_promise_1.isPromise(result)) | ||
if (beforeValidation && isPromise(result)) | ||
throw beforeValidationError; | ||
return is_promise_1.isPromise(result) | ||
return isPromise(result) | ||
? result.then(middlewareObj => Object.assign(acc, middlewareObj)) | ||
@@ -61,2 +56,1 @@ : Object.assign(acc, result); | ||
} | ||
exports.applyMiddleware = applyMiddleware; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseCommand = void 0; | ||
function parseCommand(cmd) { | ||
export function parseCommand(cmd) { | ||
const extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' '); | ||
@@ -36,2 +33,1 @@ const splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/); | ||
} | ||
exports.parseCommand = parseCommand; |
@@ -1,17 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.usage = void 0; | ||
// this file handles outputting usage instructions, | ||
// failures, etc. keeps logging in one place. | ||
const common_types_1 = require("./common-types"); | ||
const obj_filter_1 = require("./obj-filter"); | ||
const path = require("path"); | ||
const yerror_1 = require("./yerror"); | ||
const decamelize = require("decamelize"); | ||
const setBlocking = require("set-blocking"); | ||
const stringWidth = require("string-width"); | ||
function usage(yargs, y18n) { | ||
import { assertNotStrictEqual } from './typings/common-types.js'; | ||
import { objFilter } from './utils/obj-filter.js'; | ||
import { YError } from './yerror.js'; | ||
import setBlocking from './utils/set-blocking.js'; | ||
export function usage(yargs, y18n, shim) { | ||
const __ = y18n.__; | ||
const self = {}; | ||
// methods for ouputting/building failure message. | ||
const fails = []; | ||
@@ -43,3 +34,2 @@ self.failFn = function failFn(f) { | ||
setBlocking(true); | ||
// don't output failure message more than once | ||
if (!failureOutput) { | ||
@@ -59,3 +49,3 @@ failureOutput = true; | ||
} | ||
err = err || new yerror_1.YError(msg); | ||
err = err || new YError(msg); | ||
if (yargs.getExitProcess()) { | ||
@@ -72,3 +62,2 @@ return yargs.exit(1); | ||
}; | ||
// methods for ouputting/building help (usage) message. | ||
let usages = []; | ||
@@ -101,3 +90,2 @@ let usageDisabled = false; | ||
self.command = function command(cmd, description, isDefault, aliases, deprecated = false) { | ||
// the last default wins, so cancel out any previously set default | ||
if (isDefault) { | ||
@@ -152,4 +140,3 @@ commands = commands.map((cmdArray) => { | ||
normalizeAliases(); | ||
// handle old demanded API | ||
const base$0 = yargs.customScriptName ? yargs.$0 : path.basename(yargs.$0); | ||
const base$0 = yargs.customScriptName ? yargs.$0 : shim.path.basename(yargs.$0); | ||
const demandedOptions = yargs.getDemandedOptions(); | ||
@@ -172,10 +159,8 @@ const demandedCommands = yargs.getDemandedCommands(); | ||
const theWrap = getWrap(); | ||
const ui = require('cliui')({ | ||
const ui = shim.cliui({ | ||
width: theWrap, | ||
wrap: !!theWrap | ||
}); | ||
// the usage string. | ||
if (!usageDisabled) { | ||
if (usages.length) { | ||
// user-defined usage. | ||
usages.forEach((usage) => { | ||
@@ -191,3 +176,2 @@ ui.div(`${usage[0].replace(/\$0/g, base$0)}`); | ||
let u = null; | ||
// demonstrate how commands are used. | ||
if (demandedCommands._) { | ||
@@ -202,4 +186,2 @@ u = `${base$0} <${__('command')}>\n`; | ||
} | ||
// your application's commands, i.e., non-option | ||
// arguments populated in '_'. | ||
if (commands.length) { | ||
@@ -213,3 +195,3 @@ ui.div(__('Commands:')); | ||
commands.forEach((command) => { | ||
const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}`; // drop $0 from default commands. | ||
const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}`; | ||
ui.span({ | ||
@@ -243,9 +225,5 @@ text: commandString, | ||
} | ||
// perform some cleanup on the keys array, making it | ||
// only include top-level keys not their aliases. | ||
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)); | ||
// populate 'Options:' group with any keys that have not | ||
// explicitly had a group set. | ||
const defaultGroup = __('Options:'); | ||
@@ -255,8 +233,6 @@ if (!groups[defaultGroup]) | ||
addUngroupedKeys(keys, options.alias, groups, defaultGroup); | ||
// display 'Options:' table along with any custom tables: | ||
Object.keys(groups).forEach((groupName) => { | ||
if (!groups[groupName].length) | ||
return; | ||
// if we've grouped the key 'f', but 'f' aliases 'foobar', | ||
// normalizedKeys should contain only 'foobar'. | ||
const isLongSwitch = (sw) => /^--/.test(getText(sw)); | ||
const displayedGroups = Object.keys(groups) | ||
.filter(groupName => groups[groupName].length > 0) | ||
.map(groupName => { | ||
const normalizedKeys = groups[groupName].filter(filterHiddenOptions).map((key) => { | ||
@@ -271,18 +247,13 @@ if (~aliasKeys.indexOf(key)) | ||
}); | ||
if (normalizedKeys.length < 1) | ||
return; | ||
ui.div(groupName); | ||
// actually generate the switches string --foo, -f, --bar. | ||
return { groupName, normalizedKeys }; | ||
}) | ||
.filter(({ normalizedKeys }) => normalizedKeys.length > 0) | ||
.map(({ groupName, normalizedKeys }) => { | ||
const switches = normalizedKeys.reduce((acc, key) => { | ||
acc[key] = [key].concat(options.alias[key] || []) | ||
.map(sw => { | ||
// for the special positional group don't | ||
// add '--' or '-' prefix. | ||
if (groupName === self.getPositionalGroupName()) | ||
return sw; | ||
else { | ||
return ( | ||
// matches yargs-parser logic in which single-digits | ||
// aliases declared with a boolean type are now valid | ||
/^[0-9]$/.test(sw) | ||
return (/^[0-9]$/.test(sw) | ||
? ~options.boolean.indexOf(key) ? '-' : '--' | ||
@@ -292,5 +263,24 @@ : sw.length > 1 ? '--' : '-') + sw; | ||
}) | ||
.sort((sw1, sw2) => isLongSwitch(sw1) === isLongSwitch(sw2) ? 0 : (isLongSwitch(sw1) ? 1 : -1)) | ||
.join(', '); | ||
return acc; | ||
}, {}); | ||
return { groupName, normalizedKeys, switches }; | ||
}); | ||
const shortSwitchesUsed = displayedGroups | ||
.filter(({ groupName }) => groupName !== self.getPositionalGroupName()) | ||
.some(({ normalizedKeys, switches }) => !normalizedKeys.every(key => isLongSwitch(switches[key]))); | ||
if (shortSwitchesUsed) { | ||
displayedGroups | ||
.filter(({ groupName }) => groupName !== self.getPositionalGroupName()) | ||
.forEach(({ normalizedKeys, switches }) => { | ||
normalizedKeys.forEach(key => { | ||
if (isLongSwitch(switches[key])) { | ||
switches[key] = addIndentation(switches[key], '-x, '.length); | ||
} | ||
}); | ||
}); | ||
} | ||
displayedGroups.forEach(({ groupName, normalizedKeys, switches }) => { | ||
ui.div(groupName); | ||
normalizedKeys.forEach((key) => { | ||
@@ -324,3 +314,3 @@ const kswitch = switches[key]; | ||
].filter(Boolean).join(' '); | ||
ui.span({ text: kswitch, padding: [0, 2, 0, 2], width: maxWidth(switches, theWrap) + 4 }, desc); | ||
ui.span({ text: getText(kswitch), padding: [0, 2, 0, 2 + getIndentation(kswitch)], width: maxWidth(switches, theWrap) + 4 }, desc); | ||
if (extra) | ||
@@ -333,3 +323,2 @@ ui.div({ text: extra, padding: [0, 0, 0, 2], align: 'right' }); | ||
}); | ||
// describe some common use-cases for your application. | ||
if (examples.length) { | ||
@@ -359,3 +348,2 @@ ui.div(__('Examples:')); | ||
} | ||
// the usage string. | ||
if (epilogs.length > 0) { | ||
@@ -365,11 +353,6 @@ const e = epilogs.map(epilog => epilog.replace(/\$0/g, base$0)).join('\n'); | ||
} | ||
// Remove the trailing white spaces | ||
return ui.toString().replace(/\s*$/, ''); | ||
}; | ||
// return the maximum width of a string | ||
// in the left-hand column of a table. | ||
function maxWidth(table, theWrap, modifier) { | ||
let width = 0; | ||
// table might be of the form [leftColumn], | ||
// or {key: leftColumn} | ||
if (!Array.isArray(table)) { | ||
@@ -379,6 +362,4 @@ table = Object.values(table).map(v => [v]); | ||
table.forEach((v) => { | ||
width = Math.max(stringWidth(modifier ? `${modifier} ${v[0]}` : v[0]), width); | ||
width = Math.max(shim.stringWidth(modifier ? `${modifier} ${getText(v[0])}` : getText(v[0])) + getIndentation(v[0]), width); | ||
}); | ||
// if we've enabled 'wrap' we should limit | ||
// the max-width of the left-column. | ||
if (theWrap) | ||
@@ -388,6 +369,3 @@ width = Math.min(width, parseInt((theWrap * 0.5).toString(), 10)); | ||
} | ||
// make sure any options set for aliases, | ||
// are copied to the keys being aliased. | ||
function normalizeAliases() { | ||
// handle old demanded API | ||
const demandedOptions = yargs.getDemandedOptions(); | ||
@@ -397,9 +375,6 @@ const options = yargs.getOptions(); | ||
options.alias[key].forEach((alias) => { | ||
// copy descriptions. | ||
if (descriptions[alias]) | ||
self.describe(key, descriptions[alias]); | ||
// copy demanded. | ||
if (alias in demandedOptions) | ||
yargs.demandOption(key, demandedOptions[alias]); | ||
// type messages. | ||
if (~options.boolean.indexOf(alias)) | ||
@@ -420,4 +395,2 @@ yargs.boolean(key); | ||
} | ||
// if yargs is executing an async handler, we take a snapshot of the | ||
// help message to display on failure: | ||
let cachedHelpMessage; | ||
@@ -427,9 +400,5 @@ self.cacheHelpMessage = function () { | ||
}; | ||
// however this snapshot must be cleared afterwards | ||
// not to be be used by next calls to parse | ||
self.clearCachedHelpMessage = function () { | ||
cachedHelpMessage = undefined; | ||
}; | ||
// given a set of keys, place any keys that are | ||
// ungrouped under the 'Options:' grouping. | ||
function addUngroupedKeys(keys, aliases, groups, defaultGroup) { | ||
@@ -460,3 +429,3 @@ let groupedKeys = []; | ||
self.functionDescription = (fn) => { | ||
const description = fn.name ? decamelize(fn.name, '-') : __('generated-value'); | ||
const description = fn.name ? shim.Parser.decamelize(fn.name, '-') : __('generated-value'); | ||
return ['(', description, ')'].join(''); | ||
@@ -477,4 +446,2 @@ }; | ||
}; | ||
// format the default-value-string displayed in | ||
// the right-hand column. | ||
function defaultString(value, defaultDescription) { | ||
@@ -501,9 +468,6 @@ let string = `[${__('default:')} `; | ||
} | ||
// guess the width of the console window, max-width 80. | ||
function windowWidth() { | ||
const maxWidth = 80; | ||
// CI is not a TTY | ||
/* c8 ignore next 2 */ | ||
if (typeof process === 'object' && process.stdout && process.stdout.columns) { | ||
return Math.min(maxWidth, process.stdout.columns); | ||
if (shim.process.stdColumns) { | ||
return Math.min(maxWidth, shim.process.stdColumns); | ||
} | ||
@@ -514,3 +478,2 @@ else { | ||
} | ||
// logic for displaying application version. | ||
let version = null; | ||
@@ -525,4 +488,2 @@ self.version = (ver) => { | ||
self.reset = function reset(localLookup) { | ||
// do not reset wrap here | ||
// do not reset fails here | ||
failMessage = null; | ||
@@ -535,3 +496,3 @@ failureOutput = false; | ||
commands = []; | ||
descriptions = obj_filter_1.objFilter(descriptions, k => !localLookup[k]); | ||
descriptions = objFilter(descriptions, k => !localLookup[k]); | ||
return self; | ||
@@ -554,3 +515,3 @@ }; | ||
const frozen = frozens.pop(); | ||
common_types_1.assertNotStrictEqual(frozen, undefined); | ||
assertNotStrictEqual(frozen, undefined, shim); | ||
({ | ||
@@ -569,2 +530,15 @@ failMessage, | ||
} | ||
exports.usage = usage; | ||
function isIndentedText(text) { | ||
return typeof text === 'object'; | ||
} | ||
function addIndentation(text, indent) { | ||
return isIndentedText(text) | ||
? { text: text.text, indentation: text.indentation + indent } | ||
: { text, indentation: indent }; | ||
} | ||
function getIndentation(text) { | ||
return isIndentedText(text) ? text.indentation : 0; | ||
} | ||
function getText(text) { | ||
return isIndentedText(text) ? text.text : text; | ||
} |
@@ -1,20 +0,12 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validation = void 0; | ||
const argsert_1 = require("./argsert"); | ||
const common_types_1 = require("./common-types"); | ||
const levenshtein_1 = require("./levenshtein"); | ||
const obj_filter_1 = require("./obj-filter"); | ||
import { argsert } from './argsert.js'; | ||
import { assertNotStrictEqual } from './typings/common-types.js'; | ||
import { levenshtein as distance } from './utils/levenshtein.js'; | ||
import { objFilter } from './utils/obj-filter.js'; | ||
const specialKeys = ['$0', '--', '_']; | ||
// validation-type-stuff, missing params, | ||
// bad implications, custom checks. | ||
function validation(yargs, usage, y18n) { | ||
export function validation(yargs, usage, y18n, shim) { | ||
const __ = y18n.__; | ||
const __n = y18n.__n; | ||
const self = {}; | ||
// validate appropriate # of non-option | ||
// arguments were provided, i.e., '_'. | ||
self.nonOptionCount = function nonOptionCount(argv) { | ||
const demandedCommands = yargs.getDemandedCommands(); | ||
// don't count currently executing commands | ||
const _s = argv._.length - yargs.getContext().commands.length; | ||
@@ -24,5 +16,3 @@ if (demandedCommands._ && (_s < demandedCommands._.min || _s > demandedCommands._.max)) { | ||
if (demandedCommands._.minMsg !== undefined) { | ||
usage.fail( | ||
// replace $0 with observed, $1 with expected. | ||
demandedCommands._.minMsg | ||
usage.fail(demandedCommands._.minMsg | ||
? demandedCommands._.minMsg.replace(/\$0/g, _s.toString()).replace(/\$1/, demandedCommands._.min.toString()) | ||
@@ -32,3 +22,3 @@ : null); | ||
else { | ||
usage.fail(__n('Not enough non-option arguments: got %s, need at least %s', 'Not enough non-option arguments: got %s, need at least %s', _s, _s, demandedCommands._.min)); | ||
usage.fail(__n('Not enough non-option arguments: got %s, need at least %s', 'Not enough non-option arguments: got %s, need at least %s', _s, _s.toString(), demandedCommands._.min.toString())); | ||
} | ||
@@ -38,5 +28,3 @@ } | ||
if (demandedCommands._.maxMsg !== undefined) { | ||
usage.fail( | ||
// replace $0 with observed, $1 with expected. | ||
demandedCommands._.maxMsg | ||
usage.fail(demandedCommands._.maxMsg | ||
? demandedCommands._.maxMsg.replace(/\$0/g, _s.toString()).replace(/\$1/, demandedCommands._.max.toString()) | ||
@@ -46,3 +34,3 @@ : null); | ||
else { | ||
usage.fail(__n('Too many non-option arguments: got %s, maximum of %s', 'Too many non-option arguments: got %s, maximum of %s', _s, _s, demandedCommands._.max)); | ||
usage.fail(__n('Too many non-option arguments: got %s, maximum of %s', 'Too many non-option arguments: got %s, maximum of %s', _s, _s.toString(), demandedCommands._.max.toString())); | ||
} | ||
@@ -52,4 +40,2 @@ } | ||
}; | ||
// validate the appropriate # of <required> | ||
// positional arguments were provided: | ||
self.positionalCount = function positionalCount(required, observed) { | ||
@@ -60,3 +46,2 @@ if (observed < required) { | ||
}; | ||
// make sure all the required arguments are present. | ||
self.requiredArguments = function requiredArguments(argv) { | ||
@@ -83,3 +68,2 @@ const demandedOptions = yargs.getDemandedOptions(); | ||
}; | ||
// check for unknown arguments (strict-mode). | ||
self.unknownArguments = function unknownArguments(argv, aliases, positionalMap, isDefaultCommand) { | ||
@@ -99,4 +83,4 @@ const commandKeys = yargs.getCommandInstance().getCommands(); | ||
argv._.slice(currentContext.commands.length).forEach((key) => { | ||
if (commandKeys.indexOf(key) === -1) { | ||
unknown.push(key); | ||
if (commandKeys.indexOf('' + key) === -1) { | ||
unknown.push('' + key); | ||
} | ||
@@ -115,4 +99,4 @@ }); | ||
argv._.slice(currentContext.commands.length).forEach((key) => { | ||
if (commandKeys.indexOf(key) === -1) { | ||
unknown.push(key); | ||
if (commandKeys.indexOf('' + key) === -1) { | ||
unknown.push('' + key); | ||
} | ||
@@ -129,4 +113,2 @@ }); | ||
}; | ||
// check for a key that is not an alias, or for which every alias is new, | ||
// implying that it was invented by the parser, e.g., during camelization | ||
self.isValidAndSomeAliasIsNotNew = function isValidAndSomeAliasIsNotNew(key, aliases) { | ||
@@ -144,3 +126,2 @@ if (!Object.prototype.hasOwnProperty.call(aliases, key)) { | ||
}; | ||
// validate arguments limited to enumerated choices | ||
self.limitedChoices = function limitedChoices(argv) { | ||
@@ -155,3 +136,2 @@ const options = yargs.getOptions(); | ||
[].concat(argv[key]).forEach((value) => { | ||
// TODO case-insensitive configurability | ||
if (options.choices[key].indexOf(value) === -1 && | ||
@@ -173,3 +153,2 @@ value !== undefined) { | ||
}; | ||
// custom checks, added using the `check` option on yargs. | ||
let checks = []; | ||
@@ -201,6 +180,5 @@ self.check = function check(f, global) { | ||
}; | ||
// check implications, argument foo implies => argument bar. | ||
let implied = {}; | ||
self.implies = function implies(key, value) { | ||
argsert_1.argsert('<string|object> [array|number|string]', [key, value], arguments.length); | ||
argsert('<string|object> [array|number|string]', [key, value], arguments.length); | ||
if (typeof key === 'object') { | ||
@@ -220,3 +198,3 @@ Object.keys(key).forEach((k) => { | ||
else { | ||
common_types_1.assertNotStrictEqual(value, undefined); | ||
assertNotStrictEqual(value, undefined, shim); | ||
implied[key].push(value); | ||
@@ -230,11 +208,8 @@ } | ||
function keyExists(argv, val) { | ||
// convert string '1' to number 1 | ||
const num = Number(val); | ||
val = isNaN(num) ? val : num; | ||
if (typeof val === 'number') { | ||
// check length of argv._ | ||
val = argv._.length >= val; | ||
} | ||
else if (val.match(/^--no-.+/)) { | ||
// check if key/value doesn't exist | ||
val = val.match(/^--no-(.+)/)[1]; | ||
@@ -244,3 +219,2 @@ val = !argv[val]; | ||
else { | ||
// check if key/value exists | ||
val = argv[val]; | ||
@@ -274,3 +248,3 @@ } | ||
self.conflicts = function conflicts(key, value) { | ||
argsert_1.argsert('<string|object> [array|string]', [key, value], arguments.length); | ||
argsert('<string|object> [array|string]', [key, value], arguments.length); | ||
if (typeof key === 'object') { | ||
@@ -299,4 +273,2 @@ Object.keys(key).forEach((k) => { | ||
conflicting[key].forEach((value) => { | ||
// we default keys to 'undefined' that have been configured, we should not | ||
// apply conflicting check unless they are a value other than 'undefined'. | ||
if (value && argv[key] !== undefined && argv[value] !== undefined) { | ||
@@ -310,3 +282,3 @@ usage.fail(__('Arguments %s and %s are mutually exclusive', key, value)); | ||
self.recommendCommands = function recommendCommands(cmd, potentialCommands) { | ||
const threshold = 3; // if it takes more than three edits, let's move on. | ||
const threshold = 3; | ||
potentialCommands = potentialCommands.sort((a, b) => b.length - a.length); | ||
@@ -316,3 +288,3 @@ let recommended = null; | ||
for (let i = 0, candidate; (candidate = potentialCommands[i]) !== undefined; i++) { | ||
const d = levenshtein_1.levenshtein(cmd, candidate); | ||
const d = distance(cmd, candidate); | ||
if (d <= threshold && d < bestDistance) { | ||
@@ -327,4 +299,4 @@ bestDistance = d; | ||
self.reset = function reset(localLookup) { | ||
implied = obj_filter_1.objFilter(implied, k => !localLookup[k]); | ||
conflicting = obj_filter_1.objFilter(conflicting, k => !localLookup[k]); | ||
implied = objFilter(implied, k => !localLookup[k]); | ||
conflicting = objFilter(conflicting, k => !localLookup[k]); | ||
checks = checks.filter(c => c.global); | ||
@@ -343,3 +315,3 @@ return self; | ||
const frozen = frozens.pop(); | ||
common_types_1.assertNotStrictEqual(frozen, undefined); | ||
assertNotStrictEqual(frozen, undefined, shim); | ||
({ | ||
@@ -353,2 +325,1 @@ implied, | ||
} | ||
exports.validation = validation; |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.YError = void 0; | ||
class YError extends Error { | ||
export class YError extends Error { | ||
constructor(msg) { | ||
@@ -11,2 +8,1 @@ super(msg || 'yargs error'); | ||
} | ||
exports.YError = YError; |
122
CHANGELOG.md
@@ -299,123 +299,1 @@ # Changelog | ||
* we now warn if the yargs stanza package.json is used. | ||
<a name="12.0.5"></a> | ||
## [12.0.5](https://github.com/yargs/yargs/compare/v12.0.4...v12.0.5) (2018-11-19) | ||
### Bug Fixes | ||
* allows camel-case, variadic arguments, and strict mode to be combined ([#1247](https://github.com/yargs/yargs/issues/1247)) ([eacc035](https://github.com/yargs/yargs/commit/eacc035)) | ||
<a name="12.0.4"></a> | ||
## [12.0.4](https://github.com/yargs/yargs/compare/v12.0.3...v12.0.4) (2018-11-10) | ||
### Bug Fixes | ||
* don't load config when processing positionals ([5d0dc92](https://github.com/yargs/yargs/commit/5d0dc92)) | ||
<a name="12.0.3"></a> | ||
## [12.0.3](https://github.com/yargs/yargs/compare/v12.0.2...v12.0.3) (2018-10-06) | ||
### Bug Fixes | ||
* $0 contains first arg in bundled electron apps ([#1206](https://github.com/yargs/yargs/issues/1206)) ([567820b](https://github.com/yargs/yargs/commit/567820b)) | ||
* accept single function for middleware ([66fd6f7](https://github.com/yargs/yargs/commit/66fd6f7)), closes [#1214](https://github.com/yargs/yargs/issues/1214) [#1214](https://github.com/yargs/yargs/issues/1214) | ||
* hide `hidden` options from help output even if they are in a group ([#1221](https://github.com/yargs/yargs/issues/1221)) ([da54028](https://github.com/yargs/yargs/commit/da54028)) | ||
* improve Norwegian Bokmål translations ([#1208](https://github.com/yargs/yargs/issues/1208)) ([a458fa4](https://github.com/yargs/yargs/commit/a458fa4)) | ||
* improve Norwegian Nynorsk translations ([#1207](https://github.com/yargs/yargs/issues/1207)) ([d422eb5](https://github.com/yargs/yargs/commit/d422eb5)) | ||
<a name="12.0.2"></a> | ||
## [12.0.2](https://github.com/yargs/yargs/compare/v12.0.1...v12.0.2) (2018-09-04) | ||
### Bug Fixes | ||
* middleware should work regardless of when method is called ([664b265](https://github.com/yargs/yargs/commit/664b265)), closes [#1178](https://github.com/yargs/yargs/issues/1178) | ||
* translation not working when using __ with a single parameter ([#1183](https://github.com/yargs/yargs/issues/1183)) ([f449aea](https://github.com/yargs/yargs/commit/f449aea)) | ||
* upgrade os-locale to version that addresses license issue ([#1195](https://github.com/yargs/yargs/issues/1195)) ([efc0970](https://github.com/yargs/yargs/commit/efc0970)) | ||
<a name="12.0.1"></a> | ||
## [12.0.1](https://github.com/yargs/yargs/compare/v12.0.0...v12.0.1) (2018-06-29) | ||
<a name="12.0.0"></a> | ||
# [12.0.0](https://github.com/yargs/yargs/compare/v11.1.0...v12.0.0) (2018-06-26) | ||
### Bug Fixes | ||
* .argv and .parse() now invoke identical code path ([#1126](https://github.com/yargs/yargs/issues/1126)) ([f13ebf4](https://github.com/yargs/yargs/commit/f13ebf4)) | ||
* remove the trailing white spaces from the help output ([#1090](https://github.com/yargs/yargs/issues/1090)) ([3f0746c](https://github.com/yargs/yargs/commit/3f0746c)) | ||
* **completion:** Avoid default command and recommendations during completion ([#1123](https://github.com/yargs/yargs/issues/1123)) ([036e7c5](https://github.com/yargs/yargs/commit/036e7c5)) | ||
### Chores | ||
* test Node.js 6, 8 and 10 ([#1160](https://github.com/yargs/yargs/issues/1160)) ([84f9d2b](https://github.com/yargs/yargs/commit/84f9d2b)) | ||
* upgrade to version of yargs-parser that does not populate value for unset boolean ([#1104](https://github.com/yargs/yargs/issues/1104)) ([d4705f4](https://github.com/yargs/yargs/commit/d4705f4)) | ||
### Features | ||
* add support for global middleware, useful for shared tasks like metrics ([#1119](https://github.com/yargs/yargs/issues/1119)) ([9d71ac7](https://github.com/yargs/yargs/commit/9d71ac7)) | ||
* allow setting scriptName $0 ([#1143](https://github.com/yargs/yargs/issues/1143)) ([a2f2eae](https://github.com/yargs/yargs/commit/a2f2eae)) | ||
* remove `setPlaceholderKeys` ([#1105](https://github.com/yargs/yargs/issues/1105)) ([6ee2c82](https://github.com/yargs/yargs/commit/6ee2c82)) | ||
### BREAKING CHANGES | ||
* Options absent from `argv` (not set via CLI argument) are now absent from the parsed result object rather than being set with `undefined` | ||
* drop Node 4 from testing matrix, such that we'll gradually start drifting away from supporting Node 4. | ||
* yargs-parser does not populate 'false' when boolean flag is not passed | ||
* tests that assert against help output will need to be updated | ||
<a name="11.1.0"></a> | ||
# [11.1.0](https://github.com/yargs/yargs/compare/v11.0.0...v11.1.0) (2018-03-04) | ||
### Bug Fixes | ||
* choose correct config directory when require.main does not exist ([#1056](https://github.com/yargs/yargs/issues/1056)) ([a04678c](https://github.com/yargs/yargs/commit/a04678c)) | ||
### Features | ||
* allow hidden options to be displayed with --show-hidden ([#1061](https://github.com/yargs/yargs/issues/1061)) ([ea862ae](https://github.com/yargs/yargs/commit/ea862ae)) | ||
* extend *.rc files in addition to json ([#1080](https://github.com/yargs/yargs/issues/1080)) ([11691a6](https://github.com/yargs/yargs/commit/11691a6)) | ||
<a name="11.0.0"></a> | ||
# [11.0.0](https://github.com/yargs/yargs/compare/v10.1.2...v11.0.0) (2018-01-22) | ||
### Bug Fixes | ||
* Set implicit nargs=1 when type=number requiresArg=true ([#1050](https://github.com/yargs/yargs/issues/1050)) ([2b56812](https://github.com/yargs/yargs/commit/2b56812)) | ||
### Features | ||
* requiresArg is now simply an alias for nargs(1) ([#1054](https://github.com/yargs/yargs/issues/1054)) ([a3ddacc](https://github.com/yargs/yargs/commit/a3ddacc)) | ||
### BREAKING CHANGES | ||
* requiresArg now has significantly different error output, matching nargs. | ||
[Historical Versions](/docs/CHANGELOG-historical.md) |
{ | ||
"name": "yargs", | ||
"version": "15.4.1", | ||
"version": "16.0.0-alpha.0", | ||
"description": "yargs the modern, pirate-themed, successor to optimist.", | ||
"main": "./index.js", | ||
"main": "./index.cjs", | ||
"exports": { | ||
".": { | ||
"import": "./index.mjs", | ||
"require": "./index.cjs" | ||
}, | ||
"./yargs": { | ||
"require": "./build/index.cjs" | ||
} | ||
}, | ||
"type": "module", | ||
"module": "./build/index.mjs", | ||
"contributors": [ | ||
@@ -13,28 +24,25 @@ { | ||
"files": [ | ||
"index.js", | ||
"yargs.js", | ||
"index.cjs", | ||
"build", | ||
"locales", | ||
"LICENSE" | ||
"LICENSE", | ||
"lib/platform-shims/*.mjs", | ||
"!*.d.ts" | ||
], | ||
"dependencies": { | ||
"cliui": "^6.0.0", | ||
"decamelize": "^1.2.0", | ||
"find-up": "^4.1.0", | ||
"get-caller-file": "^2.0.1", | ||
"cliui": "^7.0.0", | ||
"escalade": "^3.0.2", | ||
"get-caller-file": "^2.0.5", | ||
"require-directory": "^2.1.1", | ||
"require-main-filename": "^2.0.0", | ||
"set-blocking": "^2.0.0", | ||
"string-width": "^4.2.0", | ||
"which-module": "^2.0.0", | ||
"y18n": "^4.0.0", | ||
"yargs-parser": "^18.1.2" | ||
"yargs-parser": "^19.0.1" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.2.11", | ||
"@types/decamelize": "^1.2.0", | ||
"@types/mocha": "^7.0.2", | ||
"@types/node": "^10.0.3", | ||
"@types/mocha": "^8.0.0", | ||
"@types/node": "^14.0.27", | ||
"@typescript-eslint/eslint-plugin": "^3.0.0", | ||
"@typescript-eslint/parser": "^3.0.0", | ||
"@wessberg/rollup-plugin-ts": "^1.3.2", | ||
"c8": "^7.0.0", | ||
@@ -45,4 +53,4 @@ "chai": "^4.2.0", | ||
"cpr": "^3.0.1", | ||
"cross-env": "^7.0.2", | ||
"cross-spawn": "^7.0.0", | ||
"es6-promise": "^4.2.5", | ||
"eslint": "^6.8.0", | ||
@@ -53,4 +61,6 @@ "eslint-plugin-import": "^2.20.1", | ||
"hashish": "0.0.4", | ||
"mocha": "^7.0.0", | ||
"mocha": "^8.0.0", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.23.0", | ||
"rollup-plugin-cleanup": "^3.1.1", | ||
"standardx": "^5.0.0", | ||
@@ -62,10 +72,14 @@ "typescript": "^3.7.0", | ||
"scripts": { | ||
"fix": "standardx --fix && standardx --fix **/*.ts", | ||
"check": "standardx './*.ts' && standardx '**/*.ts'", | ||
"fix": "standardx --fix './*.ts' && standardx --fix '**/*.ts'", | ||
"posttest": "npm run check", | ||
"test": "c8 mocha --require ./test/before.js --timeout=12000 --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", | ||
"check": "standardx && standardx **/*.ts", | ||
"prepare": "npm run compile", | ||
"pretest": "npm run compile -- -p tsconfig.test.json && cross-env NODE_ENV=test npm run build:cjs", | ||
"compile": "rimraf build && tsc", | ||
"prepare": "npm run compile", | ||
"pretest": "npm run compile -- -p tsconfig.test.json" | ||
"postcompile": "npm run build:cjs", | ||
"build:cjs": "rollup -c rollup.config.cjs", | ||
"postbuild:cjs": "rimraf ./build/index.cjs.d.ts" | ||
}, | ||
@@ -80,2 +94,4 @@ "repository": { | ||
"build", | ||
"index.cjs", | ||
"yargs.cjs", | ||
"**/example/**" | ||
@@ -95,4 +111,4 @@ ] | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=10" | ||
} | ||
} |
@@ -128,2 +128,8 @@ <p align="center"> | ||
## Supported Node.js Versions | ||
Libraries in this ecosystem make a best effort to track | ||
[Node.js' release schedule](https://nodejs.org/en/about/releases/). Here's [a | ||
post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a). | ||
[travis-url]: https://travis-ci.org/yargs/yargs | ||
@@ -130,0 +136,0 @@ [travis-image]: https://img.shields.io/travis/yargs/yargs/master.svg |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 7 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
288994
7
6710
147
14
Yes
26
51
1
3
+ Addedescalade@^3.0.2
+ Addedcliui@7.0.4(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedyargs-parser@19.0.4(transitive)
- Removeddecamelize@^1.2.0
- Removedfind-up@^4.1.0
- Removedrequire-main-filename@^2.0.0
- Removedset-blocking@^2.0.0
- Removedwhich-module@^2.0.0
- Removedcamelcase@5.3.1(transitive)
- Removedcliui@6.0.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removedfind-up@4.1.0(transitive)
- Removedlocate-path@5.0.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@4.1.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedrequire-main-filename@2.0.0(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedwhich-module@2.0.1(transitive)
- Removedwrap-ansi@6.2.0(transitive)
- Removedyargs-parser@18.1.3(transitive)
Updatedcliui@^7.0.0
Updatedget-caller-file@^2.0.5
Updatedyargs-parser@^19.0.1