undefinedfix
Sign in

How to implement complex commands in Python's click command line library

Rickard edited in Sat, 30 Jul 2022

The functions I want to achieve are similar to the following:

docker image rm
docker image ls
或者
git remote add origin
git remote rm origin

Now the implementation method is as follows, but I feel that argument should not be used in this way, but there should be a concept of subcommand. Please give me some advice.

@click.group()
def main():
    pass
    
@main.command()
@click.argument("command", click.Choice(["rm", "ls"]))
def image(command):
    if command == "rm":
        pass
    elif command == "ls":
        pass
1 Replies
altegn0
commented on Sat, 30 Jul 2022

You can call the docker API directly~

https://docs.docker.com/regis...

lock This question has been locked and the reply function has been disabled.