39 if 'robot' not in sys.modules
and __name__ ==
'__main__':
40 import pythonpathsetter
47 USAGE =
"""robot.libdoc -- Robot Framework library documentation generator
51 Usage: python -m robot.libdoc [options] library output_file
52 or: python -m robot.libdoc [options] library list|show|version [names]
54 Libdoc tool can generate keyword documentation in HTML and XML formats both
55 for test libraries and resource files. HTML format is suitable for humans and
56 XML specs for RIDE and other tools. Libdoc also has few special commands to
57 show library or resource information on the console.
59 Libdoc supports all library and resource types and also earlier generated XML
60 specs can be used as input. If a library needs arguments, they must be given
61 as part of the library name and separated by two colons, for example, like
62 `LibraryName::arg1::arg2`.
67 -f --format HTML|XML Specifies whether to generate HTML or XML output.
68 If this options is not used, the format is got
69 from the extension of the output file.
70 -F --docformat ROBOT|HTML|TEXT|REST
71 Specifies the source documentation format. Possible
72 values are Robot Framework's documentation format,
73 HTML, plain text, and reStructuredText. The default
74 value can be specified in test library source code
75 and the initial default value is `ROBOT`.
76 -n --name newname Sets the name of the documented library or resource.
77 -v --version newversion Sets the version of the documented library or
79 -P --pythonpath path * Additional locations where to search for libraries
81 -E --escape what:with * Deprecated. Use console escape mechanism instead.
82 -h -? --help Print this help.
84 Creating documentation
85 ======================
87 When creating documentation in HTML or XML format, the output file must
88 be specified as a second argument after the library/resource name or path.
89 Output format is got automatically from the extension but can also be set
90 with `--format` option.
94 python -m robot.libdoc src/MyLib.py doc/MyLib.html
95 jython -m robot.libdoc MyJavaLibrary.java MyJavaLibrary.html
96 python -m robot.libdoc --name MyLib Remote::10.0.0.42:8270 MyLib.xml
98 Viewing information on console
99 ==============================
101 Libdoc has three special commands to show information on the console. These
102 commands are used instead of the name of the output file, and they can also
103 take additional arguments.
105 list: List names of the keywords the library/resource contains. Can be
106 limited to show only certain keywords by passing optional patterns as
107 arguments. Keyword is listed if its name contains any given pattern.
108 show: Show library/resource documentation. Can be limited to show only
109 certain keywords by passing names as arguments. Keyword is shown if
110 its name matches any given name. Special argument `intro` will show
111 the library introduction and importing sections.
112 version: Show library version
114 Optional patterns given to `list` and `show` are case and space insensitive.
115 Both also accept `*` and `?` as wildcards.
119 python -m robot.libdoc Dialogs list
120 python -m robot.libdoc Selenium2Library list browser
121 python -m robot.libdoc Remote::10.0.0.42:8270 show
122 python -m robot.libdoc Dialogs show PauseExecution execute*
123 python -m robot.libdoc Selenium2Library show intro
124 python -m robot.libdoc Selenium2Library version
126 Alternative execution
127 =====================
129 Libdoc works with all interpreters supported by Robot Framework (Python,
130 Jython and IronPython). In the examples above Libdoc is executed as an
131 installed module, but it can also be executed as a script like
132 `python path/robot/libdoc.py`.
134 For more information about Libdoc and other built-in tools, see
135 http://robotframework.org/robotframework/#built-in-tools.
142 Application.__init__(self, USAGE, arg_limits=(2,), auto_version=
False)
145 if ConsoleViewer.handles(arguments[1]):
146 ConsoleViewer.validate_command(arguments[1], arguments[2:])
147 elif len(arguments) > 2:
148 raise DataError(
'Only two arguments allowed when writing output.')
149 return options, arguments
151 def main(self, args, name='', version='', format=None, docformat=None):
152 lib_or_res, output = args[:2]
155 if ConsoleViewer.handles(output):
156 ConsoleViewer(libdoc).view(output, *args[2:])
159 self.console(os.path.abspath(output))
165 [
'ROBOT',
'TEXT',
'HTML',
'REST'])
168 default = os.path.splitext(output)[1][1:]
169 return self.
_verify_format_verify_format(
'Format', format
or default, [
'HTML',
'XML'])
172 format = format.upper()
173 if format
not in valid:
174 raise DataError(
"%s must be %s, got '%s'."
175 % (type,
seq2str(valid, lastsep=
' or '), format))
194 LibDoc().execute_cli(arguments)
222 def libdoc(library_or_resource, outfile, name='', version='', format=None,
224 LibDoc().execute(library_or_resource, outfile, name=name, version=version,
225 format=format, docformat=docformat)
228 if __name__ ==
'__main__':
Used when variable does not exist.
def _get_output_format(self, format, output)
def _get_doc_format(self, format)
def _verify_format(self, type, format, valid)
def main(self, args, name='', version='', format=None, docformat=None)
def validate(self, options, arguments)
def libdoc(library_or_resource, outfile, name='', version='', format=None, docformat=None)
Executes Libdoc.
def libdoc_cli(arguments)
Executes Libdoc similarly as from the command line.
def LibraryDocumentation(library_or_resource, name=None, version=None, doc_format=None)
def seq2str(sequence, quote="'", sep=', ', lastsep=' and ')
Returns sequence in format ‘'item 1’, 'item 2' and 'item 3'`.