From 9f86b7a6f9ccc4ff6830760eceba6faaaa2d684a Mon Sep 17 00:00:00 2001 From: emilyzhang <1430863441emily@gmail.com> Date: Thu, 1 Jun 2023 19:10:39 +0930 Subject: [PATCH 01/11] added mdt error detection --- thefuck/rules/mandel.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 thefuck/rules/mandel.py diff --git a/thefuck/rules/mandel.py b/thefuck/rules/mandel.py new file mode 100644 index 0000000..bd26986 --- /dev/null +++ b/thefuck/rules/mandel.py @@ -0,0 +1,14 @@ +import re +from thefuck.shells import shell +from thefuck.utils import for_app +from thefuck.utils import which + + +@for_app('mdt') +def match(command): + return "Unknown command" in command.output and "try 'mdt help'" in command.output + + +def get_new_command(command): + #mdt_commands = [] + return "mdt" + "shell" From e87a86afcd3223b15f265f022ab7df95b645e10c Mon Sep 17 00:00:00 2001 From: emilyzhang <1430863441emily@gmail.com> Date: Thu, 1 Jun 2023 19:18:47 +0930 Subject: [PATCH 02/11] rename to generic mdt --- thefuck/rules/{mandel.py => mdt.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename thefuck/rules/{mandel.py => mdt.py} (100%) diff --git a/thefuck/rules/mandel.py b/thefuck/rules/mdt.py similarity index 100% rename from thefuck/rules/mandel.py rename to thefuck/rules/mdt.py From 5a1fd7969fdf9e4dfcd74b647af9382bc8c49a2a Mon Sep 17 00:00:00 2001 From: emilyzhang <1430863441emily@gmail.com> Date: Thu, 1 Jun 2023 19:47:51 +0930 Subject: [PATCH 03/11] functional match for 'mdt shell' --- thefuck/rules/mdt.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/thefuck/rules/mdt.py b/thefuck/rules/mdt.py index bd26986..2850339 100644 --- a/thefuck/rules/mdt.py +++ b/thefuck/rules/mdt.py @@ -10,5 +10,11 @@ def match(command): def get_new_command(command): - #mdt_commands = [] - return "mdt" + "shell" + corrections = ["help"] + command = str(command) + extracted_command = re.findall(r"'(.*?)'", command)[0] + + if re.match('[shell]{2,}', extracted_command): + corrections.insert(0, "shell") + + return ["mdt " + correction for correction in corrections] From be778496985542af44edafb0c22ed2accd64ae12 Mon Sep 17 00:00:00 2001 From: emilyzhang <1430863441emily@gmail.com> Date: Thu, 1 Jun 2023 19:48:12 +0930 Subject: [PATCH 04/11] cleanup --- thefuck/rules/mdt.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/thefuck/rules/mdt.py b/thefuck/rules/mdt.py index 2850339..afddefb 100644 --- a/thefuck/rules/mdt.py +++ b/thefuck/rules/mdt.py @@ -1,7 +1,5 @@ import re -from thefuck.shells import shell from thefuck.utils import for_app -from thefuck.utils import which @for_app('mdt') From 463dd97276ddc9b9168130ec2bcab6bdedce1248 Mon Sep 17 00:00:00 2001 From: emilyzhang <1430863441emily@gmail.com> Date: Thu, 1 Jun 2023 20:06:39 +0930 Subject: [PATCH 05/11] add support for devices, reboot, and version commands --- thefuck/rules/mdt.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/thefuck/rules/mdt.py b/thefuck/rules/mdt.py index afddefb..4141e8a 100644 --- a/thefuck/rules/mdt.py +++ b/thefuck/rules/mdt.py @@ -14,5 +14,12 @@ def get_new_command(command): if re.match('[shell]{2,}', extracted_command): corrections.insert(0, "shell") + elif re.match('[devices]{2,}', extracted_command): + corrections.insert(0, "devices") + elif re.match('[reboot]{2,}', extracted_command): + corrections.insert(0, "reboot") + corrections.insert(1, "reboot-bootloader") + elif re.match('[version]{2,}', extracted_command): + corrections.insert(0, "version") return ["mdt " + correction for correction in corrections] From 3dad5a9fff20b8d012799cae0b8ec7a99c6b5bca Mon Sep 17 00:00:00 2001 From: emilyzhang <1430863441emily@gmail.com> Date: Thu, 1 Jun 2023 20:09:59 +0930 Subject: [PATCH 06/11] stricter regex conditions due to similar letters --- thefuck/rules/mdt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thefuck/rules/mdt.py b/thefuck/rules/mdt.py index 4141e8a..4364863 100644 --- a/thefuck/rules/mdt.py +++ b/thefuck/rules/mdt.py @@ -14,12 +14,12 @@ def get_new_command(command): if re.match('[shell]{2,}', extracted_command): corrections.insert(0, "shell") - elif re.match('[devices]{2,}', extracted_command): + elif re.match('[devices]{3,}', extracted_command): corrections.insert(0, "devices") elif re.match('[reboot]{2,}', extracted_command): corrections.insert(0, "reboot") corrections.insert(1, "reboot-bootloader") - elif re.match('[version]{2,}', extracted_command): + elif re.match('[version]{3,}', extracted_command): corrections.insert(0, "version") return ["mdt " + correction for correction in corrections] From be5077848e658fec360bb7bdf657b261743188a1 Mon Sep 17 00:00:00 2001 From: emilyzhang <1430863441emily@gmail.com> Date: Thu, 1 Jun 2023 20:16:33 +0930 Subject: [PATCH 07/11] add 'wait-for-device' command --- thefuck/rules/mdt.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/thefuck/rules/mdt.py b/thefuck/rules/mdt.py index 4364863..4e7b73e 100644 --- a/thefuck/rules/mdt.py +++ b/thefuck/rules/mdt.py @@ -21,5 +21,7 @@ def get_new_command(command): corrections.insert(1, "reboot-bootloader") elif re.match('[version]{3,}', extracted_command): corrections.insert(0, "version") + elif re.match('[wait\-for\-device]{3,}', extracted_command): + corrections.insert(0, "wait-for-device") return ["mdt " + correction for correction in corrections] From b0244475a99441f7d8edc9e90fce7d373ab2327a Mon Sep 17 00:00:00 2001 From: emilyzhang <1430863441emily@gmail.com> Date: Thu, 1 Jun 2023 20:19:46 +0930 Subject: [PATCH 08/11] add description in README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3ea406f..6605244 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,7 @@ following rules are enabled by default: * `ls_lah` – adds `-lah` to `ls`; * `man` – changes manual section; * `man_no_space` – fixes man commands without spaces, for example `mandiff`; +* `mdt` – fixes misspellings in mdt commands like `mdt shll`; * `mercurial` – fixes wrong `hg` commands; * `missing_space_before_subcommand` – fixes command with missing space like `npminstall`; * `mkdir_p` – adds `-p` when you try to create a directory without a parent; From 7f78ff07bd58c3403f232081ff652102c3509919 Mon Sep 17 00:00:00 2001 From: emilyzhang <1430863441emily@gmail.com> Date: Thu, 1 Jun 2023 20:27:32 +0930 Subject: [PATCH 09/11] added some comments --- thefuck/rules/mdt.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/thefuck/rules/mdt.py b/thefuck/rules/mdt.py index 4e7b73e..435369f 100644 --- a/thefuck/rules/mdt.py +++ b/thefuck/rules/mdt.py @@ -9,9 +9,12 @@ def match(command): def get_new_command(command): corrections = ["help"] + + """ Extract what the user typed in""" command = str(command) extracted_command = re.findall(r"'(.*?)'", command)[0] + """ Find possible matches in the case of typos""" if re.match('[shell]{2,}', extracted_command): corrections.insert(0, "shell") elif re.match('[devices]{3,}', extracted_command): From f122235ad288d7d4bf382d0e1f299d51155e5b42 Mon Sep 17 00:00:00 2001 From: StefanParenti Date: Sat, 3 Jun 2023 23:16:30 +0930 Subject: [PATCH 10/11] adding some testing --- tests/rules/test_mdt.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/rules/test_mdt.py diff --git a/tests/rules/test_mdt.py b/tests/rules/test_mdt.py new file mode 100644 index 0000000..372b48a --- /dev/null +++ b/tests/rules/test_mdt.py @@ -0,0 +1,15 @@ +import pytest +from thefuck.rules.mdt import match, get_new_command +from thefuck.types import Command + +def test_match(): + assert match(Command('mdt hlp', 'Unknown command\ntry \'mdt help\'')) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('mdt shll', ''), 'mdt shell'), + (Command('mdt hlp', ''), 'mdt help') +]) + +def test_get_new_command(command, new_command): + assert get_new_command(command) == new_command From cd85820da3d213871057c332f0b682dd3e0ed83e Mon Sep 17 00:00:00 2001 From: emilyzhang <1430863441emily@gmail.com> Date: Sat, 3 Jun 2023 23:46:59 +0930 Subject: [PATCH 11/11] updated mdt unit test --- tests/rules/test_mdt.py | 52 +++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/tests/rules/test_mdt.py b/tests/rules/test_mdt.py index 372b48a..4249818 100644 --- a/tests/rules/test_mdt.py +++ b/tests/rules/test_mdt.py @@ -1,15 +1,37 @@ -import pytest -from thefuck.rules.mdt import match, get_new_command -from thefuck.types import Command - -def test_match(): - assert match(Command('mdt hlp', 'Unknown command\ntry \'mdt help\'')) - - -@pytest.mark.parametrize('command, new_command', [ - (Command('mdt shll', ''), 'mdt shell'), - (Command('mdt hlp', ''), 'mdt help') -]) - -def test_get_new_command(command, new_command): - assert get_new_command(command) == new_command +import pytest +from thefuck.rules.mdt import match, get_new_command +from thefuck.types import Command + +output_unknown_shell = """Unknown command 'shll': try 'mdt help'""" + +output_unknown_devices = """Unknown command 'dvices': try 'mdt help'""" + +output_unknown_reboot = """Unknown command 'rboot': try 'mdt help'""" + +output_unknown_version = """Unknown command 'verson': try 'mdt help'""" + +output_unknown_wait = """Unknown command 'wai-for-dvice': try 'mdt help'""" + + +@pytest.mark.parametrize('command', [ + Command('mdt shll', output_unknown_shell), + Command('mdt dvices', output_unknown_devices), + Command('mdt rboot', output_unknown_reboot), + Command('mdt verson', output_unknown_version), + Command('mdt wai-for-dvice', output_unknown_wait) +]) +def test_match(command): + # check mdt detection + assert match(command) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('mdt shll', output_unknown_shell), 'mdt shell'), + (Command('mdt dvices', output_unknown_devices), 'mdt devices'), + (Command('mdt rboot', output_unknown_reboot), 'mdt reboot'), + (Command('mdt verson', output_unknown_version), 'mdt version'), + (Command('mdt wai-for-dvice', output_unknown_wait), 'mdt wait-for-device') +]) +def test_get_new_command(command, new_command): + # check first correction + assert get_new_command(command)[0] == new_command