Closed carmocca closed 5 months ago
The bug is something simple and would be fixed with #468.
The ideal behaviour would be that python repro.py -h only lists the method argument:
Unfortunately this is not how it currently works. All arguments are shown in the help, under "Conditional arguments" groups.
And then when one does python repro.py --method B -h then it also shows:
This would be rather complex to implement. One issue is that argparse
prints the help using a single print_help
method which does not depend on previous arguments given, thus not possible to be conditional on --method B
. And would also be complex because the help would need to redo code introspection with provided parameter values to figure out what code branches to apply.
I don't know if the AST is smart enough to parse the *args, **kwargs specific to the method selected.
It is capable of identifying conditional parameters. Though not specific enough to group it by dependence on other parameter values.
I'm happy to try out a different way to support CLI behaviour like this, if there are better ways to approach this problem.
I would say that jsonargparse.CLI
is just a convenience function for some cases. But, when targeting more specific behaviors, implementing the logic to build the parser and call respective functions might be more advisable. And relying on code introspection to get a kind of subcommand behavior is destined to have limitations. I think better to use actual subcommands. I you really want repro.py --method B ...
instead of just repro.py B ...
maybe it is possible to easily implement the subcommands requiring a prior --key
, though not sure.
Thank you for the quick fix Mauricio!
The jsonargparse.CLI
is awesome so I was trying to avoid building my own for as long as possible.
🐛 Bug report
I am trying to setup a CLI system where I have a multitude of subcommands (only 1 in the repro code,
finetune
) and some of them take a--method
argument that allows selecting a different function.See https://github.com/Lightning-AI/litgpt/issues/996 for the real purpose of this.
To reproduce
Expected behavior
The ideal behaviour would be that
python repro.py -h
only lists the method argument:And then when one does
python repro.py --method B -h
then it also shows:I don't know if the AST is smart enough to parse the
*args, **kwargs
specific to the method selected.I'm happy to try out a different way to support CLI behaviour like this, if there are better ways to approach this problem.
Environment