jonaslu / ain

A HTTP API client for the terminal
MIT License
601 stars 13 forks source link

Add default value to unset environment variables #16

Closed erikeah closed 1 year ago

erikeah commented 1 year ago

Similar to how it's been done in bash, this allows to give dafault values to environment variables that hasn't been set yet.

Test plan:

Congrats for such a cool project, Ain is just what I have been looking for. ๐Ÿ’

jonaslu commented 1 year ago

Hey, thanks for the kind words.

I'll have a think if ain should support sh-isms such as variable defaults. If we go this route then probably all bash-variable antics should be supported too. Need to read up on that.

In the meantime you can work around it by defining an .env file supplying the defaults there.

erikeah commented 1 year ago

By bash variables antics, do you mean what's called in the bash manual ยซExpansionยป?

In that case I think Ain it could have a lot methods to transform environment variables. However I see too much methods, I don't see anyone using all that features (or knowing how to use it), also maintain all those lines... and ensure code quality... pain increasing

I think a well being selected, or inspired by, those features of shell inside a Ain could be cool but just a few, or even anyone. ๐Ÿ˜‚

But I think a default value for env vars could be useful, maybe changing the nomenclature will make you more confortable?

Thanks for response!

jonaslu commented 1 year ago

Yes that's what I mean with bash-antics.

I've thought some more about it, and this is not the way to go.

With this syntax you can define the same variable twice with different defaults (thanks to @meros for pointing this out). That will be confusing and bug prone, esp. if several files are used.

VAR:value is a valid env-variable, you can define it via env but not in bash itself. This will cause regression in any files using this as the actual variable.

erikeah commented 1 year ago

Thanks @meros, I haven't notice on env... To be fair, I haven't ever used.

I will try to get some documentation on illegal symbols on Environment Variables, from that I will craft some posible syntax to present to you and may one of them will fit on ain!

jonaslu commented 1 year ago

Allright, good luck!

I'll close this PR.