Cecil Westerhof <
Ce...@decebal.nl> wrote:
> Cecil Westerhof <
Ce...@decebal.nl> writes:
>
>> I wrote a simple FizzBuzz program.
>> It should be called with no parameters.
>> Or only with the maximum value.
>> Or with start value followed by maximum value.
>>
>> I want to give an usage message when it is called wrongly. What would
>> be the standard way for a tcl program to display those options?
>
> I have opted for the following:
> WRONG ARGUMENTS
> USAGE:
> fizzBuzz.tcl
> fizzBuzz.tcl endValue
> fizzBuzz.tcl startValue endValue
> fizzBuzz.tcl --help
>
> Default: startValue = 1, endValue = 100
>
>
> And when called with --help I off-course give:
> USAGE:
> fizzBuzz.tcl
> fizzBuzz.tcl endValue
> fizzBuzz.tcl startValue endValue
> fizzBuzz.tcl --help
>
> Default: startValue = 1, endValue = 100
Seems understandable for this bit of code.
I would suggest one more item. When using the "--help" option to
request help explicitly, then send the output to stdout, but when
reporting because of an actual error in usage, send the output to
stderr.
The reason being, when I am *explicitly asking* for the help text on
the CLI, I very well may want to pipe it to 'less', [1] and sending
explicit "--help" output to stderr means one needs to do a "2>&1"
incantation in bash before it goes to stdout where less can pick it up.
I've encountered numerous CLI programs that also send explicit "--help"
requests to stderr, and it always bugs me when I run into one of them.
[1] Admittedly not too likely here, given only six lines, but for a much
more extensive CLI tool, the --help output can easily exceed several
screens (i.e., output of "rsync --help").