From 866e1839a7ce5ee34a9b6ff799a08b67103f752f Mon Sep 17 00:00:00 2001 From: Roopesh V S Date: Mon, 3 Aug 2020 17:02:22 +0530 Subject: [PATCH] Version Command --- tests/rules/test_version.py | 20 ++++++++++++++++++++ thefuck/rules/version.py | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/rules/test_version.py create mode 100644 thefuck/rules/version.py diff --git a/tests/rules/test_version.py b/tests/rules/test_version.py new file mode 100644 index 00000000..eca350ab --- /dev/null +++ b/tests/rules/test_version.py @@ -0,0 +1,20 @@ +import pytest +from thefuck.rules.version import match, get_new_command +from thefuck.types import Command + + +@pytest.mark.parametrize('command', [ + Command('git -v', ''), + Command('git -version', ''), + Command('git -version', ''), + Command('fuck -ver', '')]) +def test_match(command): + assert match(command) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('git -v', ''), 'git --version'), + (Command('git -version', ''), 'git --version'), + (Command('fuck -ver', ''), 'fuck --version')]) +def test_get_new_command(command, new_command): + assert get_new_command(command) == new_command diff --git a/thefuck/rules/version.py b/thefuck/rules/version.py new file mode 100644 index 00000000..750024fb --- /dev/null +++ b/thefuck/rules/version.py @@ -0,0 +1,17 @@ +# Fixes incorrect usage of version commands +# +# Example : +# > git -v +# Here the correct usage is +# > git --version + + +def match(command): + return ('-v' in command.script) + + +def get_new_command(command): + if '--version' in command.script: + return command.script_parts[0] + ' -v' + else: + return command.script_parts[0] + ' --version'