diff --git a/certbot/cli.py b/certbot/cli.py index 05a189712..4ffa7ea3b 100644 --- a/certbot/cli.py +++ b/certbot/cli.py @@ -334,7 +334,7 @@ class HelpfulArgumentParser(object): # Do any post-parsing homework here - if self.verb == "renew": + if self.verb == "renew" and not parsed_args.dialog_mode: parsed_args.noninteractive_mode = True if parsed_args.staging or parsed_args.dry_run: @@ -346,6 +346,16 @@ class HelpfulArgumentParser(object): if parsed_args.must_staple: parsed_args.staple = True + # Avoid conflicting args + conficting_args = ["quiet", "noninteractive_mode", "text_mode"] + if parsed_args.dialog_mode: + for arg in conficting_args: + if getattr(parsed_args, arg): + raise errors.Error( + ("Conflicting values for displayer." + " {0} conflicts with dialog_mode").format(arg) + ) + hooks.validate_hooks(parsed_args) return parsed_args @@ -570,6 +580,9 @@ def prepare_and_parse_args(plugins, args, detect_defaults=False): :rtype: argparse.Namespace """ + + # pylint: disable=too-many-statements + helpful = HelpfulArgumentParser(args, plugins, detect_defaults) # --help is automatically provided by argparse @@ -587,6 +600,9 @@ def prepare_and_parse_args(plugins, args, detect_defaults=False): help="Run without ever asking for user input. This may require " "additional command line flags; the client will try to explain " "which ones are required if it finds one missing") + helpful.add( + None, "--dialog", dest="dialog_mode", action="store_true", + help="Run using dialog") helpful.add( None, "--dry-run", action="store_true", dest="dry_run", help="Perform a test run of the client, obtaining test (invalid) certs" diff --git a/certbot/tests/cli_test.py b/certbot/tests/cli_test.py index 00c9a0a26..5d4237d22 100644 --- a/certbot/tests/cli_test.py +++ b/certbot/tests/cli_test.py @@ -149,6 +149,14 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods args.extend(['--email', 'io@io.is']) self._cli_missing_flag(args, "--agree-tos") + @mock.patch('certbot.main.renew') + def test_gui(self, renew): + args = ['renew', '--dialog'] + # --text conflicts with --dialog + self.standard_args.remove('--text') + self._call(args) + self.assertFalse(renew.call_args[0][0].noninteractive_mode) + @mock.patch('certbot.main.client.acme_client.Client') @mock.patch('certbot.main._determine_account') @mock.patch('certbot.main.client.Client.obtain_and_enroll_certificate') @@ -907,6 +915,10 @@ class CLITest(unittest.TestCase): # pylint: disable=too-many-public-methods self._call(['-c', test_util.vector_path('cli.ini')]) self.assertTrue(mocked_run.called) + def test_conflicting_args(self): + args = ['renew', '--dialog', '--text'] + self.assertRaises(errors.Error, self._call, args) + class DetermineAccountTest(unittest.TestCase): """Tests for certbot.cli._determine_account."""