launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #13176
[Merge] lp:~allenap/maas/maas-cli-explain-after-login into lp:maas
Gavin Panella has proposed merging lp:~allenap/maas/maas-cli-explain-after-login into lp:maas.
Commit message:
Print a helpful message after logging in via maas-cli.
Previously it was not obvious what the next step should be.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~allenap/maas/maas-cli-explain-after-login/+merge/128693
--
https://code.launchpad.net/~allenap/maas/maas-cli-explain-after-login/+merge/128693
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/maas-cli-explain-after-login into lp:maas.
=== modified file 'src/maascli/cli.py'
--- src/maascli/cli.py 2012-10-08 13:39:12 +0000
+++ src/maascli/cli.py 2012-10-09 11:57:22 +0000
@@ -14,6 +14,8 @@
'register_cli_commands',
]
+from textwrap import fill
+
from apiclient.creds import convert_tuple_to_string
from maascli.api import fetch_api_description
from maascli.auth import obtain_credentials
@@ -73,6 +75,23 @@
"name": profile_name,
"url": options.url,
}
+ profile = config[profile_name]
+ self.print_whats_next(profile)
+
+ @staticmethod
+ def print_whats_next(profile):
+ """Explain what to do next."""
+ what_next = [
+ "You are now logged in to the MAAS server at {url} "
+ "with the profile name '{name}'.",
+ "For help with the available commands, try:",
+ " maas-cli {name} --help",
+ ]
+ print()
+ for message in what_next:
+ message = message.format(**profile)
+ print(fill(message))
+ print()
class cmd_refresh(Command):
=== 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 11:57:22 +0000
@@ -12,9 +12,16 @@
__metaclass__ = type
__all__ = []
+from cStringIO import StringIO
+import doctest
+import sys
+from textwrap import dedent
+
from maascli import cli
from maascli.parser import ArgumentParser
+from maastesting.factory import factory
from maastesting.testcase import TestCase
+from testtools.matchers import DocTestMatches
class TestRegisterCLICommands(TestCase):
@@ -32,3 +39,27 @@
self.assertIsInstance(
parser.subparsers.choices['login'].get_default('execute'),
cli.cmd_login)
+
+
+class TestLogin(TestCase):
+
+ def test_print_whats_next(self):
+ profile = {
+ "name": factory.make_name("profile"),
+ "url": factory.make_name("url"),
+ }
+ stdout = self.patch(sys, "stdout", StringIO())
+ cli.cmd_login.print_whats_next(profile)
+ expected = dedent("""\
+
+ You are now logged in to the MAAS server at %(url)s
+ with the profile name '%(name)s'.
+
+ For help with the available commands, try:
+
+ maas-cli %(name)s --help
+
+ """) % profile
+ observed = stdout.getvalue()
+ flags = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE
+ self.assertThat(observed, DocTestMatches(expected, flags))