Skip to content

Commit 4188887

Browse files
committed
The functionality for the cowsay project in python.
1 parent 3f26943 commit 4188887

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

implement-cowsay/cow_script.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
import cowsay
2-
import sys
2+
import argparse
33

4-
cowsay.cow(" ".join(sys.argv[1:]))
4+
parser = argparse.ArgumentParser(
5+
prog="Display items",
6+
description="Display the contents of a file reminiscent of the cat command"
7+
)
8+
9+
parser.add_argument("--animal", help="Gives the user the option of adding the animal")
10+
parser.add_argument("message", nargs="+", help="The message the animal needs to say.")
11+
12+
args = parser.parse_args()
13+
14+
animal_entered = args.animal
15+
message_to_say = " ".join(args.message)
16+
17+
animals = [animal for animal in dir(cowsay) if callable(getattr(cowsay, animal))]
18+
19+
if animal_entered in animals:
20+
getattr(cowsay, animal_entered)(message_to_say)
21+
else:
22+
print(f"'{animal_entered}' is not a valid animal. please choose from '{animals[1:]}'")
23+
print(f"Try one of: {', '.join(animals)}")

0 commit comments

Comments
 (0)