From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21713 invoked by alias); 30 May 2002 13:17:58 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 21625 invoked from network); 30 May 2002 13:17:53 -0000 Received: from unknown (HELO firewall1ext.vx.com) (65.34.19.122) by sources.redhat.com with SMTP; 30 May 2002 13:17:53 -0000 Received: from port (port.vx.com [192.168.1.231]) by firewall1ext.vx.com (8.11.0/8.11.0) with SMTP id g4UDHmX21669; Thu, 30 May 2002 09:17:48 -0400 From: "Bernard A Badger" To: "Michael A Chase" , Subject: RE: trivial mkpasswd defect Date: Thu, 30 May 2002 09:20:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal In-Reply-To: Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-SW-Source: 2002-05/txt/msg01859.txt.bz2 > -----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 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).
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.
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, foo * would generate "options" instead of file names. So this is something best avoided. (BTW, you could say foo ./* to be safe.)) In http://www.gnu.org/prep/standards_18.html#SEC18
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.
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/