From b494c4e273943f4b05925da141cccd8a8a63de26 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Thu, 13 Aug 2015 13:09:19 +0100 Subject: [PATCH] basic support for the hdfs dfs when the command misses the dash --- README.md | 1 + tests/rules/test_hadoop_dfs_missing_dash.py | 30 +++++++++++++++++++++ thefuck/rules/hadoop_dfs_missing_dash.py | 10 +++++++ 3 files changed, 41 insertions(+) create mode 100644 tests/rules/test_hadoop_dfs_missing_dash.py create mode 100644 thefuck/rules/hadoop_dfs_missing_dash.py diff --git a/README.md b/README.md index 4f97417..0197c1f 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `tsuru_not_command` – fixes wrong tsuru commands like `tsuru shell`; * `tmux` – fixes `tmux` commands; * `whois` – fixes `whois` command. +* `hdfs dfs` – Add the missing dash to the command. Enabled by default only on specific platforms: diff --git a/tests/rules/test_hadoop_dfs_missing_dash.py b/tests/rules/test_hadoop_dfs_missing_dash.py new file mode 100644 index 0000000..8bb659d --- /dev/null +++ b/tests/rules/test_hadoop_dfs_missing_dash.py @@ -0,0 +1,30 @@ +import pytest +from thefuck.rules.hadoop_dfs_missing_dash import match, get_new_command +from tests.utils import Command + + +@pytest.mark.parametrize('command', [ + Command(script='./bin/hdfs dfs ls', stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), + Command(script='hdfs dfs ls', + stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.'), + Command(script='hdfs dfs ls /foo/bar', stderr='ls: Unknown command\nDid you mean -ls? This command begins with a dash.')]) +def test_match(command): + assert match(command, None) + + +@pytest.mark.parametrize('command', [ + Command(script='./bin/hdfs dfs -ls', stderr=''), + Command(script='./bin/hdfs dfs -ls /foo/bar', stderr=''), + Command(script='hdfs dfs -ls -R /foo/bar', stderr=''), + Command()]) +def test_not_match(command): + assert not match(command, None) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('hdfs dfs ls'), 'hdfs dfs -ls'), + (Command('hdfs dfs ls /foo/bar'), 'hdfs dfs -ls /foo/bar'), + (Command('./bin/hdfs dfs ls -R /foo/bar'), './bin/hdfs dfs -ls -R /foo/bar')]) +def test_get_new_command(command, new_command): + assert get_new_command(command, None) == new_command + diff --git a/thefuck/rules/hadoop_dfs_missing_dash.py b/thefuck/rules/hadoop_dfs_missing_dash.py new file mode 100644 index 0000000..e525c54 --- /dev/null +++ b/thefuck/rules/hadoop_dfs_missing_dash.py @@ -0,0 +1,10 @@ +def match(command, settings): + return ('hdfs dfs' in command.script + and "this command begins with a dash." in command.stderr.lower()) + + +def get_new_command(command, settings): + data = command.script.split() + data[2] = '-' + data[2] + return ' '.join(data) +