Giter Club home page Giter Club logo

commando's Introduction

commando - argparse in style

Version 0.1.2a

A simple wrapper for argparse that allows commands and arguments to be defined declaratively using decorators. Note that this does not support all the features of argparse yet.

Example

Without commando:

def main():
    parser = argparse.ArgumentParser(description='hyde - a python static website generator',
                                  epilog='Use %(prog)s {command} -h to get help on individual commands')
    parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
    parser.add_argument('-s', '--sitepath', action='store', default='.', help="Location of the hyde site")
    subcommands = parser.add_subparsers(title="Hyde commands",
                                     description="Entry points for hyde")
    init_command = subcommands.add_parser('init', help='Create a new hyde site')
    init_command.set_defaults(run=init)
    init_command.add_argument('-t', '--template', action='store', default='basic', dest='template',
                     help='Overwrite the current site if it exists')
    init_command.add_argument('-f', '--force', action='store_true', default=False, dest='force',
                     help='Overwrite the current site if it exists')
    args = parser.parse_args()
    args.run(args)

def init(self, params):
    print params.sitepath
    print params.template
    print params.overwrite

With commando

class Engine(Application):

    @command(description='hyde - a python static website generator',
            epilog='Use %(prog)s {command} -h to get help on individual commands')
    @param('-v', '--version', action='version', version='%(prog)s ' + __version__)
    @param('-s', '--sitepath', action='store', default='.', help="Location of the hyde site")
    def main(self, params): pass

    @subcommand('init', help='Create a new hyde site')
    @param('-t', '--template', action='store', default='basic', dest='template',
            help='Overwrite the current site if it exists')
    @param('-f', '--force', action='store_true', default=False, dest='overwrite',
            help='Overwrite the current site if it exists')
    def init(self, params):
        print params.sitepath
        print params.template
        print params.overwrite

Authors

Lakshmi Vyas Brandon Philips

commando's People

Contributors

navilan avatar philips avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.