From 8e9fd4fcc13c2c454d761bfc3d71eef5f11085c2 Mon Sep 17 00:00:00 2001 From: Pezhman-Azizi <80008463+Pezhman-Azizi@users.noreply.github.com> Date: Wed, 10 Dec 2025 16:32:46 +0000 Subject: [PATCH] Implement cowsay CLI using cowsay library --- implement-cowsay/cow.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 implement-cowsay/cow.py diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py new file mode 100644 index 00000000..ed305757 --- /dev/null +++ b/implement-cowsay/cow.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +import argparse +import cowsay + + +def main(): + # 1. Get supported animals dynamically from the library + animals = list(cowsay.char_names) + + # 2. Set up the argument parser + parser = argparse.ArgumentParser( + description="Make animals say things" + ) + + parser.add_argument( + "--animal", + choices=animals, + default="cow", + help="The animal to be saying things." + ) + + parser.add_argument( + "message", + nargs="+", + help="The message to say." + ) + + # 3. Parse arguments + args = parser.parse_args() + + # 4. Combine message words into a single string + text = " ".join(args.message) + + # 5. Dynamically call the correct animal function + # e.g. cowsay.cow(text), cowsay.turtle(text), etc. + speaker = getattr(cowsay, args.animal) + print(speaker(text)) + + +if __name__ == "__main__": + main()