Skip to main content

A declarative interface to argparse with additional utilities

Project description

Version 0.3.4

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.

Commando also bundles a few utilities that are useful when building command line applications.

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

Resources

  1. Changelog

  2. License

  3. Contributing

  4. Authors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

commando-0.3.4.tar.gz (15.9 kB view details)

Uploaded Source

File details

Details for the file commando-0.3.4.tar.gz.

File metadata

  • Download URL: commando-0.3.4.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for commando-0.3.4.tar.gz
Algorithm Hash digest
SHA256 2bde3af093e64d93e9cb9fd657ee24cbb6956bd973aecc323dcb7f0c84bdf639
MD5 33c6ec2e7de6d24584fb08cc61029fc9
BLAKE2b-256 995321658735be516b4e782ff6b7476493bcfde5cd8bfac2da9c6b5a567583cc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page