Add rule for restic

* Detect typos recognized by restic and add fixed command for it
* Add test cases for the restic rule
* Update README.md
This commit is contained in:
Saiwing Yeung 2021-11-05 18:24:07 -07:00
parent c719712b62
commit c816c8e45b
3 changed files with 37 additions and 0 deletions

View File

@ -316,6 +316,7 @@ following rules are enabled by default:
* `react_native_command_unrecognized` – fixes unrecognized `react-native` commands;
* `remove_shell_prompt_literal` – remove leading shell prompt symbol `$`, common when copying commands from documentations;
* `remove_trailing_cedilla` – remove trailing cedillas `ç`, a common typo for European keyboard layouts;
* `restic` – fixes restic commands;
* `rm_dir` – adds `-rf` when you try to remove a directory;
* `scm_correction` – corrects wrong scm like `hg log` to `git log`;
* `sed_unterminated_s` – adds missing '/' to `sed`'s `s` commands;

View File

@ -0,0 +1,22 @@
import pytest
from thefuck.rules.restic_typo import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def mistype_suggestion():
return """
unknown command "snapshot" for "restic"
Did you mean this?
snapshots
"""
def test_match(mistype_suggestion):
assert match(Command('restic snapshot', mistype_suggestion))
def test_get_new_command(mistype_suggestion):
assert (get_new_command(Command('restic snapshot', mistype_suggestion)) == ['restic snapshots'])

View File

@ -0,0 +1,14 @@
import re
from thefuck.utils import replace_command, for_app
@for_app("restic")
def match(command):
return (re.search('unknown command ".*" for "restic"', command.output)
and "Did you mean this" in command.output)
def get_new_command(command):
broken_cmd = re.findall(r"(?<=unknown command \")([a-z\-]+)", command.output)[0]
correct_cmd = re.findall(r"([a-z\-]+)", command.output)[-1]
return replace_command(command, broken_cmd, [correct_cmd])