Skip to content

Instantly share code, notes, and snippets.

@lost-theory
Created June 4, 2012 23:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lost-theory/2871500 to your computer and use it in GitHub Desktop.
Save lost-theory/2871500 to your computer and use it in GitHub Desktop.
my new fabric wrapping technique is unstoppable
DESC = "command description goes here"
def usage():
print "%s - %s\n" % (__file__, DESC)
print "Note: use %s --fab-help to get help on arguments specific to" % __file__
print " fabric (roles, hosts, parallel execution, etc.)\n"
new_argv = ['fab', '-f', __file__, '--list']
sys.argv = new_argv
fabric.main.main()
if __name__ == "__main__":
import fabric.main
import sys
sys.argv.pop(0)
#XXX: do custom preprocessing of argv here (e.g. replace a custom flag with a flag fabric is expecting)
if not sys.argv or '--help' in sys.argv:
usage()
elif '--fab-help' in sys.argv:
new_argv = ['fab', '-f', __file__, '--help']
else:
new_argv = ['fab', '-f', __file__] + sys.argv
sys.argv = new_argv
fabric.main.main()
# $ cmd.py
# will show you a nice description and list of subcommands
# $ cmd.py --help
# will show the same
# $ cmd.py --list
# will show a nice short list of subcommands
# $ cmd.py --fab-help
# will show the complete list of fabric-specific options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment