-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add multilevel subcommands with class objects support to CLI #438
Comments
Thank you very much for the proposal! I have several comments:
Since it was mentioned, I can give some ideas for a potential chaining feature. I am not completely convinced on how Fire does chaining. I would probable go for something more explicit, for instance using double dash
|
Hi @mauvilsa , just came across with this comment and found my issue might relate to it. I have two arguments linked from data to model when |
@tensorcopy I don't really understand what you mean about |
🚀 Feature request
I would like to request the ability to define multilevel subcommands using only class objects.
Motivation
Related: #334
We cannot define multilevel subcommands using class objects. While it's possible to define such subcommands using dictionaries, in this case, generating help from docstrings is not feasible (see below).
So, we have to choose between multilevel subcommands or complete help.
Also, I personally don't like using a dictionary to define CLIs. It is not intuitive and can easily get messy.
Pitch
One idea I came up with is to use properties as references to the sub-subcommands.
This allows us to define arbitrary levels of subcommands using only class objects and generate complete help using only docstrings.
Example:
In a shell, it can be called like this.
This is equivalent to the following Python code.
As a proof of concept, I implemented this idea.
https://github.com/Kenji-Hata/jsonargparse/pull/1/files
The changes required seem small, but I'm new to jsonargparse, so I may be missing something.
Alternatives
As an alternative to multilevel subcommands, another solution is chaining function calls. That is, if a command returns a class object or function, use it as the next component and run the CLI with the remaining arguments.
With this approach, we could give additional arguments to each level of the subcommand.
This is not what I requested, as I do not design CLIs like this, but if there are plans to add such a feature, then the feature I suggested would be redundant.
The text was updated successfully, but these errors were encountered: