env-cmd
env-cmd copied to clipboard
-v argument to output version is detected anywhere in command, preventing calling any command with a -v argument
Node 12.16.3 env-cmd 10.1.0
npx env-cmd node -v
Output: 10.1.0 Expected output: 12.16.3
If I comment out this line in my node_modules, then it works as expected:
https://github.com/toddbluhm/env-cmd/blob/master/dist/parse-args.js#L77
I don't know enough about commander to propose a fix.
I ran into this, too and found a solution. env-cmd uses the package commander for its CLI functionality, including support for version, usage and options. That package supports grouping multiple single-letter options into one option parameter. For example, it is interpreting -abcv to be the same as -a -b -c -v. The option -v corresponds to printing the version. The implementation of version just happens to short-circuit any other processing, so if any of the options it sees includes a v, you will get the version number printed out and no other functionality.
The solution is to include -- (documented here) at the right place to tell env-cmd (and commander under the hood) to stop processing further options. Here is a simplified example from my package.json where I was only getting the version number displayed because the v in -derivedDataPath was triggering commander's version handler:
"e2e:build:ios:bad": "env-cmd -x echo -derivedDataPath \\$IOS_DERIVED_PATH",
And here it works correctly by adding in -- to separate options intended for env-cmd from options intended for the tool I am controlling:
"e2e:build:ios:good": "env-cmd -x -- echo -derivedDataPath \\$IOS_DERIVED_PATH",