mirror of
https://github.com/nvbn/thefuck.git
synced 2025-04-19 09:10:47 +01: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', [
|
@pytest.mark.parametrize('argv, result', [
|
||||||
(['thefuck'], {'alias': None, 'command': [], 'yes': False,
|
(['thefuck'], {'alias': None, 'command': [], 'yes': False,
|
||||||
'help': False, 'version': False}),
|
'help': False, 'version': False, 'debug': False}),
|
||||||
(['thefuck', '-a'], {'alias': 'fuck', 'command': [], 'yes': False,
|
(['thefuck', '-a'],
|
||||||
'help': False, 'version': False}),
|
{'alias': 'fuck', 'command': [], 'yes': False,
|
||||||
(['thefuck', '-a', 'fix'], {'alias': 'fix', 'command': [], 'yes': False,
|
'help': False, 'version': False, 'debug': False}),
|
||||||
'help': False, 'version': False}),
|
(['thefuck', '-a', 'fix'],
|
||||||
|
{'alias': 'fix', 'command': [], 'yes': False,
|
||||||
|
'help': False, 'version': False, 'debug': False}),
|
||||||
(['thefuck', 'git', 'branch', ARGUMENT_PLACEHOLDER, '-y'],
|
(['thefuck', 'git', 'branch', ARGUMENT_PLACEHOLDER, '-y'],
|
||||||
{'alias': None, 'command': ['git', 'branch'], 'yes': True,
|
{'alias': None, 'command': ['git', 'branch'], 'yes': True,
|
||||||
'help': False, 'version': False}),
|
'help': False, 'version': False, 'debug': False}),
|
||||||
(['thefuck', 'git', 'branch', '-a', ARGUMENT_PLACEHOLDER, '-y'],
|
(['thefuck', 'git', 'branch', '-a', ARGUMENT_PLACEHOLDER, '-y'],
|
||||||
{'alias': None, 'command': ['git', 'branch', '-a'], 'yes': True,
|
{'alias': None, 'command': ['git', 'branch', '-a'], 'yes': True,
|
||||||
'help': False, 'version': False}),
|
'help': False, 'version': False, 'debug': False}),
|
||||||
(['thefuck', ARGUMENT_PLACEHOLDER, '-v'],
|
(['thefuck', ARGUMENT_PLACEHOLDER, '-v'],
|
||||||
{'alias': None, 'command': [], 'yes': False, 'help': False,
|
{'alias': None, 'command': [], 'yes': False, 'help': False,
|
||||||
'version': True}),
|
'version': True, 'debug': False}),
|
||||||
(['thefuck', ARGUMENT_PLACEHOLDER, '--help'],
|
(['thefuck', ARGUMENT_PLACEHOLDER, '--help'],
|
||||||
{'alias': None, 'command': [], 'yes': False, 'help': True,
|
{'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):
|
def test_parse(argv, result):
|
||||||
assert vars(Parser().parse(argv)) == result
|
assert vars(Parser().parse(argv)) == result
|
||||||
|
@ -79,6 +79,12 @@ class TestSettingsFromEnv(object):
|
|||||||
assert settings.rules == const.DEFAULT_RULES + ['bash', 'lisp']
|
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):
|
class TestInitializeSettingsFile(object):
|
||||||
def test_ignore_if_exists(self, settings):
|
def test_ignore_if_exists(self, settings):
|
||||||
settings_path_mock = Mock(is_file=Mock(return_value=True), open=Mock())
|
settings_path_mock = Mock(is_file=Mock(return_value=True), open=Mock())
|
||||||
|
@ -24,6 +24,10 @@ class Parser(object):
|
|||||||
'-y', '--yes',
|
'-y', '--yes',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='execute fixed command without confirmation')
|
help='execute fixed command without confirmation')
|
||||||
|
self._parser.add_argument(
|
||||||
|
'-d', '--debug',
|
||||||
|
action='store_true',
|
||||||
|
help='enable debug output')
|
||||||
self._parser.add_argument('command',
|
self._parser.add_argument('command',
|
||||||
nargs='*',
|
nargs='*',
|
||||||
help='command that should be fixed')
|
help='command that should be fixed')
|
||||||
|
@ -113,10 +113,15 @@ class Settings(dict):
|
|||||||
|
|
||||||
def _settings_from_args(self, args):
|
def _settings_from_args(self, args):
|
||||||
"""Loads settings from args."""
|
"""Loads settings from args."""
|
||||||
if args and args.yes:
|
if not args:
|
||||||
return {'require_confirmation': False}
|
|
||||||
else:
|
|
||||||
return {}
|
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)
|
settings = Settings(const.DEFAULT_SETTINGS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user