Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace minimist with yargs-parser #7187

Merged
merged 4 commits into from Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/providers/aws/cli-reference/invoke-local.md
Expand Up @@ -34,7 +34,7 @@ serverless invoke local --function functionName
* `--env` or `-e` String representing an environment variable to set when invoking your function, in the form `<name>=<value>`. Can be repeated for more than one environment variable.
* `--docker` Enable docker support for NodeJS/Python/Ruby/Java. Enabled by default for other
runtimes.
* `--docker-arg` Pass additional arguments to docker run command when `--docker` is option used. e.g. `--docker-arg '-p 9229:9229' --docker-arg '-v /var:/host_var'`
* `--docker-arg` Pass additional arguments to docker run command when `--docker` is option used. e.g. `--docker-arg='-p 9229:9229' --docker-arg='-v /var:/host_var'`

## Environment

Expand Down
15 changes: 8 additions & 7 deletions lib/utils/resolveCliInput.js
@@ -1,9 +1,9 @@
'use strict';

const _ = require('lodash');
const minimist = require('minimist');
const yargsParser = require('yargs-parser');

const minimistOptions = {
const yargsOptions = {
boolean: ['help', 'version', 'verbose'],
string: ['config'],
alias: { config: 'c', help: 'h', version: 'v' },
richarddd marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -15,10 +15,11 @@ module.exports = _.memoize(inputArray => {
const toBase64Helper = value => {
const valueStr = value.toString();
if (valueStr.startsWith('-')) {
if (valueStr.indexOf('=') !== -1) {
const equalsIndex = valueStr.indexOf('=');
if (equalsIndex !== -1) {
// do not encode argument names, since those are parsed by
// minimist, and thus need to be there unconverted:
const splitted = valueStr.split('=', 2);
// yargs-parser, and thus need to be there unconverted:
const splitted = [valueStr.substring(0, equalsIndex), valueStr.substring(equalsIndex + 1)];
// splitted[1] values, however, need to be encoded, since we
// decode them later back to utf8
const encodedValue = base64Encode(splitted[1]);
Expand All @@ -42,8 +43,8 @@ module.exports = _.memoize(inputArray => {
// encode all the options values to base64
const valuesToParse = _.map(inputArray, toBase64Helper);

// parse the options with minimist
const argvToParse = minimist(valuesToParse, minimistOptions);
// parse the options with yargs-parser
const argvToParse = yargsParser(valuesToParse, yargsOptions);

// decode all values back to utf8 strings
const argv = _.mapValues(argvToParse, decodedArgsHelper);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -184,7 +184,6 @@
"jszip": "^3.2.2",
"jwt-decode": "^2.2.0",
"lodash": "^4.17.15",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"nanomatch": "^1.2.13",
"ncjsm": "^4.0.1",
Expand All @@ -203,6 +202,7 @@
"update-notifier": "^2.5.0",
"uuid": "^2.0.3",
"write-file-atomic": "^2.4.3",
"yaml-ast-parser": "0.0.43"
"yaml-ast-parser": "0.0.43",
richarddd marked this conversation as resolved.
Show resolved Hide resolved
"yargs-parser": "^16.1.0"
}
}
2 changes: 1 addition & 1 deletion scripts/pkg/upload.js
Expand Up @@ -6,7 +6,7 @@

require('essentials');

const argv = require('minimist')(process.argv.slice(2), {
const argv = require('yargs-parser')(process.argv.slice(2), {
boolean: ['help'],
alias: { help: 'h' },
});
Expand Down