From 6867a3441fc29b15806aa5a14b3695a83f1afcde Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 7 Oct 2016 13:37:03 +0300 Subject: [PATCH] Fix validation of -- options The validation of -- options passed on the command line depends on yargs module. Update it to latest versions as the previously used one didn't set correct values of options marked as strings. Also in our code we pass object of valid options to yargs. Options which have `-` in the name are treated in a special manner in yargs. However instead of passing them with `-`, we pass their secondary representation (remove the `-` and capitalize the next letter). This way, when the user passes option with `-`, yargs treat it with it's default behavior and does not respect our options for it (as we have not defined that we have option with `-`). Example: ```JavaScript var yargs = require("yargs"); var opts = { "profile-dir": { type: "string" } }; console.log(yargs(process.argv).options(opts).argv); var opts1 = { "profileDir": { type: "string" } }; console.log(yargs(process.argv).options(opts1).argv); ``` When called with: ``` node testYargs.js --profile-dir ``` The result is: ``` { 'profile-dir': '', profileDir: '', '$0': 'testYargs.js' } { 'profile-dir': true, profileDir: true, '$0': 'testYargs.js' } ``` As you can see, passing "profileDir" and defining it as string does not work. But when we use "profile-dir" in our opts, everything works as expected and yargs sets the value to empty string. In order to resolve the problem, make sure we pass options with dashes to yargs. When boolean value is passed to isNullOrWhitespace helper method, it fails as true.replace is not available function. Add unit tests for: - options issue - assert correct behavior when dashed option is passed on the terminal - helpers isNullOrWhitespace method - helpers isBoolean method --- lib/common | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/common b/lib/common index 5b5a74129a..35330ab7a7 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 5b5a74129a0ffd69f111ea9f6889d43d0fd59c91 +Subproject commit 35330ab7a7146ac9427051ffde5d65c1391602f3 diff --git a/package.json b/package.json index 24f68638ad..20220fd662 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "xcode": "https://github.com/NativeScript/node-xcode/archive/1.4.0.tar.gz", "xmldom": "0.1.21", "xmlhttprequest": "https://github.com/telerik/node-XMLHttpRequest/tarball/master", - "yargs": "3.15.0" + "yargs": "6.0.0" }, "analyze": true, "devDependencies": {