Created
June 4, 2012 23:35
-
-
Save lost-theory/2871500 to your computer and use it in GitHub Desktop.
my new fabric wrapping technique is unstoppable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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