Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions implement-cowsay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv/
17 changes: 17 additions & 0 deletions implement-cowsay/cow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import argparse
import cowsay


parser = argparse.ArgumentParser(description="implement Cowsay command")
parser.add_argument("text", help="Text to be displayed")
parser.add_argument("--animal", help="Animal to say the text", default="cow")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get the help to show the list of possible animals?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback. I’ve added a list of all cowsay animals to the help output so can see the available options.

args = parser.parse_args()

animals = cowsay.char_names
animal = args.animal.lower()
if animal not in animals:
print(f"Invalid animal. Supported animals are: {', '.join(animals)}")
exit(1)
cowsay.char_funcs[animal](args.text)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if I give my arguments as plain text, without quotes?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback
I’ve updated the script to support multi-word text without quotes by using (nargs="+") for the text argument.