Skip to content

Commit f39e5b5

Browse files
committed
update the --help option content to show the range of animal options an end user can select from
1 parent 35ecdac commit f39e5b5

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

implement-cowsay/cow.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
import sys
33
import argparse
44

5+
listed_animals = [listed_animal for listed_animal in dir(cowsay) if callable(getattr(cowsay, listed_animal)) and not listed_animal.startswith("__") and listed_animal not in ["draw", "func", "get_output_string", "CowsayError"]]
6+
57
parser = argparse.ArgumentParser(
68
prog="cow",
79
description="Makes animals say things",
810
)
911

10-
parser.add_argument("--animal", help="Select an animal to say anything")
12+
parser.add_argument("--animal", help="Select an animal to say anything", choices=listed_animals)
1113
parser.add_argument("message", nargs ="+", help="The message that the animal says")
1214

1315
args = parser.parse_args()
1416

1517
message = " ".join(args.message)
1618
animal = args.animal or "cow"
1719

18-
listed_animals = [listed_animal for listed_animal in dir(cowsay) if callable(getattr(cowsay, listed_animal)) and not listed_animal.startswith("__") and listed_animal not in ["draw", "func", "get_output_string", "CowsayError"]]
1920

2021
if animal not in listed_animals:
2122
print(f"Error: argument --animal: invalid choice: '{animal}'. Choose from: {', '.join(listed_animals)}")

0 commit comments

Comments
 (0)