mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 02:01:13 +00:00
#1133: Match commands with path prefixes in @for_app decorations
* Resolve paths before checking app identity Commands entered with a path do not match is_app. I encountered this when working with a test for the rm_dir rule. This rule did not use the @for_app decorator, but when I migrated it, the test for "./bin/hdfs.." failed because 'hdfs' was recognized as a command, while "./bin/hdfs" was not. This commit addresses the false negative by resolving path names in the command, via os.path.basename. * Remove paths from for_app invocations in rules I presume that the `./` in `./gradlew` was used here because thefuck would not find an app match on just `gradlew`, and thus no fucks would be given on the most common and idiomatic way of invoking gradlew. After 8faf9b1, thefuck does not distinguish between commands with paths and those without. Therefore, the tests for this rule are now broken because thefuck strips paths from the _user_'s command, but not from the for_app decoration. This commit addresses that problem by changing the for_app decoration to this rule.
This commit is contained in:
parent
13fda64d6e
commit
fe1942866b
@ -146,6 +146,8 @@ def test_get_all_matched_commands(stderr, result):
|
||||
|
||||
@pytest.mark.usefixtures('no_memoize')
|
||||
@pytest.mark.parametrize('script, names, result', [
|
||||
('/usr/bin/git diff', ['git', 'hub'], True),
|
||||
('/bin/hdfs dfs -rm foo', ['hdfs'], True),
|
||||
('git diff', ['git', 'hub'], True),
|
||||
('hub diff', ['git', 'hub'], True),
|
||||
('hg diff', ['git', 'hub'], False)])
|
||||
@ -155,6 +157,8 @@ def test_is_app(script, names, result):
|
||||
|
||||
@pytest.mark.usefixtures('no_memoize')
|
||||
@pytest.mark.parametrize('script, names, result', [
|
||||
('/usr/bin/git diff', ['git', 'hub'], True),
|
||||
('/bin/hdfs dfs -rm foo', ['hdfs'], True),
|
||||
('git diff', ['git', 'hub'], True),
|
||||
('hub diff', ['git', 'hub'], True),
|
||||
('hg diff', ['git', 'hub'], False)])
|
||||
|
@ -5,7 +5,7 @@ from thefuck.utils import for_app, eager, replace_command
|
||||
regex = re.compile(r"Task '(.*)' (is ambiguous|not found)")
|
||||
|
||||
|
||||
@for_app('gradle', './gradlew')
|
||||
@for_app('gradle', 'gradlew')
|
||||
def match(command):
|
||||
return regex.findall(command.output)
|
||||
|
||||
|
@ -180,7 +180,7 @@ def is_app(command, *app_names, **kwargs):
|
||||
raise TypeError("got an unexpected keyword argument '{}'".format(kwargs.keys()))
|
||||
|
||||
if len(command.script_parts) > at_least:
|
||||
return command.script_parts[0] in app_names
|
||||
return os.path.basename(command.script_parts[0]) in app_names
|
||||
|
||||
return False
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user