cowsay-org / cowsay

apjanke's fork of the classic cowsay project
http://cowsay.diamonds
GNU General Public License v3.0
83 stars 15 forks source link

cowsay -h: After help message, expecting program exit but cowsay waits for input instead #21

Closed ndim closed 2 months ago

ndim commented 2 years ago

When running cowsay -h, cowsay prints the help message and proceeds to wait for data on stdin, then finally prints a cow which says the data from stdin as if cowsay had been called.

My expectation is for cowsay -h to print the help message and exit the program.

As it is, cowsay -h does what I would expect cowsay -h; cowsay to do.

$ cowsay --version
/usr/bin/cowsay version 3.7.0 calling Getopt::Std::getopts (version 1.13),
running under Perl version 5.34.1.
$ cowsay -h
cowsay version 3.7.0

Usage:

    cowsay [-bdgpstwy] [-e <eyes>] [-f <cowfile> | -r [-C] ] 
        [-n] [-T <tongue>] [-W <wrapcolumn>]
        <message>
    cowsay -l    # List defined cows
    cowsay -h    # Displays this help screen

^C
$ cowsay -h
cowsay version 3.7.0

Usage:

    cowsay [-bdgpstwy] [-e <eyes>] [-f <cowfile> | -r [-C] ] 
        [-n] [-T <tongue>] [-W <wrapcolumn>]
        <message>
    cowsay -l    # List defined cows
    cowsay -h    # Displays this help screen

moo
^D
 _____ 
< moo >
 ----- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
$ _
apjanke commented 2 years ago

Your expectation is correct. cowsay -h should just display the help and then exit. This is a bug, and a dumb one. Should be an easy fix though.

Thanks for the report!

apjanke commented 2 months ago

Fixed in https://github.com/cowsay-org/cowsay/commit/46114bf10d40a3acd80604bc2db7a99705644842.

Your analysis here was correct. For the special case of handling cowsay -h (instead of cowsay --help), it was calling the function to display the help screen, but then not actually calling exit() to bail, and it fell through and moved on to the regular main case behavior, which in the absence of command-line positional arguments, read the message from stdin and displayed it.

Going out in cowsay 3.9.0. Or maybe earlier, like 3.8.1 or 3.8.2.