Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to display expected arguments

32 views
Skip to first unread message

Cecil Westerhof

unread,
May 26, 2018, 4:44:05 PM5/26/18
to
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?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Cecil Westerhof

unread,
May 27, 2018, 6:44:05 AM5/27/18
to
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

Rich

unread,
May 27, 2018, 9:24:55 AM5/27/18
to
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").

Cecil Westerhof

unread,
May 27, 2018, 10:44:05 AM5/27/18
to
Rich <ri...@example.invalid> writes:

> 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.

That is exactly what I do. ;-)

I wanted to share the program on the WiKi, but that is sadly not
possible because the reCAPTCHA needs to be updated to a newer version.
0 new messages