MetricsGrimoire / MailingListStats

Mailing List Stats is a command line based tool used to analyze mboxes
http://metricsgrimoire.github.com/MailingListStats/
GNU General Public License v2.0
38 stars 25 forks source link

Create a git-like command #17

Open gpoo opened 10 years ago

gpoo commented 10 years ago

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 commented 10 years ago

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 #16https://github.com/MetricsGrimoire/MailingListStats/issues/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/MetricsGrimoire/MailingListStats/issues/17 .

gpoo commented 10 years ago

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)