File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 11import argparse
2+ import sys
23
34from . import CowsayError , char_names , char_funcs , __version__
45
@@ -15,7 +16,7 @@ def cli():
1516 default = 'cow' )
1617
1718 parser .add_argument ('-t' , '--text' ,
18- required = True )
19+ help = 'Text to display. If not provided, reads from stdin.' )
1920
2021 parser .add_argument ('-v' , '--version' ,
2122 action = 'version' , version = __version__ )
@@ -25,7 +26,15 @@ def cli():
2526 if args .character not in char_names :
2627 raise CowsayError (f'Available Characters: { char_names } ' )
2728
28- char_funcs [args .character ](args .text )
29+ if args .text :
30+ text = args .text
31+ else :
32+ if sys .stdin .isatty ():
33+ print ("using pipe" )
34+ parser .error ('Text argument is required if not piping input.' )
35+ text = sys .stdin .read ().strip ()
36+
37+ char_funcs [args .character ](text )
2938
3039
3140if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments