Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upAccessing values of environment variables #23
Comments
This comment has been minimized.
This comment has been minimized.
|
No. Dhall can only import values via file paths or URLs |
This comment has been minimized.
This comment has been minimized.
|
Do you see handling of environment variables as something that should be external do Dhall? |
This comment has been minimized.
This comment has been minimized.
|
Actually, I could add support for reading in Dhall expressions via environment variables, using something like this syntax:
However, there are two issues with that:
|
This comment has been minimized.
This comment has been minimized.
|
I can see your point. What if there was an implicit global For example:
would imply:
|
This comment has been minimized.
This comment has been minimized.
|
What is the motivation for providing support for environment variables, though? The reason I ask is that any program that takes environment variables implicitly could be done by reformulating the program as a function. For example, your code could be written as: λ(ENV : { FOO : Text, BAR : Text })
→ { foo = ENV.BAR }... and instead of running: $ FOO=foo BAR=bar dhall <<< './example'... you could supply the desired variables as an ordinary function argument when invoking the expression: $ dhall <<< './example { FOO = "foo", BAR = "bar" }'... or if you are really constrained to obtain the values from environment variables, you could even do: $ dhall <<< "./example { FOO = \"${FOO}\", BAR = \"${BAR}\" }" |
This comment has been minimized.
This comment has been minimized.
|
In the last case, it will mostly work except when the environment variable needs to be escaped, which is the tricky bit. Perhaps all we need is a
Or:
|
This comment has been minimized.
This comment has been minimized.
|
Hmmm. I would prefer reading environment variables directly within Dhall as a built-in mechanism rather than provide an The main issue with The second issue (when I thought about this more) is that an So what I'll probably do is add something like So in other words, you could do: $ FOO='"foo"' BAR='1' dhall <<< '{ foo = env://FOO , bar = env://BAR }'
{ bar : Integer, foo : Text }
{ bar = 1, foo = "foo" }How does that sound? |
This comment has been minimized.
This comment has been minimized.
|
That sounds really good. Although being able embed variables as string is also useful. I don't mind having to type extra to get it. For example, I'd be happy with |
This comment has been minimized.
This comment has been minimized.
|
I just realized that I also like the idea of using |
This comment has been minimized.
This comment has been minimized.
|
Good spot. Thanks! |
This comment has been minimized.
This comment has been minimized.
|
Alright, the first part of this is done in 11ceab1 (supporting |
This comment has been minimized.
This comment has been minimized.
|
Looking good! |
This comment has been minimized.
This comment has been minimized.
|
I just discovered a case that might need better
|
This comment has been minimized.
This comment has been minimized.
|
At the moment, I'm required to put the absolute path in:
|
This comment has been minimized.
This comment has been minimized.
|
Could I propose an alternative syntax for importing raw { foo = /foo as Text
, bar = env:HOME as Text
, baz = http://example.com as Text
}Would that be alright? |
Gabriel439
added a commit
that referenced
this issue
Mar 31, 2017
Gabriel439
added a commit
that referenced
this issue
Mar 31, 2017
Gabriel439
referenced this issue
Mar 31, 2017
Merged
Add support for importing paths as raw `Text` #34
This comment has been minimized.
This comment has been minimized.
|
I put up a PR for the |
Gabriel439
added a commit
that referenced
this issue
Mar 31, 2017
Gabriel439
closed this
Mar 31, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Thanks so much! |
This comment has been minimized.
This comment has been minimized.
|
You're welcome! :) |
newhoggy commentedFeb 18, 2017
Is there a way to evaluate an environment variable in a dhall expression?