Skip to content

Commit bd6945c

Browse files
committed
last-review
1 parent 8eec635 commit bd6945c

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

implement-cowsay/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ usage: cowsay [-h] [--animal {beavis,cheese,cow,daemon,dragon,fox,ghostbusters,k
4949

5050
Make animals say things
5151

52+
53+
5254
positional arguments:
5355
message The message to say.
5456

implement-cowsay/cow.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
1-
import cowsay
21
import argparse
3-
import sys
4-
import os
2+
import cowsay
3+
4+
def main():
5+
# List of available animals (provided by the package)
6+
animals = cowsay.char_names
7+
8+
parser = argparse.ArgumentParser(
9+
prog="cowsay",
10+
description="Make animals say things"
11+
)
12+
13+
parser.add_argument(
14+
"message",
15+
nargs="+",
16+
help="The message to say."
17+
)
518

6-
# Dynamically determine the cows directory
7-
COWS_DIR = os.path.join(os.path.dirname(cowsay.__file__), "cows")
19+
parser.add_argument(
20+
"--animal",
21+
choices=animals,
22+
default="cow",
23+
help="The animal to be saying things."
24+
)
825

9-
# Set up argument parsing
10-
parser = argparse.ArgumentParser()
11-
parser.add_argument("--animal", required=True)
12-
parser.add_argument("message", nargs="+")
13-
args = parser.parse_args()
26+
args = parser.parse_args()
1427

15-
# Combine message parts into a single string
16-
message = " ".join(args.message)
28+
message = " ".join(args.message)
1729

18-
# Dynamically fetch available animals
19-
animals = [f[:-4] for f in os.listdir(COWS_DIR) if f.endswith(".cow")]
30+
# Dynamically call the function for the chosen animal
31+
animal_func = getattr(cowsay, args.animal)
32+
print(animal_func(message))
2033

21-
# Validate the provided animal
22-
if args.animal not in animals:
23-
print("Error: '--animal' is not a valid cowsay animal.")
24-
print("Available animals:", ", ".join(sorted(animals)))
25-
sys.exit(1)
2634

27-
# Just pass the animal name directly
28-
print(cowsay.cowsay(message, cow=args.animal))
35+
if __name__ == "__main__":
36+
main()

implement-cowsay/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cowsay

0 commit comments

Comments
 (0)