Skip to content

Instantly share code, notes, and snippets.

@aliles
Last active December 20, 2015 01:19
Show Gist options
  • Save aliles/6048488 to your computer and use it in GitHub Desktop.
Save aliles/6048488 to your computer and use it in GitHub Desktop.
Example help output generated by the new subcommands feature for the next release of begins. https://github.com/aliles/begins
$ python subcommands.py --help
usage: subcommands.py [-h] [-v | -q]
[--loglvl {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
[--logfile LOGFILE] [--logfmt LOGFMT]
{goodbye,hello} ...
Greetings and salutations
optional arguments:
-h, --help show this help message and exit
-v, --verbose Increse logging output
-q, --quiet Decrease logging output
Available subcommands:
{goodbye,hello}
goodbye Say goodbye
hello Say hello
logging:
Detailed control of logging output
--loglvl {DEBUG,INFO,WARNING,ERROR,CRITICAL}
Set explicit log level
--logfile LOGFILE Ouput log messages to file
--logfmt LOGFMT Log message format
$ python subcommands.py hello --help
usage: subcommands.py hello [-h] -n NAME
optional arguments:
-h, --help show this help message and exit
-n NAME, --name NAME
$ python subcommands.py hello -n Mick
Hello Mick
import begin
import logging
@begin.subcommand
def hello(name):
"Say hello"
logging.info("Hello {0}".format(name))
@begin.subcommand
def goodbye(name):
"Say goodbye"
logging.info("Goodbye {0}".format(name))
@begin.start
@begin.logging
def main():
"Greetings and salutations"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment