Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
e5170771
Commit
e5170771
authored
Feb 23, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2120 from jpmens/doc_ex1
Add support for additional EXAMPLES string in Ansible modules
parents
f7fb681b
396a07bc
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
7 deletions
+50
-7
bin/ansible-doc
+6
-2
docsite/rst/moduledev.rst
+13
-0
hacking/module_formatter.py
+2
-1
hacking/templates/man.j2
+7
-0
hacking/templates/markdown.j2
+5
-1
hacking/templates/rst.j2
+8
-0
lib/ansible/utils/module_docs.py
+9
-3
No files found.
bin/ansible-doc
View file @
e5170771
...
...
@@ -91,6 +91,9 @@ def print_man(doc):
for
ex
in
doc
[
'examples'
]:
print
"
%
s
\n
"
%
(
ex
[
'code'
])
if
'plainexamples'
in
doc
and
doc
[
'plainexamples'
]
is
not
None
:
print
doc
[
'plainexamples'
]
def
print_snippet
(
doc
):
desc
=
tty_ify
(
""
.
join
(
doc
[
'short_description'
]))
...
...
@@ -153,7 +156,7 @@ def main():
filename
=
utils
.
plugins
.
module_finder
.
find_plugin
(
module
)
try
:
doc
=
module_docs
.
get_docstring
(
filename
)
doc
,
plainexamples
=
module_docs
.
get_docstring
(
filename
)
desc
=
tty_ify
(
doc
.
get
(
'short_description'
,
'?'
))
if
len
(
desc
)
>
55
:
desc
=
desc
+
'...'
...
...
@@ -180,7 +183,7 @@ def main():
continue
try
:
doc
=
module_docs
.
get_docstring
(
filename
)
doc
,
plainexamples
=
module_docs
.
get_docstring
(
filename
)
except
:
traceback
.
print_exc
()
sys
.
stderr
.
write
(
"ERROR: module
%
s has a documentation error formatting or is missing documentation
\n
"
%
module
)
...
...
@@ -197,6 +200,7 @@ def main():
doc
[
'filename'
]
=
filename
doc
[
'docuri'
]
=
doc
[
'module'
]
.
replace
(
'_'
,
'-'
)
doc
[
'now_date'
]
=
datetime
.
date
.
today
()
.
strftime
(
'
%
Y-
%
m-
%
d'
)
doc
[
'plainexamples'
]
=
plainexamples
if
options
.
show_snippet
:
print_snippet
(
doc
)
...
...
docsite/rst/moduledev.rst
View file @
e5170771
...
...
@@ -354,6 +354,19 @@ for URL, module, italic, and constant-width respectively. It is suggested
to use ``C()`` for file and option names, and ``I()`` when referencing
parameters; module names should be specifies as ``M(module)``.
Examples (which typically contain colons, quotes, etc.) are difficult
to format with YAML, so these can (alternatively, or additionally) be
written in plain text in an ``EXAMPLES`` string within the module
like this::
EXAMPLES = '''
- action: modulename opt1=arg1 opt2=arg2
'''
The ``module_formatter.py`` script and ``ansible-doc(1)`` append the
``EXAMPLES`` blob after any existing ``examples`` you may have in the
YAML ``DOCUMENTATION`` string.
Building & Testing
++++++++++++++++++
...
...
hacking/module_formatter.py
View file @
e5170771
...
...
@@ -296,7 +296,7 @@ def main():
js_data
.
append
(
j
)
continue
doc
=
ansible
.
utils
.
module_docs
.
get_docstring
(
fname
,
verbose
=
options
.
verbose
)
doc
,
examples
=
ansible
.
utils
.
module_docs
.
get_docstring
(
fname
,
verbose
=
options
.
verbose
)
if
doc
is
None
and
module
not
in
ansible
.
utils
.
module_docs
.
BLACKLIST_MODULES
:
sys
.
stderr
.
write
(
"*** ERROR: CORE MODULE MISSING DOCUMENTATION:
%
s ***
\n
"
%
module
)
...
...
@@ -314,6 +314,7 @@ def main():
doc
[
'docuri'
]
=
doc
[
'module'
]
.
replace
(
'_'
,
'-'
)
doc
[
'now_date'
]
=
datetime
.
date
.
today
()
.
strftime
(
'
%
Y-
%
m-
%
d'
)
doc
[
'ansible_version'
]
=
options
.
ansible_version
doc
[
'plainexamples'
]
=
examples
#plain text
if
options
.
includes_file
is
not
None
and
includefmt
!=
""
:
incfile
.
write
(
includefmt
%
module
)
...
...
hacking/templates/man.j2
View file @
e5170771
...
...
@@ -56,6 +56,13 @@
.fi
{% endfor %}
{% endif %}
." ------ PLAINEXAMPLES
{% if plainexamples is defined %}
.nf
@{ plainexamples }@
.fi
{% endif %}
." ------- AUTHOR
{% if author is defined %}
.SH AUTHOR
...
...
hacking/templates/markdown.j2
View file @
e5170771
...
...
@@ -44,7 +44,11 @@ New in version @{ version_added }@.
@{ example['code'] }@
```
{% endfor %}
{% if plainexamples -%}
```
@{ plainexamples }@
```
{% endif %}
{% if notes %}
#### Notes
...
...
hacking/templates/rst.j2
View file @
e5170771
...
...
@@ -54,6 +54,14 @@
{% endfor %}
<br/>
{% if plainexamples %}
.. raw:: html
<pre>
@{ plainexamples | escape | indent(4, True) }@
</pre>
{% endif %}
{% if notes %}
.. raw:: html
...
...
lib/ansible/utils/module_docs.py
View file @
e5170771
...
...
@@ -30,11 +30,14 @@ BLACKLIST_MODULES = [
def
get_docstring
(
filename
,
verbose
=
False
):
"""
Search for assignment of the DOCUMENTATION variable in the given file.
Parse that from YAML and return the YAML doc or None.
Search for assignment of the DOCUMENTATION and EXAMPLES variables
in the given file.
Parse DOCUMENTATION from YAML and return the YAML doc or None
together with EXAMPLES, as plain text.
"""
doc
=
None
plainexamples
=
None
try
:
# Thank you, Habbie, for this bit of code :-)
...
...
@@ -43,8 +46,11 @@ def get_docstring(filename, verbose=False):
if
isinstance
(
child
,
ast
.
Assign
):
if
'DOCUMENTATION'
in
(
t
.
id
for
t
in
child
.
targets
):
doc
=
yaml
.
load
(
child
.
value
.
s
)
if
'EXAMPLES'
in
(
t
.
id
for
t
in
child
.
targets
):
plainexamples
=
child
.
value
.
s
[
1
:]
# Skip first empty line
except
:
if
verbose
==
True
:
traceback
.
print_exc
()
print
"unable to parse
%
s"
%
filename
return
doc
return
doc
,
plainexamples
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment