Create cat_dir rule for replacing cat with ls (#823)

* Create `cat_dir` rule for replacing `cat` with `ls` when you try to run `cat` on a directory.

* Changed to string methods in response to feedback.

Added a test to make sure lines like 'cat cat' don't become 'ls ls'.

Added trailing '\n's to test cases.
This commit is contained in:
Scott Colby
2018-07-09 15:51:42 -07:00
committed by Vladimir Iakovlev
parent 142ef6e66c
commit fe0785bc42
3 changed files with 40 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
def match(command):
return (
command.script.startswith('cat') and
command.output.startswith('cat: ') and
command.output.rstrip().endswith(': Is a directory')
)
def get_new_command(command):
return command.script.replace('cat', 'ls', 1)