From c3eca8234a3dad4566a1a2193472331e1f77c095 Mon Sep 17 00:00:00 2001 From: Vladimir Iakovlev Date: Tue, 28 Mar 2017 13:09:11 +0200 Subject: [PATCH] #620: Add `--debug` --- tests/test_argument_parser.py | 23 ++++++++++++++--------- tests/test_conf.py | 6 ++++++ thefuck/argument_parser.py | 4 ++++ thefuck/conf.py | 11 ++++++++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/tests/test_argument_parser.py b/tests/test_argument_parser.py index 35c754f6..7705a229 100644 --- a/tests/test_argument_parser.py +++ b/tests/test_argument_parser.py @@ -5,22 +5,27 @@ from thefuck.const import ARGUMENT_PLACEHOLDER @pytest.mark.parametrize('argv, result', [ (['thefuck'], {'alias': None, 'command': [], 'yes': False, - 'help': False, 'version': False}), - (['thefuck', '-a'], {'alias': 'fuck', 'command': [], 'yes': False, - 'help': False, 'version': False}), - (['thefuck', '-a', 'fix'], {'alias': 'fix', 'command': [], 'yes': False, - 'help': False, 'version': False}), + 'help': False, 'version': False, 'debug': False}), + (['thefuck', '-a'], + {'alias': 'fuck', 'command': [], 'yes': False, + 'help': False, 'version': False, 'debug': False}), + (['thefuck', '-a', 'fix'], + {'alias': 'fix', 'command': [], 'yes': False, + 'help': False, 'version': False, 'debug': False}), (['thefuck', 'git', 'branch', ARGUMENT_PLACEHOLDER, '-y'], {'alias': None, 'command': ['git', 'branch'], 'yes': True, - 'help': False, 'version': False}), + 'help': False, 'version': False, 'debug': False}), (['thefuck', 'git', 'branch', '-a', ARGUMENT_PLACEHOLDER, '-y'], {'alias': None, 'command': ['git', 'branch', '-a'], 'yes': True, - 'help': False, 'version': False}), + 'help': False, 'version': False, 'debug': False}), (['thefuck', ARGUMENT_PLACEHOLDER, '-v'], {'alias': None, 'command': [], 'yes': False, 'help': False, - 'version': True}), + 'version': True, 'debug': False}), (['thefuck', ARGUMENT_PLACEHOLDER, '--help'], {'alias': None, 'command': [], 'yes': False, 'help': True, - 'version': False})]) + 'version': False, 'debug': False}), + (['thefuck', 'git', 'branch', '-a', ARGUMENT_PLACEHOLDER, '-y', '-d'], + {'alias': None, 'command': ['git', 'branch', '-a'], 'yes': True, + 'help': False, 'version': False, 'debug': True})]) def test_parse(argv, result): assert vars(Parser().parse(argv)) == result diff --git a/tests/test_conf.py b/tests/test_conf.py index f496155c..fec66af9 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -79,6 +79,12 @@ class TestSettingsFromEnv(object): assert settings.rules == const.DEFAULT_RULES + ['bash', 'lisp'] +def test_settings_from_args(settings): + settings.init(Mock(yes=True, debug=True)) + assert not settings.require_confirmation + assert settings.debug + + class TestInitializeSettingsFile(object): def test_ignore_if_exists(self, settings): settings_path_mock = Mock(is_file=Mock(return_value=True), open=Mock()) diff --git a/thefuck/argument_parser.py b/thefuck/argument_parser.py index d751faed..7e86d4cb 100644 --- a/thefuck/argument_parser.py +++ b/thefuck/argument_parser.py @@ -24,6 +24,10 @@ class Parser(object): '-y', '--yes', action='store_true', help='execute fixed command without confirmation') + self._parser.add_argument( + '-d', '--debug', + action='store_true', + help='enable debug output') self._parser.add_argument('command', nargs='*', help='command that should be fixed') diff --git a/thefuck/conf.py b/thefuck/conf.py index 32e051a0..04f6694c 100644 --- a/thefuck/conf.py +++ b/thefuck/conf.py @@ -113,10 +113,15 @@ class Settings(dict): def _settings_from_args(self, args): """Loads settings from args.""" - if args and args.yes: - return {'require_confirmation': False} - else: + if not args: return {} + from_args = {} + if args.yes: + from_args['require_confirmation'] = not args.yes + if args.debug: + from_args['debug'] = args.debug + return from_args + settings = Settings(const.DEFAULT_SETTINGS)