Skip to content

Commit 9a3ec37

Browse files
committed
Implement cowsay command-line tool
- Create cow.py with argparse for command-line argument parsing - Support dynamic animal selection with --animal flag (defaults to "cow") - Accept message as positional arguments and join them - Use getattr() to dynamically call animal functions from cowsay library - Fetch available animals from cowsay.CHARS instead of hardcoding - Add requirements.txt with cowsay dependency
1 parent c54ba92 commit 9a3ec37

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

implement-cowsay/cow.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import argparse
2+
import cowsay
3+
4+
available_animals = cowsay.CHARS
5+
6+
parser = argparse.ArgumentParser(prog="cowsay")
7+
parser.add_argument("message", nargs="+", help="What the animal will say")
8+
parser.add_argument(
9+
"--animal",
10+
choices=available_animals.keys(),
11+
default="cow",
12+
help="The animal that will say the word",
13+
)
14+
15+
args = parser.parse_args()
16+
17+
message_joined = " ".join(args.message)
18+
19+
animal = args.animal
20+
21+
getattr(cowsay, animal)(message_joined)

implement-cowsay/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cowsay

0 commit comments

Comments
 (0)