Skip to content

Commit abb66cf

Browse files
committed
Implement configurable cowsay animal.
1 parent 0bd44cc commit abb66cf

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

implement-cowsay/cow.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
11
import cowsay
2-
import sys
2+
import argparse
3+
4+
parser = argparse.ArgumentParser(prog="cow.py",
5+
description="Print a message using a cowsay animal")
6+
7+
parser.add_argument("message")
8+
parser.add_argument("-a",
9+
"--animal",
10+
default="cow",
11+
help="Animal to use for the speech bubble.")
12+
13+
args = parser.parse_args()
14+
15+
animal_names = cowsay.char_names
16+
17+
if args.animal not in animal_names:
18+
parser.error("The specified animal is not found in the cowsay animal list.")
19+
20+
animal_function = getattr(cowsay, args.animal)
21+
animal_function(args.message)

0 commit comments

Comments
 (0)