~maas-committers/maas/1.2

« back to all changes in this revision

Viewing changes to src/maascli/api.py

  • Committer: Tarmac
  • Author(s): Julian Edwards, Jeroen Vermeulen
  • Date: 2012-12-03 05:20:26 UTC
  • mfrom: (1316.1.2 backport-r1265-1267)
  • Revision ID: tarmac-20121203052026-crp2z5sq93c4saki
[r=julian-edwards][bug=1085788][author=julian-edwards] Rearrange maas-cli's --help output, and add to the API docstrings (backport r1265, r1267 from trunk)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import json
22
22
from operator import itemgetter
23
23
import sys
 
24
from textwrap import (
 
25
    dedent,
 
26
    fill,
 
27
    )
24
28
from urlparse import (
25
29
    urljoin,
26
30
    urlparse,
257
261
            }
258
262
        action_class = type(action_name, action_bases, action_ns)
259
263
        action_parser = parser.subparsers.add_parser(
260
 
            action_name, help=help_title, description=help_body)
 
264
            action_name, help=help_title, description=help_title,
 
265
            epilog=help_body)
261
266
        action_parser.set_defaults(
262
267
            execute=action_class(action_parser))
263
268
 
267
272
    help_title, help_body = parse_docstring(handler["doc"])
268
273
    handler_name = handler_command_name(handler["name"])
269
274
    handler_parser = parser.subparsers.add_parser(
270
 
        handler_name, help=help_title, description=help_body)
 
275
        handler_name, help=help_title, description=help_title,
 
276
        epilog=help_body)
271
277
    register_actions(profile, handler, handler_parser)
272
278
 
273
279
 
308
314
            register_handler(profile, represent_as, parser)
309
315
 
310
316
 
 
317
profile_help = '\n\n'.join(
 
318
    map(fill, map(dedent, [
 
319
    """\
 
320
        This is a profile.  Any commands you issue on this
 
321
        profile will operate on the MAAS region server.
 
322
        """,
 
323
    """\
 
324
        The command information you see here comes from the
 
325
        region server's API; it may differ for different
 
326
        profiles.  If you believe the API may have changed,
 
327
        use the command's 'refresh' sub-command to fetch the
 
328
        latest version of this help information from the
 
329
        server.
 
330
        """,
 
331
    ])))
 
332
 
 
333
 
311
334
def register_api_commands(parser):
312
335
    """Register all profiles as subcommands on `parser`."""
313
336
    with ProfileConfig.open() as config:
314
337
        for profile_name in config:
315
338
            profile = config[profile_name]
316
339
            profile_parser = parser.subparsers.add_parser(
317
 
                profile["name"], help="Interact with %(url)s" % profile)
 
340
                profile["name"], help="Interact with %(url)s" % profile,
 
341
                description=(
 
342
                    "Issue commands to the MAAS region controller at %(url)s."
 
343
                    % profile),
 
344
                epilog=profile_help)
318
345
            register_resources(profile, profile_parser)