Message111221
Porting the a2x program to argparse from the now-deprecated optparse subtly breaks it when certain options are passed:
$ a2x --asciidoc-opts --safe gitcli.txt
$ ./a2x.argparse --asciidoc-opts --safe gitcli.txt
usage: a2x [-h] [--version] [-a ATTRIBUTE] [--asciidoc-opts ASCIIDOC_OPTS]
[--copy] [--conf-file CONF_FILE] [-D PATH] [-d DOCTYPE]
[--epubcheck] [-f FORMAT] [--icons] [--icons-dir PATH] [-k]
[--lynx] [-L] [-n] [-r PATH] [-s] [--stylesheet STYLESHEET]
[--safe] [--dblatex-opts DBLATEX_OPTS] [--fop]
[--fop-opts FOP_OPTS] [--xsltproc-opts XSLTPROC_OPTS] [-v]
a2x: error: argument --asciidoc-opts: expected one argument
Apparently argparse uses a heuristic to try to guess whether an argument looks like an argument or an option, going so far as to check whether it looks like a negative number (!). It should _never_ guess: the option was specified to take an argument, so the following argument should always be parsed as an argument.
Small test case:
>>> import optparse
>>> parser = optparse.OptionParser(prog='a2x')
>>> parser.add_option('--asciidoc-opts',
... action='store', dest='asciidoc_opts', default='',
... metavar='ASCIIDOC_OPTS', help='asciidoc options')
>>> parser.parse_args(['--asciidoc-opts', '--safe'])
(<Values at 0x7f585142ef80: {'asciidoc_opts': '--safe'}>, [])
>>> import argparse
>>> parser = argparse.ArgumentParser(prog='a2x')
>>> parser.add_argument('--asciidoc-opts',
... action='store', dest='asciidoc_opts', default='',
... metavar='ASCIIDOC_OPTS', help='asciidoc options')
>>> parser.parse_args(['--asciidoc-opts', '--safe'])
usage: a2x [-h] [--asciidoc-opts ASCIIDOC_OPTS]
a2x: error: argument --asciidoc-opts: expected one argument |
|
Date |
User |
Action |
Args |
2010-07-22 22:15:39 | andersk | set | recipients:
+ andersk |
2010-07-22 22:15:39 | andersk | set | messageid: <1279836939.11.0.811316280273.issue9334@psf.upfronthosting.co.za> |
2010-07-22 22:15:36 | andersk | link | issue9334 messages |
2010-07-22 22:15:36 | andersk | create | |
|