Skip to content
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

Use docopt-dispatch in Docopt example #41

Open
bittner opened this issue May 27, 2023 · 0 comments
Open

Use docopt-dispatch in Docopt example #41

bittner opened this issue May 27, 2023 · 0 comments
Labels
good first issue Good for newcomers

Comments

@bittner
Copy link
Member

bittner commented May 27, 2023

An alternative to using docopt-ng, or just docopt, may be docopt-dispatch. It makes it largely unnecessary to implement argument dispatching logic on your own and hence renders the Docopt CLI example source code more readable.

Example

"""Awesome CLI.

...

Usage:
  awesome (-h | --help | --version)
  awesome login --user <user> --pass <pass>

Commands:
  login   Authorize a user with username and password
"""

from docopt_dispatch import dispatch

def main():
    """The CLI entrypoint."""
    dispatch(__doc__, version=__version__)

@dispatch.on("login")
def login_command(**kwargs):
    """Authorize a user with username and password.""" 
    username = kwargs["user"]
    password = kwargs["pass"]
    ...

Related

@bittner bittner added the good first issue Good for newcomers label May 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant