From 5af07adba600a2125e0a7ece45c7612d49ef967c Mon Sep 17 00:00:00 2001 From: eyuell21 Date: Sat, 2 Aug 2025 12:43:27 +0100 Subject: [PATCH 1/3] Added gitignore files. --- .gitignore | 1 + implement-cowsay/.gitignore | 1 + 2 files changed, 2 insertions(+) create mode 100644 implement-cowsay/.gitignore diff --git a/.gitignore b/.gitignore index 3c3629e6..3e5cc695 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +.venv/ \ No newline at end of file diff --git a/implement-cowsay/.gitignore b/implement-cowsay/.gitignore new file mode 100644 index 00000000..0cafc1cd --- /dev/null +++ b/implement-cowsay/.gitignore @@ -0,0 +1 @@ +.venv/ \ No newline at end of file From e448fe547b017caef4ed6392aa883434e2e10dd2 Mon Sep 17 00:00:00 2001 From: eyuell21 Date: Sat, 2 Aug 2025 12:44:15 +0100 Subject: [PATCH 2/3] created a requirements.txt files including the libraries to be installed. --- implement-cowsay/requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 implement-cowsay/requirements.txt diff --git a/implement-cowsay/requirements.txt b/implement-cowsay/requirements.txt new file mode 100644 index 00000000..c6b9ffd0 --- /dev/null +++ b/implement-cowsay/requirements.txt @@ -0,0 +1 @@ +cowsay From 96c0d120434bafc0a68928080994356aaac3d8d5 Mon Sep 17 00:00:00 2001 From: eyuell21 Date: Tue, 5 Aug 2025 09:23:12 +0100 Subject: [PATCH 3/3] Cowsay python implementation --- implement-cowsay/cow.py | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 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..0790661a --- /dev/null +++ b/implement-cowsay/cow.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import argparse +import cowsay +import inspect +import sys + +def get_supported_animals(): + animal_list = [] + for name, func in inspect.getmembers(cowsay, inspect.isfunction): + if not name.startswith('_') and name not in ['cowsay', 'cowthink']: + animal_list.append(name) + return sorted(animal_list) + + +def main(): + animals = get_supported_animals() + + 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=f'The animal to be saying things.' + ) + + args = parser.parse_args() + message = ' '.join(args.message) + + # Dynamically call the animal function (like cowsay.turtle("hello")) + try: + animal_func = getattr(cowsay, args.animal) + output = animal_func(message) + print(output) + except AttributeError: + print(f"Error: '{args.animal}' is not a valid animal.", file=sys.stderr) + sys.exit(1) + +if __name__ == '__main__': + main()