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

Should allow comment at end of lines #156

Closed
mettjus opened this issue Oct 29, 2016 · 6 comments · Fixed by #568
Closed

Should allow comment at end of lines #156

mettjus opened this issue Oct 29, 2016 · 6 comments · Fixed by #568

Comments

@mettjus
Copy link

mettjus commented Oct 29, 2016

I think it would be useful to be able to have comments at the end of lines. E.g.:

MY_VAR=some-value   # this should be treated as a comment
@jcblw
Copy link
Collaborator

jcblw commented Oct 29, 2016

I like this idea, I would be open to merging a PR for this.

@mettjus
Copy link
Author

mettjus commented Oct 31, 2016

I played a little with it and was wondering if you had already taken into account the opportunity of using a parser generator with an expression grammar, something like peg.js. I experimented with it and already implemented the comment-at-end-of-line feature using peg.js. If you want to take a look you can find it here.
The object resulting from parsing the test .env file is the same.
Let me know what you think, if this is an acceptable approach or if you'd rather stick to a manually defined parser.

@maxbeatty
Copy link
Contributor

Why are comments needed inline? Please expand on its usefulness.

@sneakertack
Copy link

They probably don't qualify as needed, maybe they're more like a nice-to-have: in certain cases some developers might prefer being able to write a short comment on the same line, instead of having to add a new line above (unfortunately I don't have stats, I can only anecdotally say I've had that want).

My specific context was during the preparation of a .env.sample file with 8 or so KV pairs (that teammates could cp and then make minor edits to). They're sample values, so I can mostly get by by describing the expected value using the value itself (e.g. POSTGRES_URL=postgres://user:password@host:port/5432). However for 1 or 2 pairs it would have been nice to provide a bit more info (e.g. # append ?ssl=true when connecting to heroku), yet dedicating a separate line for the comment would have felt excessive.

Shell script allows #-comments midway through the line, and it's plausible that this module might consume environment variable definition files originally written for Shell, so for me inline comments being unsupported rather than supported was the part that felt surprising.

@maxbeatty
Copy link
Contributor

dotenv doesn't need to support inline comments for a sample file to get its point across. If there's mass confusion, use the comments that are already supported. .env should be thought of as a simple ini file and nothing more

@sneakertack
Copy link

Okay. In case anyone else is specifically looking for this feature in future, you can use this fork here: sneakertack/dotenv#altparser.

Additional context can also be found at #158, be sure you understand the differences before installing.

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

Successfully merging a pull request may close this issue.

4 participants