This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: trivial mkpasswd defect


> -----Original Message-----
> From: cygwin-owner@cygwin.com [mailto:cygwin-owner@cygwin.com]On Behalf
> Of Michael A Chase
...
> On Wed, 29 May 2002 15:33:19 -0700 (Pacific Daylight Time) Michael A
> Chase <mchase@ix.netcom.com> wrote:
>
> > I don't see anything there that says that POSIX endorses '-?' for
> > displaying the usage message.  It just shows how to handle invalid option
> > characters.  If getopt sees an invalid character after '-' it
> returns '?' and puts the
> > invalid character ("?" in your example) in optopt.  In that example, I'd
> > expect to see
> . . .
>
> I should have been explicit about one item.  Asking for help shouldn't be
> an error.

Well, I agree with you.  That's why it's nice to have -h, or --help.  They're
not errors.  However, if you get -? what should you do?  Print the usage and
return an error.

According to the Cygwin Overview:
	The Cygwin tools are ports of the popular GNU development tools and
	utilities for Windows NT and 9x.
And the GNU guidelines support POSIX (with extensions).
<BLOCKQUOTE>
Standards for Command Line Interfaces

It is a good idea to follow the POSIX guidelines for the command-line options of
a program. The easiest way to do this is to use getopt to parse them. Note that
the GNU version of getopt will normally permit options anywhere among the
arguments unless the special argument `--' is used. This is not what POSIX
specifies; it is a GNU extension.
</BLOCKQUOTE>

A lot of commands with extensive "help" have a brief usage command that mentions
how to get the longer help.

My point---and I'm sticking to it---is that if you get -? you _should_ print
something.  I don't mind at all using -h and/or --help or even --tutorial,
but the bedrock of it all is to respond to the user that commits an error with
an intelligible message about usage.

I'd even concede that you don't have to put -? in the usage message itself.
It's sort of a ground-level default for getopt()-compatible commands.
>From that point of view, -? is just a useful "trick" to see how the command
responds to errors.  However, since it is so convenient, I encourage
advertising its presence in the usage and man page.

Someone brought up the point about -? being wildcard.  This is true, and
users "should" be aware of this, even though there's hardly ever a file
name that matches it.  (If there were, <code>foo *</code> would generate
"options" instead of file names.  So this is something best avoided.
(BTW, you could say <code>foo ./*</code> to be safe.))

In http://www.gnu.org/prep/standards_18.html#SEC18
<BLOCKQUOTE>
All programs should support two standard options: `--version' and `--help'.
...
--help
This option should output brief documentation for how to invoke the program, on
standard output, then exit successfully. Other options and arguments should be
ignored once this is seen, and the program should not perform its normal
function.
</BLOCKQUOTE>

Strangely enough, the table of long options,
http://www.gnu.org/prep/standards_19.html#SEC19
doesn't mention -h as an alternative to --help.
In fact -h is only mentioned as a synonym to --header:
`header'
`-h' in objdump and recode

Using -? _should_ be considered an error, in the sense of non-zero return value.
The getopt example does this:
>     if (errflg) {
>         fprintf(stderr, "usage: . . . ");
>         exit(2);
In this (POSIX) example,
http://www.opengroup.org/onlinepubs/007904975/functions/getopt.html
-? (or some other error such as -a and -b together) was the only way
to generate the usage string.  The GNU standard is a bit more friendly,
requiring a consistent error-free way to generate usage.

Using --help (GNU required) or -h (AFAICS optional) should be considered
successful, and should return 0.





--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]