Boolean options¶
If you specify an option for --dev
:
- !Option [dev, !Type bool]
the .dev
attribute will be None
if that options is not specified and
True
if it is specified, so you should be able to just use it with if args.dev:
If you explicitly want the attribute to be False
if the option is not specified use:
- !Option [dev, !Type bool, !Default False]
storing False¶
You can create an "inverse" boolean option, that defaults to True if not specified and to False if it is using:
- !Option [dev, !Type bool, !Const False, !Default True]
tri-state with --no-¶
If you want both an option --dev
and an option --no-dev
, the later e.g. to be able to
reverse the default value read from a configuration file, you need to specify two
options that write to the same destination attribute:
- !Option [dev, !Type bool] # without !Dest uses the first (long) option as destination
- !Option [no-dev, !Type bool, !Dest dev, !Const False]
This is actually a tri-state, with None
as attribute value when neither --dev
nor
--no-dev
were specified.