File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ import argparse
3+ import sys
4+ import cowsay
5+
6+ def main ():
7+ # Dynamically get available animals from the cowsay library
8+ animals = sorted (cowsay .char_names )
9+
10+ parser = argparse .ArgumentParser (
11+ prog = "cowsay" ,
12+ description = "Make animals say things"
13+ )
14+ parser .add_argument (
15+ "message" ,
16+ nargs = "+" ,
17+ help = "The message to say."
18+ )
19+ parser .add_argument (
20+ "--animal" ,
21+ choices = animals ,
22+ default = "cow" ,
23+ help = "The animal to be saying things."
24+ )
25+
26+ args = parser .parse_args ()
27+ msg = " " .join (args .message )
28+
29+ # Render the chosen animal saying the message
30+ output = cowsay .get_output_string (args .animal , msg )
31+ sys .stdout .write (output + "\n " )
32+
33+ if __name__ == "__main__" :
34+ main ()
You can’t perform that action at this time.
0 commit comments