mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-30 22:54:14 +00:00 
			
		
		
		
	Add brew_reinstall rule (#816)
Replaces install with reinstall when a package is already installed.
This commit is contained in:
		
				
					committed by
					
						 Vladimir Iakovlev
						Vladimir Iakovlev
					
				
			
			
				
	
			
			
			
						parent
						
							f6e50bef82
						
					
				
				
					commit
					89207d6d7c
				
			| @@ -305,6 +305,7 @@ The following rules are enabled by default on specific platforms only: | ||||
| * `apt_upgrade` – helps you run `apt upgrade` after `apt list --upgradable`; | ||||
| * `brew_cask_dependency` – installs cask dependencies; | ||||
| * `brew_install` – fixes formula name for `brew install`; | ||||
| * `brew_reinstall` – turns `brew install <formula>` into `brew reinstall <formula>`; | ||||
| * `brew_link` – adds `--overwrite --dry-run` if linking fails; | ||||
| * `brew_uninstall` – adds `--force` to `brew uninstall` if multiple versions were installed; | ||||
| * `brew_unknown_command` – fixes wrong brew commands, for example `brew docto/brew doctor`; | ||||
|   | ||||
							
								
								
									
										28
									
								
								tests/rules/test_brew_reinstall.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								tests/rules/test_brew_reinstall.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| import pytest | ||||
| from thefuck.types import Command | ||||
| from thefuck.rules.brew_reinstall import get_new_command, match | ||||
|  | ||||
|  | ||||
| output = ("Warning: thefuck 9.9 is already installed and up-to-date\nTo " | ||||
|           "reinstall 9.9, run `brew reinstall thefuck`") | ||||
|  | ||||
|  | ||||
| def test_match(): | ||||
|     command = Command('brew install thefuck', output) | ||||
|     assert match(command) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('script', [ | ||||
|     'brew reinstall thefuck', | ||||
|     'brew install foo']) | ||||
| def test_not_match(script): | ||||
|     assert not match(Command(script, '')) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('script, formula, ', [ | ||||
|     ('brew install foo', 'foo'), | ||||
|     ('brew install bar zap', 'bar zap')]) | ||||
| def test_get_new_command(script, formula): | ||||
|     command = Command(script, output) | ||||
|     new_command = 'brew reinstall {}'.format(formula) | ||||
|     assert get_new_command(command) == new_command | ||||
							
								
								
									
										19
									
								
								thefuck/rules/brew_reinstall.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								thefuck/rules/brew_reinstall.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | ||||
| import re | ||||
| from thefuck.utils import for_app | ||||
|  | ||||
|  | ||||
| warning_regex = re.compile(r'Warning: (?:.(?!is ))+ is already installed and ' | ||||
|                            r'up-to-date') | ||||
| message_regex = re.compile(r'To reinstall (?:(?!, ).)+, run `brew reinstall ' | ||||
|                            r'[^`]+`') | ||||
|  | ||||
|  | ||||
| @for_app('brew', at_least=2) | ||||
| def match(command): | ||||
|     return ('install' in command.script | ||||
|             and warning_regex.search(command.output) | ||||
|             and message_regex.search(command.output)) | ||||
|  | ||||
|  | ||||
| def get_new_command(command): | ||||
|     return command.script.replace('install', 'reinstall') | ||||
		Reference in New Issue
	
	Block a user