matejak / argbash

Bash argument parsing code generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using environment variable by default

tcheronneau opened this issue · comments

Hey just discovered this and it's really cool !
But now I find myself with something I would want and I don't find it.

Is there a way to define an argument (no matter the type) to be overwritten by an env variable ?

For example I define for my script some username / password :

./run.sh -u <user> -p <password>

And for some reason I would want this thing to be possible :

PASSWORD=toto ./run.sh -u <user>

But still to have the defaults available.
So for example by convention say that user default to admin but if USER is defined use it.
From what I've seen in the code it would simply need to overload the init phase of the variables.
Maybe not auto activation but some kind of option when you declare the variable ?

Argbash can't do this for you, but nothing stops you from examining the env variables later in the script - when you find out that no arguments have been supplied.
What you suggest is non-standard, and although I believe that it would fit your use case, it is out of scope of Argbash which aims at doing the standard thing, and to do it really right. Therefore, I close this issue, and I hope that you still find the tool useful.