mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 15:12:20 +00:00 
			
		
		
		
	Add new long_form_help rule
				
					
				
			This commit is contained in:
		| @@ -239,6 +239,7 @@ following rules are enabled by default: | ||||
| * `java` – removes `.java` extension when running Java programs; | ||||
| * `javac` – appends missing `.java` when compiling Java files; | ||||
| * `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`; | ||||
| * `long_form_help` – changes `-h` to `--help` when the short form version is not supported | ||||
| * `ln_no_hard_link` – catches hard link creation on directories, suggest symbolic link; | ||||
| * `ln_s_order` – fixes `ln -s` arguments order; | ||||
| * `ls_all` – adds `-A` to `ls` when output is empty; | ||||
|   | ||||
							
								
								
									
										22
									
								
								tests/rules/test_long_form_help.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								tests/rules/test_long_form_help.py
									
									
									
									
									
										Normal 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 | ||||
							
								
								
									
										27
									
								
								thefuck/rules/long_form_help.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								thefuck/rules/long_form_help.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| from thefuck.utils import replace_argument | ||||
| import re | ||||
|  | ||||
| # regex to match a suggested help command from the tool output | ||||
| helpRegex = r"(?:Run|Try) '([^']+)'(?: or '[^']+')? for (?:details|more information)." | ||||
|  | ||||
|  | ||||
| def match(command): | ||||
|     if re.search(helpRegex, 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(helpRegex, command.output) is not None: | ||||
|         matchObj = re.search(helpRegex, command.output, re.I) | ||||
|         return matchObj.group(1) | ||||
|  | ||||
|     return replace_argument(command.script, '-h', '--help') | ||||
|  | ||||
|  | ||||
| enabled_by_default = True | ||||
| priority = 5000 | ||||
		Reference in New Issue
	
	Block a user