← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/maas/bug-1052876 into lp:maas

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/bug-1052876 into lp:maas.

Commit message:
Print more helpful error message when maas-cli is run without arguments.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1052876 in MAAS: "When invoked without arguments, maascli is too terse"
  https://bugs.launchpad.net/maas/+bug/1052876

For more details, see:
https://code.launchpad.net/~jtv/maas/bug-1052876/+merge/134915

As discussed very briefly on the daily call.  I make the invocation fail with error code 2 because that's what it did previously.


Jeroen
-- 
https://code.launchpad.net/~jtv/maas/bug-1052876/+merge/134915
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/bug-1052876 into lp:maas.
=== modified file 'src/maascli/__init__.py'
--- src/maascli/__init__.py	2012-10-08 14:07:24 +0000
+++ src/maascli/__init__.py	2012-11-19 13:55:25 +0000
@@ -28,6 +28,14 @@
     if argv is None:
         argv = sys.argv[:1] + osutils.get_unicode_argv()
 
+    if len(argv) == 1:
+        # No arguments passed.  Be helpful and point out the --help option.
+        sys.stderr.write(
+            "Error: no arguments given.\n"
+            "Run %s --help for usage details.\n"
+            % argv[0])
+        raise SystemExit(2)
+
     parser = prepare_parser(argv)
 
     # Run, doing polite things with exceptions.

=== modified file 'src/maascli/tests/test_integration.py'
--- src/maascli/tests/test_integration.py	2012-10-04 08:36:34 +0000
+++ src/maascli/tests/test_integration.py	2012-11-19 13:55:25 +0000
@@ -33,15 +33,29 @@
 
 class TestMAASCli(TestCase):
 
+    output_file = '/dev/null'
+
     def run_command(self, *args):
-        with open('/dev/null', 'ab') as dev_null:
+        with open(self.output_file, 'ab') as output:
             check_call(
                 [locate_maascli()] + list(args),
-                stdout=dev_null, stderr=dev_null)
+                stdout=output, stderr=output)
 
     def test_run_without_args_fails(self):
         self.assertRaises(CalledProcessError, self.run_command)
 
+    def test_run_without_args_shows_help_reminder(self):
+        self.output_file = self.make_file('output')
+        try:
+            self.run_command()
+        except CalledProcessError:
+            pass
+        with open(self.output_file, 'rb') as captured_output:
+            output = captured_output.read()
+        self.assertIn(
+            "Run %s --help for usage details." % locate_maascli(),
+            output)
+
     def test_help_option_succeeds(self):
         self.run_command('-h')
         # The test is that we get here without error.


Follow ups