Skip to content

Commit c634395

Browse files
committed
implement cowsay
1 parent 407b010 commit c634395

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

implement-cowsay/cow.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import sys
4+
import cowsay
5+
6+
def main():
7+
# Dynamically get available animals from the cowsay library
8+
animals = sorted(cowsay.char_names)
9+
10+
parser = argparse.ArgumentParser(
11+
prog="cowsay",
12+
description="Make animals say things"
13+
)
14+
parser.add_argument(
15+
"message",
16+
nargs="+",
17+
help="The message to say."
18+
)
19+
parser.add_argument(
20+
"--animal",
21+
choices=animals,
22+
default="cow",
23+
help="The animal to be saying things."
24+
)
25+
26+
args = parser.parse_args()
27+
msg = " ".join(args.message)
28+
29+
# Render the chosen animal saying the message
30+
output = cowsay.get_output_string(args.animal, msg)
31+
sys.stdout.write(output + "\n")
32+
33+
if __name__ == "__main__":
34+
main()

0 commit comments

Comments
 (0)