#5 OptionParser()'s description arg to recognize `%prog'

closed
Greg Ward
5
2004-07-24
2004-07-09
Micah Elliott
No

Presently it appears that I cannot use `\n' or `%prog'
in the `description' arg. Thus, code like:
...
parser = OptionParser(..., description='This %prog
program does nothing.\n')
...

comes out looking like:

$ foo
usage: foo ...

This %prog program does nothing.
options:
--version
...

[I just started using optparse today so sorry if I
missed something. Thanks a lot for the tool!]

Discussion

  • Greg Ward
    Greg Ward
    2004-07-24

    Logged In: YES
    user_id=14422

    Good catch on the %prog in 'description' thing. I'm sure I
    would have noticed this the first time I used 'description'
    (which I have yet to do!). This is pretty easy to do for
    the description attached to the OptionParser instance; not
    so for the OptionGroup description. So I'm going to go
    halfway and expand %prog in the description of the whole
    program, but not the descriptions of option groups. Good
    enough, I think.

    Fixed in:
    lib/option_parser.py rev 1.65
    lib/help.py rev 1.14
    test/test_optik.py rev 1.31

     
  • Greg Ward
    Greg Ward
    2004-07-24

    Logged In: YES
    user_id=14422

    Oh yeah: the "swallowed newline" is because Optik uses
    textwrap to wrap the description as a single paragraph. The
    current CVS code prints an extra newline after the
    description so the output looks nicer. Will be in Optik
    1.5, hopefully Python 2.4.

     
  • Greg Ward
    Greg Ward
    2004-07-24

    • status: open --> closed