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

Create a git-like command #17

Open
gpoo opened this issue Feb 13, 2014 · 2 comments
Open

Create a git-like command #17

gpoo opened this issue Feb 13, 2014 · 2 comments

Comments

@gpoo
Copy link
Member

gpoo commented Feb 13, 2014

Slightly related to #16, it would be nice to have operations with mlstats to make it simpler yet powerful. For example,

$ mls db create ...
$ mls report ...
$ mls parse ...

I am unsure about the commands yet, but splitting the operation of connecting and creating the database made me think about this.

@andygrunwald
Copy link
Contributor

REALLY good idea.
I like the implementation of the Symfony console:
https://github.com/symfony/Console
This is a PHP project which is kindly the same as this idea.

Maybe we can port this to Python?
Or is there something similar in Python itselfs?

Am Freitag, 14. Februar 2014 schrieb Germán Poo-Caamaño :

Slightly related to #16#16,
it would be nice to have operations with mlstats to make it simpler yet
powerful. For example,

$ mls db create ...
$ mls report ...
$ mls parse ...

I am unsure about the commands yet, but splitting the operation of
connecting and creating the database made me think about this.

Reply to this email directly or view it on GitHubhttps://github.com//issues/17
.

@gpoo
Copy link
Member Author

gpoo commented Feb 14, 2014

I have never tried that. By looking at the repository it seems a bit overkill. I would go for something simpler, like argparse. Take a look at the following snippet:

def main():
    arger = argparse.ArgumentParser()

    # Arguments for top-level, e.g "subcmds.py -v"
    arger.add_argument("-v", "--verbose", action="count", default=0)

    subparsers = arger.add_subparsers(dest="command")

    # Make parser for "subcmds.py report ..."
    report_parser = subparsers.add_parser("report")
    report_parser.add_argument("-m", "--moo", dest="moo")

    # Make parser for "subcmds.py parse ..."
    parse_parser = subparsers.add_parser("parse")
    parse_parser.add_argument("url", nargs="+")

    # Parse
    opts = arger.parse_args()

    # Print option object for old-school debugging
    print opts

    if opts.command == "report":
        print "Report command"
        print "--moo was %s" % opts.moo

    elif opts.command == "parse":
        print "url: %s" % opts.url

    else:
        # argparse will error on unexpected commands, but
        # in case we mistype one of the elif statements...
        raise ValueError("Unhandled command %s" % opts.command)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants