mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 06:38:32 +00:00
Added more test cases, refactored parsing
This commit is contained in:
parent
e7782119fe
commit
0ad479b4b0
@ -7,6 +7,12 @@ from thefuck.types import Command
|
||||
('choco install logstitcher', 'choco install logstitcher.install'),
|
||||
('cinst logstitcher', 'cinst logstitcher.install'),
|
||||
('choco install logstitcher -y', 'choco install logstitcher.install -y'),
|
||||
('cinst logstitcher -y', 'cinst logstitcher.install -y')])
|
||||
('cinst logstitcher -y', 'cinst logstitcher.install -y'),
|
||||
('choco install logstitcher -y -n=test', 'choco install logstitcher.install -y -n=test'),
|
||||
('cinst logstitcher -y -n=test', 'cinst logstitcher.install -y -n=test'),
|
||||
('choco install logstitcher -y -n=test /env', 'choco install logstitcher.install -y -n=test /env'),
|
||||
('cinst logstitcher -y -n=test /env', 'cinst logstitcher.install -y -n=test /env'),
|
||||
('choco install chocolatey -y', 'choco install chocolatey.install -y'),
|
||||
('cinst chocolatey -y', 'cinst chocolatey.install -y'),])
|
||||
def test_get_new_command(before, after):
|
||||
assert (get_new_command(Command(before, '')) == after)
|
||||
|
@ -1,6 +1,5 @@
|
||||
from thefuck.utils import for_app, which
|
||||
|
||||
|
||||
@for_app("choco", "cinst")
|
||||
def match(command):
|
||||
return ((command.script.startswith('choco install') or 'cinst' in command.script_parts)
|
||||
@ -10,17 +9,14 @@ def match(command):
|
||||
def get_new_command(command):
|
||||
# Find the argument that is the package name
|
||||
for script_part in command.script_parts:
|
||||
if "choco" in script_part:
|
||||
if script_part in ["choco", "cinst", "install"]:
|
||||
# Need exact match (bc chocolatey is a package)
|
||||
continue
|
||||
if "cinst" in script_part:
|
||||
if script_part.startswith('-'):
|
||||
# Leading hyphens are parameters; some packages contain them though
|
||||
continue
|
||||
if "install" in script_part:
|
||||
continue
|
||||
if script_part.startswith('-'): # Some parameters start with hyphens; some packages contain them though
|
||||
continue
|
||||
if '=' in script_part: # Some paramaters contain '='
|
||||
continue
|
||||
if '/' in script_part: # Some parameters contain slashes
|
||||
if '=' in script_part or '/' in script_part:
|
||||
# These are certainly parameters
|
||||
continue
|
||||
else:
|
||||
packageName = script_part
|
||||
|
Loading…
x
Reference in New Issue
Block a user