Merge lp://qastaging/~jtv/maas/bug-1189742 into lp://qastaging/~maas-committers/maas/trunk

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 2036
Proposed branch: lp://qastaging/~jtv/maas/bug-1189742
Merge into: lp://qastaging/~maas-committers/maas/trunk
Diff against target: 440 lines (+366/-6)
3 files modified
src/maascli/api.py (+125/-4)
src/maascli/tests/test_api.py (+238/-0)
src/maasserver/forms_settings.py (+3/-2)
To merge this branch: bzr merge lp://qastaging/~jtv/maas/bug-1189742
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+208617@code.qastaging.launchpad.net

Commit message

Custom-formatted help output for API operations in the CLI. The default formatting was unhelpful and, in particular, didn't explain how to pass parameters.

Help output for handlers (which do not take parameters) remains unchanged, as does the global help output.

Description of the change

As a simple example, compare the old output:

«
$ ./bin/maas test zone read -h
usage: ./bin/maas test zone read [-h] [-d] [-k] name [data [data ...]]

GET request. Return zone.

positional arguments:
  name
  data

optional arguments:
  -h, --help show this help message and exit
  -d, --debug Display more information about API responses.
  -k, --insecure Disable SSL certificate check
»

...to the new output:

«
$ ./bin/maas test zone read -h
usage: ./bin/maas test zone read [--help] [-d] [-k] name [data [data ...]]

GET request. Return zone.

Positional arguments:
 name

Common command-line options:
    --help, -h
 Show this help message and exit.
    -d, --debug
 Display more information about API responses.
    -k, --insecure
 Disable SSL certificate check
»

The pointless "data" argument is gone, and most sentences are properly capitalised, and spacing is generally a bit more generous. Otherwise, these basic examples should be similar.

A more involved example... Old output:

«
$ ./bin/maas test tag update -h
usage: ./bin/maas test tag update [-h] [-d] [-k] name [data [data ...]]

Update a specific Tag.

positional arguments:
  name
  data

optional arguments:
  -h, --help show this help message and exit
  -d, --debug Display more information about API responses.
  -k, --insecure Disable SSL certificate check

:param name: The name of the Tag to be created. This should be a short
    name, and will be used in the URL of the tag.
:param comment: A long form description of what the tag is meant for.
    It is meant as a human readable description of the tag.
:param definition: An XPATH query that will be evaluated against the
    hardware_details stored for all nodes (output of `lshw -xml`).
»

And new output:

«
$ ./bin/maas test tag update -h
usage: ./bin/maas test tag update [--help] [-d] [-k] name [data [data ...]]

Update a specific Tag.

Positional arguments:
 name

This method accepts keyword arguments. Pass each argument as a
key-value pair with an equals sign between the key and the value:
key1=value1 key2=value key3=value3. Keyword arguments must come after
any positional arguments.

:param name: The name of the Tag to be created. This should be a short
    name, and will be used in the URL of the tag.
:param comment: A long form description of what the tag is meant for.
    It is meant as a human readable description of the tag.
:param definition: An XPATH query that will be evaluated against the
    hardware_details stored for all nodes (output of `lshw -xml`).

Common command-line options:
    --help, -h
 Show this help message and exit.
    -d, --debug
 Display more information about API responses.
    -k, --insecure
 Disable SSL certificate check
»

We could still do better on the usage string, but this was work enough for now!

Jeroen

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Bootiful!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.