Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions implement-cowsay/cow.py
Original file line number Diff line number Diff line change
@@ -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()