Skip to content

Commit 5eb1779

Browse files
committed
Implement cowsay CLI tool to select animals and make them say things
1 parent 0334e5a commit 5eb1779

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

implement-cowsay/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ env/
1111

1212
# macOS Finder file (ignore if on Mac)
1313
.DS_Store
14+
name

implement-cowsay/cow.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
1+
import argparse
12
import cowsay
23

4+
parser = argparse.ArgumentParser(
5+
prog="cowsay",
6+
description="program to make animal say things"
7+
)
38

9+
# to fetch animals names
10+
animals = cowsay.char_names
411

12+
parser.add_argument(
13+
"--animal",
14+
choices=animals,
15+
help="Animals to be saying things.",
16+
default="cow"
17+
)
18+
19+
parser.add_argument(
20+
"message",
21+
nargs="+",
22+
help="The message to say."
23+
)
24+
25+
args = parser.parse_args()
26+
27+
# get the correct anima function by name
28+
animal_func = getattr(cowsay, args.animal)
29+
30+
print(animal_func(" ".join(args.message)))

0 commit comments

Comments
 (0)