Skip to content

Commit 28a3a0a

Browse files
committed
completed cowsay
1 parent 0d554e0 commit 28a3a0a

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

implement-cowsay/cow.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
import argparse
2+
import cowsay
23
import sys
3-
from cowpy import cow
4+
5+
available_animals = cowsay.char_names
46

57
parser = argparse.ArgumentParser(
68
prog="cowsay",
7-
description="uses the cowsay library to show user-supplied text, as said by a specified animal",
9+
description="Uses the cowsay library to show user-supplied text, as said by a specified animal",
810
)
911

10-
parser.add_argument("--animal", help="The animal to be saying things", default="cowacter")
12+
parser.add_argument("--animal", help="The animal to be saying things", default="cow", choices=available_animals)
1113
parser.add_argument("message", help="The message to say", nargs="*", default=["Hello, World!"])
1214

1315
args = parser.parse_args()
1416

15-
16-
available_animals = {name.lower(): name for name in cow.Cowacter.cowacters} # List of all characters
17-
1817
msg = " ".join(args.message)
1918
animal = args.animal.lower()
2019

21-
if animal not in available_animals:
22-
print(f"Invalid choice: '{animal}' (choose from {', '.join(available_animals)})")
20+
if not hasattr(cowsay, animal):
21+
print(f"Invalid choice: '{args.animal}' (choose from: {', '.join(available_animals)})")
2322
sys.exit(1)
2423

25-
animal_class_name = available_animals[animal]
26-
AnimalClass = getattr(cow, animal_class_name)
27-
print(AnimalClass().milk(msg))
24+
# Dynamically call the cowsay function for the chosen animal
25+
getattr(cowsay, animal)(msg)

0 commit comments

Comments
 (0)