Merge ~jsseidel/maas:jsseidel-cli-help-format-fix into maas:master

Proposed by Spencer Seidel
Status: Merged
Approved by: Lee Trager
Approved revision: 4f2d169a4a57c5047a7f81995113754c96a3bf3f
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~jsseidel/maas:jsseidel-cli-help-format-fix
Merge into: maas:master
Diff against target: 49 lines (+16/-11)
1 file modified
src/maasserver/api/doc.py (+16/-11)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Andres Rodriguez (community) Approve
Review via email: mp+359080@code.launchpad.net

Commit message

Fixed incorrect formatting of CLI help for docstrings containing API annotations.

Description of the change

If empty lines were present between @param tags in an annotated API docstring, the resulting CLI help would not be correctly formatted. Empty lines would result in CLI help that looked like this:

----snip
:param foo: some description

:type foo: unicode
:param nextfoo: the next param's description

:type nextfoo: unicode
----snip

This is because annotation tag description fields were not being rstripped before output.

Now, regardless of empty lines, the CLI format should be consistently formatted.

To post a comment you must log in.
Revision history for this message
Andres Rodriguez (andreserl) wrote :

lgtm!

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b jsseidel-cli-help-format-fix lp:~jsseidel/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 4f2d169a4a57c5047a7f81995113754c96a3bf3f

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/api/doc.py b/src/maasserver/api/doc.py
2index 08df55d..861e5af 100644
3--- a/src/maasserver/api/doc.py
4+++ b/src/maasserver/api/doc.py
5@@ -229,12 +229,14 @@ def describe_actions(handler):
6 # to stdout that matches the style used for
7 # non-annotated docstrings in the CLI.
8 ap.parse(doc)
9- d = ap.get_dict()
10- if d['description_title'] != "":
11- doc = d['description_title'] + "\n\n"
12- doc += d['description'] + "\n\n"
13+ ap_dict = ap.get_dict()
14+ description = ap_dict['description'].rstrip()
15+ description_title = ap_dict['description_title'].rstrip()
16+ if description_title != "":
17+ doc = description_title + "\n\n"
18+ doc += description + "\n\n"
19 else:
20- doc = d['description'] + "\n\n"
21+ doc = description + "\n\n"
22
23 # Here, we add the params, but we skip params
24 # surrounded by curly brackets (e.g. {foo})
25@@ -242,15 +244,18 @@ def describe_actions(handler):
26 # the URI (e.g. /zone/{name}/). I.e. positional
27 # arguments. These already appear in the CLI
28 # help command output so we don't want duplicates.
29- for p in d['params']:
30- if p['name'].find("{") == -1 and p['name'].find("}") == -1:
31+ for param in ap_dict['params']:
32+ pname = param['name']
33+ if pname.find("{") == -1 and pname.find("}") == -1:
34 required = "Required. "
35- if p['options']['required'] == "false":
36+ if param['options']['required'] == "false":
37 required = "Optional. "
38
39- doc += (":param %s: %s%s" %
40- (p['name'], required, p['description']))
41- doc += (":type %s: %s\n " % (p['name'], p['type']))
42+ param_description = param['description'].rstrip()
43+
44+ doc += (":param %s: %s%s\n" %
45+ (pname, required, param_description))
46+ doc += (":type %s: %s\n\n " % (pname, param['type']))
47
48 yield dict(
49 method=http_method, name=name, doc=doc,

Subscribers

People subscribed via source and target branches