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

env() removes capitalization from camel case variable names #345

Closed
pownkel opened this issue Dec 9, 2020 · 6 comments
Closed

env() removes capitalization from camel case variable names #345

pownkel opened this issue Dec 9, 2020 · 6 comments
Labels

Comments

@pownkel
Copy link

pownkel commented Dec 9, 2020

In the update to v16, it looks like the behavior of env() changed to convert all env variable names to lowercase. Here's an example to illustrate:

process.env.camelCaseArg = 'value';
process.env.lowercasearg = 'value';

const envArgs = yargs().env().argv;

console.log(`lower case: ${envArgs.lowercasearg}`);
console.log(`camel case: ${envArgs.camelCaseArg}`);
console.log(`camel case variable with lower case name: ${envArgs.camelcasearg}`);

Running this on v15.4.0 prints

lower case: value
camel case: value
camel case variable with lower case name: undefined

While in v16.0.0 and later, the same code prints

lower case: value
camel case: undefined
camel case variable with lower case name: value

Updating to v16 broke some of our code as our camel case env variables were no longer found under their original names. I'm not sure whether the change was intentional, but the API documentation for .env() still shows camel case env variable names in the argv object, which is misleading.

@pitgrap
Copy link

pitgrap commented Dec 16, 2020

We got the same problem in our CI after updating to v16.

environmentVariable: TEST_DATA_CLI_testPropertiesUrl
Code: yargs.env("TEST_DATA_CLI").demandCommand(1, "You need at least one command before moving on.")...
Log:

[INFO] test-data import
[INFO] ...
[INFO] Missing required argument: testPropertiesUrl
[INFO] error Command failed with exit code 1.

Took me a while to find this issue as the cause for the failing CI. We have reverted to v15.

@bcoe bcoe transferred this issue from yargs/yargs Dec 17, 2020
@bcoe bcoe added the bug label Dec 17, 2020
@bcoe
Copy link
Member

bcoe commented Dec 17, 2020

@pitgrap @pownkel thank you for the bug report, I'm pretty sure this will end up being related to my reimplementing our camel case logic in v16 -- if you get a chance to dig into it, patches are very much welcome.

@pitgrap
Copy link

pitgrap commented Dec 18, 2020

@bcoe can you give me a code pointer? I tried to find the PR, which introduced this bug, but gave up after 10min search. :-/

@bcoe
Copy link
Member

bcoe commented Dec 21, 2020

@pitgrap I implemented camel-case, and de-camel-case here:

https://github.com/yargs/yargs-parser/blob/master/lib/string-utils.ts#L26

When I ported the library to ESM.

@Ivan-Strahovsky
Copy link
Contributor

@bcoe I have fix in my local branch, how can I open PR for to review?

Ivan-Strahovsky pushed a commit to Ivan-Strahovsky/yargs-parser that referenced this issue Feb 2, 2021
Ivan-Strahovsky pushed a commit to Ivan-Strahovsky/yargs-parser that referenced this issue Feb 2, 2021
…inue which is redundun fot the last loop statement
@bcoe
Copy link
Member

bcoe commented Feb 15, 2021

this should be fixed in the latest release.

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

No branches or pull requests

4 participants