New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fallback to su if sudo doesn't exist #1006
base: master
Are you sure you want to change the base?
Conversation
Thanks for contributing. Can you please add tests? |
Will do. It might not be until next week though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please regard my change requests.
@pytest.mark.parametrize('output', [ | ||
'command not found: sudo']) | ||
def test_match(output): | ||
assert match(Command('', output)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good having some practical test cases. command.script_parts
is part of the match
condition but not taken into consideration in tests.
assert not match(Command('', '')) | ||
assert not match(Command('sudo ls', 'Permission denied')) | ||
assert not match(Command('su -c ls', 'Permission denied')) | ||
assert not match(Command('ls', 'command not found: ls')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ pytest.mark.parametrize
is being used in test_match
for one entry and not in test_not_match
for four entries. Use it here as well.
@@ -0,0 +1,12 @@ | |||
def match(command): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thefuck.utils.for_app
is there for the help \o/
def match(command): | |
from thefuck.utils import for_app | |
@for_app('sudo') | |
def match(command): |
@@ -0,0 +1,12 @@ | |||
def match(command): | |||
if command.script_parts and '&&' not in command.script_parts and command.script_parts[0] == 'su': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if command.script_parts and '&&' not in command.script_parts and command.script_parts[0] == 'su': | |
if '&&' not in command.script_parts: |
Also, Fish Shell must be considered. Support to &&
operator has been added to version 3. Earlier versions only support the and
operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sudo.py suffers with the same issue, and that's already released.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true. I's been sitting there unnoticed. Thanks, @djh82. That must be fixed.
su should exist even if sudo doesn't. As such, we can try to run a command with su if sudo doesn't exist.