GetOpt formatting improvements

Benjamin Franksen benjamin.franksen at bessy.de
Wed Jul 2 12:00:51 EDT 2008


Brandon S. Allbery KF8NH wrote:
> On 2008 Jun 30, at 2:00, Johan Tibell wrote:
>> On Sun, Jun 29, 2008 at 11:46 PM, Duncan Coutts
>> <duncan.coutts at worc.ox.ac.uk> wrote:
>>> So if people think this is sensible I'll send three patches:
>>>    1. word-wrap the description to fit in 80 columns

I agree with others that 79 is better default. (Btw, finding out the
terminal width is a IO action, so we can't do that. I like it very much
that the API for GetOpt is pure.)

Anyway, the maximum output width, as well as a maximum indentation for the
option descriptions should be arguments to (new, additional) functions
getOptExt and usageInfoExt, with the old getOpt and usageInfo being defined
in terms of the new variants.

>>>    2. use less padding between columns

Yes, but add a comma, see below.

>>>    3. omit the args on short options when there is also a
>>>       corresponding long option

I think this is an excellent idea.

>> What does GNU getopt do in all these cases? I'd prefer if the programs
>> I use on the command line are consistent in their `--help' display and
>> GNU getopt seems to be the standard here. Trying to follow what other
>> people do also makes shell scripting easier.
> 
> Options are indented by two spaces.

Whitespace shouldn't matter for parsing usage output, so we can deviate from
GNU here. I think one space is enough.

> Short options are separated from long by ", ", 

Here we should follow GNU, I think.

> and that column is left 
> empty if there is no corresponding short option.

This looks nice IMO (and we agree with GNU already).

> Option descriptions begin one space after the longest option that
> doesn't extend past column 30, and word wrap with wrapped lines
> indented by two additional spaces.  If any options go past column 30,
> their descriptions start one space after the options without
> attempting to align with the other descriptions, except that wrapped
> lines are aligned.

It makes sense to have a _maximum_ indentation for the description,
otherwise one very long option name completely ruins the layout. Following
GNU (de facto) standard makes sense here.

> Note --help and --version (no short options; also, they're boilerplate
> and apparently GNU getopt makes no attempt to match their
> descriptions' indentations with the other options, instead using a
> tab) 

Which is a bug, IMO, we should not copy that.

Cheers
Ben



More information about the Libraries mailing list