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

Incorrect results when passing command line argument with default from process.env #21

Closed
alexpls opened this issue Jun 20, 2016 · 1 comment
Assignees

Comments

@alexpls
Copy link

alexpls commented Jun 20, 2016

This is a weird one. When passing a value to an argument via the command line, while also defining a fallback on process.env, [object Object] is returned instead of the correct value.

I took these steps to reproduce the issue:

  1. In a new directory do npm install args
  2. Create a file fail.js with these contents:
const args = require('args');
args.option(['p', 'port'], 'The port to run on', process.env.PORT || 3000);
const config = args.parse(process.argv);
console.log(`Your port is: ${config.port}`);
  1. Run the following tests on the CLI and observe the weird results:
$ node fail.js
Your port is: 3000 # all good

$ node fail.js -p 1000
Your port is: 1000 # all good

$ PORT=1000 node fail.js
Your port is: 1000 # all good

$ PORT=1000 node fail.js -p 1001
Your port is: [object Object] # failure

Note if I take out process.env in that script and instead specify a single default value of 3000 with no fallback everything works as expected.

Happy to look into resolving the issue if you don't have time to, as it's currently causing bugs in the master branch of slackin here: rauchg/slackin#206

@leo
Copy link
Owner

leo commented Jun 23, 2016

Fixed and released in: https://github.com/leo/args/releases/tag/v1.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants