-
Notifications
You must be signed in to change notification settings - Fork 2
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
How to create nested commands? #7
Comments
Thanks for opening the issue. The problem of multilevel subcommands has been bugging me since the very start, but I haven't come up with a clever solution so far. I'll investigate closer into your proposal, thanks! |
How about something like the following? class Env(Cliar):
def create(self):
...
def list(self):
...
def export(self):
...
class Conda(Cliar):
env: Env
def create(self):
...
def list(self):
... Cliar's metaclass will read the class definition of Of course, the nesting could be made more explicit by using descriptors. class Conda(Cliar):
env = Env()
... For this, the Cliar class should itself support the descriptor protocol. |
OK, I got it :-) I've implemented this feature in https://github.com/moigagoo/cliar/tree/feature/nested_commands Have to fix the tests and add a new test. The syntax will be as follows: class Env(Cliar):
def create(self):
...
def list(self):
...
def export(self):
...
class Conda(Cliar):
env = Env
def create(self):
...
def list(self):
... |
Added in version 1.3.0: https://moigagoo.github.io/cliar/tutorial/#nested-commands |
Take
conda
for example. We have commands like this:or
git
:I think one way to handle this is to create subcommand class and explicitly pass
args
to it'sparse
function:Currently, the
Cliar
class impliedly takeargs
from the command line.However, I think taking args from another command may be useful to build complex CLI.
The text was updated successfully, but these errors were encountered: