Open gizmomogwai opened 8 months ago
I think it is a good idea, but it needs some thinking about corner cases.
(defaults to abc)
docopt (as well as docopt.py, which gave birth to this family of libraries) uses [Default: abc]
syntax (default
is case-insensitive there), which we can adopt as well. Just suggesting alternatives so that we have more options to choose from.
It can probably be made user-configurable.
--text2 TEXT2 dsc for text2
--text2
is an optional argument, which does have a default value too – ""
. (Well, null
actually.) Should we print it? (defaults to )
/ [Default: ]
/ etc.
Fields can have arbitrary user-defined types. Will formatting them via toString
suffice? And how should we determine whether we should print the default value of a custom type?
I see few options how this can be implemented:
member = value;
can be partially done via COMMAND.init.member != typeof(COMMAND.member).init
check. Partially - because it won't detect a case when value
is the same as typeof(COMMAND.member).init
(e.g. struct T { int i = 0; }
).Default!value
modifier to PositionalArgument
and NamedArgument
. Cons is that value
will have to be duplicated: struct T { @(NamedArgument.Default!123) int i = 123; }
.PrintDefaultValueInHelp(bool)
modifier to PositionalArgument
and NamedArgument
.PrintDefaultValueInHelp(true)
or check 1 is true.I think option 4 is better as it allows reasonable default behavior and flexible customization.
An idea that hopefully makes the default [no pun intended] behavior even more reasonable. Unless overridden by PrintDefaultValueInHelp
, that flag should be true
iff T
is an enum
or check 1 is true. With this adjustment, the {WALK,RUN}
example from the initial comment will work as proposed.
If there are default values for subcommands or parameters, those should be highlighted in the helptext. e.g.
outputs
at the moment when called with
--help
. It would be great if something likecould be printed.