diff --git a/tests/test_utils.py b/tests/test_utils.py index e47db872..31b013ec 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -18,6 +18,7 @@ def test_wrap_settings(override, old, new): @pytest.mark.parametrize('return_value, command, called, result', [ ('ls -lah', 'sudo ls', 'ls', 'sudo ls -lah'), ('ls -lah', 'ls', 'ls', 'ls -lah'), + (['ls -lah'], 'sudo ls', 'ls', ['sudo ls -lah']), (True, 'sudo ls', 'ls', True), (True, 'ls', 'ls', True), (False, 'sudo ls', 'ls', False), diff --git a/thefuck/utils.py b/thefuck/utils.py index 639fa4d8..db579fe9 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -69,6 +69,8 @@ def sudo_support(fn): if result and isinstance(result, six.string_types): return u'sudo {}'.format(result) + elif isinstance(result, list): + return [u'sudo {}'.format(x) for x in result] else: return result return wrapper @@ -161,6 +163,14 @@ def replace_argument(script, from_, to): u' {} '.format(from_), u' {} '.format(to), 1) +def eager(fn): + @wraps(fn) + def wrapper(*args, **kwargs): + return list(fn(*args, **kwargs)) + return wrapper + + +@eager def get_all_matched_commands(stderr, separator='Did you mean'): should_yield = False for line in stderr.split('\n'):