1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-05 18:31:10 +01:00

Squashed commit of the following:

commit 6919161e77a39b9bd59ca54eac44b956cd3ae1dc
Author: Vladimir Iakovlev <nvbn.rm@gmail.com>
Date:   Tue May 22 19:01:33 2018 +0200

    #810: Fix code style

commit ebbb31a3227ce32ba5288e96c0c16a3d334c45d6
Merge: 2df1a5a a2799ad
Author: Vladimir Iakovlev <nvbn.rm@gmail.com>
Date:   Tue May 22 18:59:56 2018 +0200

    Merge branch 'feature/long-form-help' of https://github.com/jakewarren/thefuck into jakewarren-feature/long-form-help

commit a2799ad098
Author: Jake Warren <jakewarren@users.noreply.github.com>
Date:   Mon May 7 14:12:57 2018 -0500

    Add new `long_form_help` rule
This commit is contained in:
Vladimir Iakovlev 2018-05-22 19:01:51 +02:00
parent 2df1a5a45b
commit 81042514c8
3 changed files with 50 additions and 0 deletions

View File

@ -244,6 +244,7 @@ following rules are enabled by default:
* `java` &ndash; removes `.java` extension when running Java programs;
* `javac` &ndash; appends missing `.java` when compiling Java files;
* `lein_not_task` &ndash; fixes wrong `lein` tasks like `lein rpl`;
* `long_form_help` &ndash; changes `-h` to `--help` when the short form version is not supported
* `ln_no_hard_link` &ndash; catches hard link creation on directories, suggest symbolic link;
* `ln_s_order` &ndash; fixes `ln -s` arguments order;
* `ls_all` &ndash; adds `-A` to `ls` when output is empty;

View File

@ -0,0 +1,22 @@
import pytest
from thefuck.rules.long_form_help import match, get_new_command
from thefuck.types import Command
@pytest.mark.parametrize('output', [
'Try \'grep --help\' for more information.'])
def test_match(output):
assert match(Command('grep -h', output))
def test_not_match():
assert not match(Command('', ''))
@pytest.mark.parametrize('before, after', [
('grep -h', 'grep --help'),
('tar -h', 'tar --help'),
('docker run -h', 'docker run --help'),
('cut -h', 'cut --help')])
def test_get_new_command(before, after):
assert get_new_command(Command(before, '')) == after

View File

@ -0,0 +1,27 @@
from thefuck.utils import replace_argument
import re
# regex to match a suggested help command from the tool output
help_regex = r"(?:Run|Try) '([^']+)'(?: or '[^']+')? for (?:details|more information)."
def match(command):
if re.search(help_regex, command.output, re.I) is not None:
return True
if '--help' in command.output:
return True
return False
def get_new_command(command):
if re.search(help_regex, command.output) is not None:
match_obj = re.search(help_regex, command.output, re.I)
return match_obj.group(1)
return replace_argument(command.script, '-h', '--help')
enabled_by_default = True
priority = 5000