Question. How to use switches together with environment variables?
ilejn opened this issue · comments
Hello,
I have simple command line flags, that perfectly work with action="store_true".
I would like to have it controlled via environment as well, but it does not work well.
Ideally I want to specify
myscript --debug
or DEBUG=true myscript
and it works indeed,
unless I try DEBUG=false myscript
. The latest one is converted to True as well.
The question is what is the best way to achieve the goal.
Switching to type=bool
works, but not convenient as for commandline. Attempt to have two parameters with same dest
is not successful (obviously).
My bad, the attempt to have two parameters with same dest
IS successful.
I have
parser.add_argument(
"--silent",
action="store_true",
dest="silent_flag",
default=False,
help="no log"
)
parser.add_argument(
"--silentflag",
"--silent-flag",
dest="silent_flag",
type=bool,
default=False,
help="no log"
)