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 diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py new file mode 100644 index 00000000..2f11b554 --- /dev/null +++ b/implement-cowsay/cow.py @@ -0,0 +1,51 @@ +#!/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) + if output is not None: + print(output) + except AttributeError: + print(f"Error: '{args.animal}' is not a valid animal.", file=sys.stderr) + sys.exit(1) + +if __name__ == '__main__': + main() 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