mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
#620: Add --debug
This commit is contained in:
parent
d47ff8cbf2
commit
c3eca8234a
@ -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
|
||||
|
@ -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())
|
||||
|
@ -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')
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user