Merge lp:~allenap/maas/maas-cli-explain-after-login into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 1237
Proposed branch: lp:~allenap/maas/maas-cli-explain-after-login
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 85 lines (+50/-0)
2 files modified
src/maascli/cli.py (+19/-0)
src/maascli/tests/test_cli.py (+31/-0)
To merge this branch: bzr merge lp:~allenap/maas/maas-cli-explain-after-login
Reviewer Review Type Date Requested Status
Martin Packman (community) Approve
Review via email: mp+128693@code.launchpad.net

Commit message

Print a helpful message after logging in via maas-cli.

Previously it was not obvious what the next step should be.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Looks good, apart from I hate DocTestMatches with a passion.

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

> Looks good, apart from I hate DocTestMatches with a passion.

Thanks. It's close to / past the deadline now, so I'm going to land this, but I'll think about replacing DocTestMatches at some point :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maascli/cli.py'
--- src/maascli/cli.py 2012-10-08 13:39:12 +0000
+++ src/maascli/cli.py 2012-10-09 12:01:20 +0000
@@ -14,6 +14,8 @@
14 'register_cli_commands',14 'register_cli_commands',
15 ]15 ]
1616
17from textwrap import fill
18
17from apiclient.creds import convert_tuple_to_string19from apiclient.creds import convert_tuple_to_string
18from maascli.api import fetch_api_description20from maascli.api import fetch_api_description
19from maascli.auth import obtain_credentials21from maascli.auth import obtain_credentials
@@ -73,6 +75,23 @@
73 "name": profile_name,75 "name": profile_name,
74 "url": options.url,76 "url": options.url,
75 }77 }
78 profile = config[profile_name]
79 self.print_whats_next(profile)
80
81 @staticmethod
82 def print_whats_next(profile):
83 """Explain what to do next."""
84 what_next = [
85 "You are now logged in to the MAAS server at {url} "
86 "with the profile name '{name}'.",
87 "For help with the available commands, try:",
88 " maas-cli {name} --help",
89 ]
90 print()
91 for message in what_next:
92 message = message.format(**profile)
93 print(fill(message))
94 print()
7695
7796
78class cmd_refresh(Command):97class cmd_refresh(Command):
7998
=== modified file 'src/maascli/tests/test_cli.py'
--- src/maascli/tests/test_cli.py 2012-10-08 14:13:24 +0000
+++ src/maascli/tests/test_cli.py 2012-10-09 12:01:20 +0000
@@ -12,9 +12,16 @@
12__metaclass__ = type12__metaclass__ = type
13__all__ = []13__all__ = []
1414
15from cStringIO import StringIO
16import doctest
17import sys
18from textwrap import dedent
19
15from maascli import cli20from maascli import cli
16from maascli.parser import ArgumentParser21from maascli.parser import ArgumentParser
22from maastesting.factory import factory
17from maastesting.testcase import TestCase23from maastesting.testcase import TestCase
24from testtools.matchers import DocTestMatches
1825
1926
20class TestRegisterCLICommands(TestCase):27class TestRegisterCLICommands(TestCase):
@@ -32,3 +39,27 @@
32 self.assertIsInstance(39 self.assertIsInstance(
33 parser.subparsers.choices['login'].get_default('execute'),40 parser.subparsers.choices['login'].get_default('execute'),
34 cli.cmd_login)41 cli.cmd_login)
42
43
44class TestLogin(TestCase):
45
46 def test_print_whats_next(self):
47 profile = {
48 "name": factory.make_name("profile"),
49 "url": factory.make_name("url"),
50 }
51 stdout = self.patch(sys, "stdout", StringIO())
52 cli.cmd_login.print_whats_next(profile)
53 expected = dedent("""\
54
55 You are now logged in to the MAAS server at %(url)s
56 with the profile name '%(name)s'.
57
58 For help with the available commands, try:
59
60 maas-cli %(name)s --help
61
62 """) % profile
63 observed = stdout.getvalue()
64 flags = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE
65 self.assertThat(observed, DocTestMatches(expected, flags))