GetOpt formatting improvements

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Sun Jun 29 17:46:47 EDT 2008


GetOpt users,

I'd like to have Cabal use the standard System.Console.GetOpt but I'd
also like the output to look ok. Currently Cabal uses a private modified
version of GetOpt with improved formatting and I'd like to get those
improvements into the standard one and eliminate the code duplication.

Here's what cabal configure looks like with the standard
System.Console.GetOpt. This is what it looks like on a standard 80
column console. In particular note that the descriptions wrap around
onto the following lines and look ugly.

http://hpaste.org/8626

Here's a little snippet:

            --enable-library-for-ghci       Enable compile library for use with 
GHCi
            --disable-library-for-ghci      Disable compile library for use wit
h GHCi
            --enable-split-objs             Enable split library into smaller ob
jects to reduce binary sizes (GHC 6.6+)
            --disable-split-objs            Disable split library into smaller o
bjects to reduce binary sizes (GHC 6.6+)
            --enable-executable-stripping   Enable strip executables upon instal
lation to reduce binary sizes
            --disable-executable-stripping  Disable strip executables upon insta
llation to reduce binary sizes
            --configure-option=OPT          Extra option for configure
            --user                          Enable doing a per-user installation
            --global                        Disable doing a per-user installatio
n
            --package-db=PATH               Use a specific package database (to 
satisfy dependencies and register in)

Here's the same but using the internal modified copy of GetOpt:

http://hpaste.org/8626#a1

and the same snippet:

    --enable-library-for-ghci      Enable compile library for use with GHCi
    --disable-library-for-ghci     Disable compile library for use with GHCi
    --enable-split-objs            Enable split library into smaller objects to
                                   reduce binary sizes (GHC 6.6+)
    --disable-split-objs           Disable split library into smaller objects
                                   to reduce binary sizes (GHC 6.6+)
    --enable-executable-stripping  Enable strip executables upon installation
                                   to reduce binary sizes
    --disable-executable-stripping Disable strip executables upon installation
                                   to reduce binary sizes
    --configure-option=OPT         Extra option for configure
    --user                         Enable doing a per-user installation
    --global                       Disable doing a per-user installation
    --package-db=PATH              Use a specific package database (to satisfy
                                   dependencies and register in)

So there's two things to notice. One is that we wrap the description so
it fits in 80 columns. The other is that we use one space rather than
two of padding between the short options, the long options and the
description. This gives more space for the description.

Actually we go one step further and leave off the args on the short
options since they're shown on the long options anyway. I'm not sure
everyone wants that so I'm not really proposing it. This is what it
looks like:

  -f FLAGS  --flags=FLAGS                   Force values for the given...
vs
 -f --flags=FLAGS                  Force values for the given flags in...

Similarly:

  -v[n]     --verbose[=n]                   Control verbosity (n is 0--3,...
vs
 -v --verbose[=n]                  Control verbosity (n is 0--3, default...


So if people think this is sensible I'll send three patches:
     1. word-wrap the description to fit in 80 columns
     2. use less padding between columns
     3. omit the args on short options when there is also a
        corresponding long option

though as I say, perhaps not everyone will think the 3rd change is the
right thing to do.

Duncan



More information about the Libraries mailing list