mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 08:05:31 +02:00
Stop using print in certbot.cli module. (#5028)
* Update cerbot.tests.util.patch_get_utility (#3720) * Add new arg `stdout_notification` to `cerbot.tests.util.patch_get_utility` function. If `stdout_notification` is True, then the mock interfaces.IDisplay.notification function will print out to stdout. * Add new arg `stdout_notification` to _create_get_utility_mock function. * Add new function `_stdout_notification`. * Stop using print in certbot.cli (#3720) * certbot/cli.py (HelpfulArgumentParser._usage_string) (HelpfulArgumentParser.__init__): Update methods. * certbot/tests/cli_test.py (test_cli_ini_domains, test_no_args) (test_install_abspath, test_help, test_help_no_dashes) (test_parse_domains, test_preferred_challenges, test_server_flag) (test_must_staple_flag, test_no_gui, test_staging_flag) (test_dry_run_flag, test_option_was_set) (test_encode_revocation_reason, test_force_interactive) (test_deploy_hook_conflict, test_deploy_hook_matches_renew_hook) (test_deploy_hook_sets_renew_hook, test_renew_hook_conflict) (test_renew_hook_matches_deploy_hook) (test_renew_hook_does_not_set_renew_hook, test_max_log_backups_error) (test_max_log_backups_success, test_webroot_map) (test_report_config_interaction_str) (test_report_config_interaction_iterable): Update tests. * certbot/tests/main_test.py (test_certificates) (test_certonly_abspath, test_certonly_bad_args) (test_agree_dev_preview_config): Update tests. * certbot: Refactor cli_test.ParseTest. * certbot/tests/cli_test.py (ParseTest._unmocked_parse): Rename parse to _unmocked_parse. (parse): New method. (ParseTest._help_output, ParseTest.test_cli_ini_domains) (ParseTest.test_no_args, ParseTest.test_install_abspath) (ParseTest.test_help, ParseTest.test_help_no_dashes) (ParseTest.test_parse_domains, ParseTest.test_preferred_challenges) (ParseTest.test_server_flag, ParseTest.test_must_staple_flag) (ParseTest.test_no_gui, ParseTest.test_staging_flag) (ParseTest.test_dry_run_flag, ParseTest.test_option_was_set) (ParseTest.test_encode_revocation_reason) (ParseTest.test_force_interactive) (ParseTest.test_deploy_hook_conflict) (ParseTest.test_deploy_hook_matches_renew_hook) (ParseTest.test_deploy_hook_sets_renew_hook) (ParseTest.test_renew_hook_conflict) (ParseTest.test_renew_hook_matches_deploy_hook) (ParseTest.test_renew_hook_does_not_set_renew_hook) (ParseTest.test_max_log_backups_error) (ParseTest.test_max_log_backups_success): Update methods. * certbot: Refactor cli_test.SetByCliTest * certbot/tests/cli_test.py (SetByCliTest.test_webroot_map) (SetByCliTest.test_report_config_interaction_str) (SetByCliTest.test_report_config_interaction_iteratable) (_call_set_by_cli): Update methods. * certbot: cli: Fix style. * certbot/cli.py (HelpfulArgumentParser.__init__): Update method. * certbot: Revert changes to tests.util.patch_get_utility * certbot/tests/util.py (patch_get_utility): Remove `stdout_notification` arg. (_creat_get_utility_mock): Remove `stdout_notification` arg. (_stdout_notification): Remove function. * certbot: Revert changes to MainTest. * certbot/tests/main_test.py (MainTest.test_certificates, MainTest.test_certonly_abspath) (MainTest.test_certonly_bad_args): Update methods. * certbot: cli_test.py: Remove 'pylint: disable' lines. * certbot/tests/cli_test.py (ParseTest.parse): Update method. (_call_set_by_cli): Update function.
This commit is contained in:
+15
-2
@@ -11,6 +11,9 @@ import sys
|
||||
|
||||
import configargparse
|
||||
import six
|
||||
import zope.component
|
||||
|
||||
from zope.interface import interfaces as zope_interfaces
|
||||
|
||||
from acme import challenges
|
||||
|
||||
@@ -23,6 +26,7 @@ from certbot import hooks
|
||||
from certbot import interfaces
|
||||
from certbot import util
|
||||
|
||||
from certbot.display import util as display_util
|
||||
from certbot.plugins import disco as plugins_disco
|
||||
import certbot.plugins.selection as plugin_selection
|
||||
|
||||
@@ -439,6 +443,15 @@ class HelpfulArgumentParser(object):
|
||||
"delete": main.delete,
|
||||
}
|
||||
|
||||
# Get notification function for printing
|
||||
try:
|
||||
self.notify = zope.component.getUtility(
|
||||
interfaces.IDisplay).notification
|
||||
except zope_interfaces.ComponentLookupError:
|
||||
self.notify = display_util.NoninteractiveDisplay(
|
||||
sys.stdout).notification
|
||||
|
||||
|
||||
# List of topics for which additional help can be provided
|
||||
HELP_TOPICS = ["all", "security", "paths", "automation", "testing"]
|
||||
HELP_TOPICS += list(self.VERBS) + self.COMMANDS_TOPICS + ["manage"]
|
||||
@@ -510,10 +523,10 @@ class HelpfulArgumentParser(object):
|
||||
|
||||
usage = SHORT_USAGE
|
||||
if help_arg == True:
|
||||
print(usage + COMMAND_OVERVIEW % (apache_doc, nginx_doc) + HELP_USAGE)
|
||||
self.notify(usage + COMMAND_OVERVIEW % (apache_doc, nginx_doc) + HELP_USAGE)
|
||||
sys.exit(0)
|
||||
elif help_arg in self.COMMANDS_TOPICS:
|
||||
print(usage + self._list_subcommands())
|
||||
self.notify(usage + self._list_subcommands())
|
||||
sys.exit(0)
|
||||
elif help_arg == "all":
|
||||
# if we're doing --help all, the OVERVIEW is part of the SHORT_USAGE at
|
||||
|
||||
Reference in New Issue
Block a user