-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate command from logic, updated coverage badge refresh
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from Logic import MyWordCounter | ||
import sys | ||
|
||
myWordCounter = MyWordCounter() | ||
|
||
|
||
def run_wc(): | ||
if len(sys.argv) == 1: | ||
return (myWordCounter.all_counts(sys.stdin)) | ||
elif len(sys.argv) == 2: | ||
if sys.argv[1][0] == "-": | ||
if sys.argv[1] in myWordCounter.options: | ||
return (myWordCounter.functions[sys.argv[1]](sys.stdin)) | ||
else: | ||
return ("MyWordCounter: invalid option\nTry 'python Logic.py -h' for more information.") | ||
else: | ||
try: | ||
txtFile = sys.argv[1] | ||
txtFile = open(txtFile, 'r') | ||
return (myWordCounter.all_counts(txtFile)) | ||
except IOError: | ||
return ("MyWordCounter: ", txtFile, ": No such file or directory") | ||
|
||
elif len(sys.argv) == 3: | ||
if sys.argv[1] not in myWordCounter.options: | ||
return ("MyWordCounter: invalid option\nTry 'python Logic.py -h' for more information.") | ||
else: | ||
try: | ||
txtFile = sys.argv[2] | ||
txtFile = open(txtFile, 'r') | ||
return (myWordCounter.functions[sys.argv[1]](txtFile)) | ||
except IOError: | ||
return ("MyWordCounter: ", txtFile, ": No such file or directory") | ||
else: | ||
return ("MyWordCounter: invalid input\nTry 'python Logic.py -h' for more information.") | ||
|
||
|
||
if __name__ == '__main__': | ||
print(run_wc()) |