Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

added documentation for getting autogenerated help #590

Open
wants to merge 1 commit into from

2 participants

@wolfgangpfnuer

I found that bin/fab -l was way too short for the documentation i wanted to give my fellow colleagues, so i went ahead and created a help method that is more verbose (and colorful) with help of https://github.com/mfelsche

Im not sure wether this can (or should) be integrated in a long version of bin/fab -l (-ll maybe?), but i think it should be in the documentation how to achieve something like this.

@bitprophet
Owner

There is already a -d flag that spits out the docstring. I'd be fine with making that feature more presentable in this way (re: colors and such) but I don't think adding another new option that does the same thing makes sense.

@wolfgangpfnuer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 15, 2012
  1. added instructions for getting autogenerated help

    Wolfgang Pfnür authored
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 0 deletions.
  1. +40 −0 docs/usage/help.rst
View
40 docs/usage/help.rst
@@ -0,0 +1,40 @@
+==================
+Autogenerated Help
+==================
+
+If you write a file containing many tasks, then you might want to have your help autogenerated from your docstrings.
+To do this, simply paste the following lines into your file containing the tasks::
+
+ from fabric.colors import red, magenta, yellow
+ import fabric
+ import sys
+
+ @task(default = True)
+ def help():
+ """Prints the help
+
+ All callable methods with @task are printed, along with their docstring.
+ """
+ print_help_header()
+ mod = sys.modules[__name__]
+ for attr in dir(mod):
+ attribute = getattr(mod, attr)
+ if isinstance(attribute, fabric.tasks.Task):
+ print_help_attribute(attribute)
+
+ def print_help_header():
+ text = '%s HELP' % __name__.upper()
+ print yellow ('=' * len(text))
+ print yellow (text)
+ print yellow ('=' * len(text))
+
+ def print_help_attribute(attribute):
+ print
+ print magenta (attribute.__name__)
+ print magenta ('=' * len(attribute.__name__))
+ print
+ lines = attribute.__doc__.split('\n')
+ print magenta ('%s' % lines[0])
+ for line in lines[1:]:
+ print red ('%s' % line)
+
Something went wrong with that request. Please try again.