mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-20 09:39:01 +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'),
|
('choco install logstitcher', 'choco install logstitcher.install'),
|
||||||
('cinst logstitcher', 'cinst logstitcher.install'),
|
('cinst logstitcher', 'cinst logstitcher.install'),
|
||||||
('choco install logstitcher -y', 'choco install logstitcher.install -y'),
|
('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):
|
def test_get_new_command(before, after):
|
||||||
assert (get_new_command(Command(before, '')) == after)
|
assert (get_new_command(Command(before, '')) == after)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from thefuck.utils import for_app, which
|
from thefuck.utils import for_app, which
|
||||||
|
|
||||||
|
|
||||||
@for_app("choco", "cinst")
|
@for_app("choco", "cinst")
|
||||||
def match(command):
|
def match(command):
|
||||||
return ((command.script.startswith('choco install') or 'cinst' in command.script_parts)
|
return ((command.script.startswith('choco install') or 'cinst' in command.script_parts)
|
||||||
@ -10,17 +9,14 @@ def match(command):
|
|||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
# Find the argument that is the package name
|
# Find the argument that is the package name
|
||||||
for script_part in command.script_parts:
|
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
|
continue
|
||||||
if "cinst" in script_part:
|
if script_part.startswith('-'):
|
||||||
|
# Leading hyphens are parameters; some packages contain them though
|
||||||
continue
|
continue
|
||||||
if "install" in script_part:
|
if '=' in script_part or '/' in script_part:
|
||||||
continue
|
# These are certainly parameters
|
||||||
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
|
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
packageName = script_part
|
packageName = script_part
|
||||||
|
Loading…
x
Reference in New Issue
Block a user