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
1=== modified file 'src/maascli/cli.py'
2--- src/maascli/cli.py 2012-10-08 13:39:12 +0000
3+++ src/maascli/cli.py 2012-10-09 12:01:20 +0000
4@@ -14,6 +14,8 @@
5 'register_cli_commands',
6 ]
7
8+from textwrap import fill
9+
10 from apiclient.creds import convert_tuple_to_string
11 from maascli.api import fetch_api_description
12 from maascli.auth import obtain_credentials
13@@ -73,6 +75,23 @@
14 "name": profile_name,
15 "url": options.url,
16 }
17+ profile = config[profile_name]
18+ self.print_whats_next(profile)
19+
20+ @staticmethod
21+ def print_whats_next(profile):
22+ """Explain what to do next."""
23+ what_next = [
24+ "You are now logged in to the MAAS server at {url} "
25+ "with the profile name '{name}'.",
26+ "For help with the available commands, try:",
27+ " maas-cli {name} --help",
28+ ]
29+ print()
30+ for message in what_next:
31+ message = message.format(**profile)
32+ print(fill(message))
33+ print()
34
35
36 class cmd_refresh(Command):
37
38=== modified file 'src/maascli/tests/test_cli.py'
39--- src/maascli/tests/test_cli.py 2012-10-08 14:13:24 +0000
40+++ src/maascli/tests/test_cli.py 2012-10-09 12:01:20 +0000
41@@ -12,9 +12,16 @@
42 __metaclass__ = type
43 __all__ = []
44
45+from cStringIO import StringIO
46+import doctest
47+import sys
48+from textwrap import dedent
49+
50 from maascli import cli
51 from maascli.parser import ArgumentParser
52+from maastesting.factory import factory
53 from maastesting.testcase import TestCase
54+from testtools.matchers import DocTestMatches
55
56
57 class TestRegisterCLICommands(TestCase):
58@@ -32,3 +39,27 @@
59 self.assertIsInstance(
60 parser.subparsers.choices['login'].get_default('execute'),
61 cli.cmd_login)
62+
63+
64+class TestLogin(TestCase):
65+
66+ def test_print_whats_next(self):
67+ profile = {
68+ "name": factory.make_name("profile"),
69+ "url": factory.make_name("url"),
70+ }
71+ stdout = self.patch(sys, "stdout", StringIO())
72+ cli.cmd_login.print_whats_next(profile)
73+ expected = dedent("""\
74+
75+ You are now logged in to the MAAS server at %(url)s
76+ with the profile name '%(name)s'.
77+
78+ For help with the available commands, try:
79+
80+ maas-cli %(name)s --help
81+
82+ """) % profile
83+ observed = stdout.getvalue()
84+ flags = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE
85+ self.assertThat(observed, DocTestMatches(expected, flags))