glow icon indicating copy to clipboard operation
glow copied to clipboard

Improve handling of environment variables in the pipe transformer

Open Hoeze opened this issue 2 years ago • 5 comments

From https://github.com/projectglow/glow/blob/master/docs/source/tertiary/pipe-transformer.rst:

Options beginning with env_ are interpreted as environment variables. Like other options, the environment variable name is converted to lower snake case. For example, providing the option env_aniMal=MONKEY results in an environment variable with key ani_mal and value MONKEY being provided to the piped program.

Would it be possible to have some argument jsonEnv that can decode json-encoded environment variables? E.g.:

jsonEnv='{"PATH": "/usr/bin"}'

This would make it significantly easier to adjust environment variables IMHO.

Hoeze avatar Jan 31 '22 11:01 Hoeze

The snake-case parsing of arguments makes it impossible to pass uppercase environment variables, right? E.g. env_TEST would get translated to t_e_s_t.

Interestingly, passing env_test_path='asdf' results in an environment variable test_path="asdf". So actually there is no need to parse them as snake-case.

Hoeze avatar Jan 31 '22 11:01 Hoeze

An alternative approach is to define environment variables via JSON and put those variables into your script, which is then run through the pipe transformer.

Here's an example,

Screen Shot 2022-02-01 at 1 28 27 PM

Screen Shot 2022-02-01 at 1 28 36 PM

I have never used the environment variable feature in glow. Probably because I hit the same limitations you describe above!

williambrandler avatar Feb 01 '22 21:02 williambrandler

Ah, OK, I did not think of that solution :grin:

Hoeze avatar Feb 01 '22 21:02 Hoeze

will keep the issue open for now until this is properly documented

should delete those environment variable options from the docs, they are somewhat confusing

williambrandler avatar Feb 01 '22 21:02 williambrandler

updating the example in the docs to avoid this issue in future:

https://github.com/projectglow/glow/pull/490

williambrandler avatar Feb 18 '22 22:02 williambrandler