From c634395b11567963f6c0618ef247b10931cacad3 Mon Sep 17 00:00:00 2001 From: Pezhman-Azizi <80008463+Pezhman-Azizi@users.noreply.github.com> Date: Sun, 21 Sep 2025 15:35:07 +0100 Subject: [PATCH] implement cowsay --- implement-cowsay/cow.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 implement-cowsay/cow.py diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py new file mode 100755 index 00000000..52d1e98d --- /dev/null +++ b/implement-cowsay/cow.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +import argparse +import sys +import cowsay + +def main(): + # Dynamically get available animals from the cowsay library + animals = sorted(cowsay.char_names) + + parser = argparse.ArgumentParser( + prog="cowsay", + description="Make animals say things" + ) + parser.add_argument( + "message", + nargs="+", + help="The message to say." + ) + parser.add_argument( + "--animal", + choices=animals, + default="cow", + help="The animal to be saying things." + ) + + args = parser.parse_args() + msg = " ".join(args.message) + + # Render the chosen animal saying the message + output = cowsay.get_output_string(args.animal, msg) + sys.stdout.write(output + "\n") + +if __name__ == "__main__": + main()