summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Peveler <matt.peveler@gmail.com>2022-02-10 19:53:08 -0500
committerGitHub <noreply@github.com>2022-02-11 00:53:08 +0000
commitca4594541ca98f6e062158a4b5f43e2379469e94 (patch)
tree9c596262f894fd556771cd6738b0a7e6e58c806d
parentb40326325e5985c8b60366237eabe850b32d2176 (diff)
downloadasciidoc-py3-ca4594541ca98f6e062158a4b5f43e2379469e94.tar.gz
Fix parsing asciidoc_opt values with spaces for a2x (#237)
-rw-r--r--asciidoc/a2x.py21
-rw-r--r--tests/test_a2x.py32
2 files changed, 45 insertions, 8 deletions
diff --git a/asciidoc/a2x.py b/asciidoc/a2x.py
index 2ba2df9..be70367 100644
--- a/asciidoc/a2x.py
+++ b/asciidoc/a2x.py
@@ -873,11 +873,10 @@ class A2X(AttrDict):
shell_rm(html_file)
-def cli():
- global OPTIONS
-
+def parse_args(argv):
description = '''A toolchain manager for AsciiDoc (converts Asciidoc text files to other file formats)'''
from optparse import OptionParser
+ import shlex
parser = OptionParser(usage='usage: %prog [OPTIONS] SOURCE_FILE',
version='%s %s' % (PROG,VERSION),
description=description)
@@ -976,18 +975,24 @@ def cli():
parser.add_option('-v', '--verbose',
action='count', dest='verbose', default=0,
help='increase verbosity')
- if len(sys.argv) == 1:
+ if len(argv) == 1:
parser.parse_args(['--help'])
- source_options = get_source_options(sys.argv[-1])
- argv = source_options + sys.argv[1:]
- opts, args = parser.parse_args(argv)
+ source_options = get_source_options(argv[-1])
+ new_argv = source_options + argv[1:]
+ opts, args = parser.parse_args(new_argv)
if len(args) != 1:
parser.error('incorrect number of arguments')
- opts.asciidoc_opts = [x.split(' ') for x in opts.asciidoc_opts]
+ opts.asciidoc_opts = shlex.split(' ' .join(opts.asciidoc_opts))
opts.dblatex_opts = ' '.join(opts.dblatex_opts)
opts.fop_opts = ' '.join(opts.fop_opts)
opts.xsltproc_opts = ' '.join(opts.xsltproc_opts)
opts.backend_opts = ' '.join(opts.backend_opts)
+ return (new_argv, opts, args)
+
+
+def cli():
+ global OPTIONS
+ argv, opts, args = parse_args(sys.argv)
opts = eval(str(opts)) # Convert optparse.Values to dict.
a2x = A2X(opts)
OPTIONS = a2x # verbose and dry_run used by utility functions.
diff --git a/tests/test_a2x.py b/tests/test_a2x.py
new file mode 100644
index 0000000..0535731
--- /dev/null
+++ b/tests/test_a2x.py
@@ -0,0 +1,32 @@
+# flake8: noqa E501
+
+from asciidoc import a2x
+import pytest
+
+
+@pytest.mark.parametrize(
+ "input,expected",
+ (
+ (
+ ['a2x', '-vv', '-L', "--asciidoc-opts=-f ../build/mscgen-filter.conf -f ../build/diag-filter.conf -f ../build/docinfo-releaseinfo.conf -a srcdir='/home/user/code/osmo-dev/src/osmo-gsm-manuals/tests' -a commondir='../common'", '--dblatex-opts=-s ../build/custom-dblatex.sty -P draft.mode=yes -P draft.watermark=0', '-a', 'docinfo', '-a', 'revnumber=DRAFT ', '-a', 'revdate=unknown', 'test-usermanual.adoc'],
+ (
+ ['-vv', '-L', "--asciidoc-opts=-f ../build/mscgen-filter.conf -f ../build/diag-filter.conf -f ../build/docinfo-releaseinfo.conf -a srcdir='/home/user/code/osmo-dev/src/osmo-gsm-manuals/tests' -a commondir='../common'", '--dblatex-opts=-s ../build/custom-dblatex.sty -P draft.mode=yes -P draft.watermark=0', '-a', 'docinfo', '-a', 'revnumber=DRAFT ', '-a', 'revdate=unknown', 'test-usermanual.adoc'],
+ {'attributes': ['docinfo', 'revnumber=DRAFT ', 'revdate=unknown'], 'asciidoc_opts': ['-f', '../build/mscgen-filter.conf', '-f', '../build/diag-filter.conf', '-f', '../build/docinfo-releaseinfo.conf', '-a', 'srcdir=/home/user/code/osmo-dev/src/osmo-gsm-manuals/tests', '-a', 'commondir=../common'], 'copy': False, 'conf_file': None, 'destination_dir': None, 'doctype': None, 'backend': None, 'epubcheck': False, 'format': 'pdf', 'icons': False, 'icons_dir': None, 'keep_artifacts': False, 'lynx': False, 'no_xmllint': True, 'dry_run': False, 'resources': [], 'resource_manifest': None, 'skip_asciidoc': False, 'stylesheet': None, 'safe': False, 'dblatex_opts': '-s ../build/custom-dblatex.sty -P draft.mode=yes -P draft.watermark=0', 'backend_opts': '', 'fop': False, 'fop_opts': '', 'xsltproc_opts': '', 'xsl_file': None, 'verbose': 2},
+ ['test-usermanual.adoc'],
+ ),
+ ),
+ (
+ ['a2x', '-v', "--asciidoc-opts=-v -f doc/asciidoc.conf -a manmanual='Pakku Manual' -a mansource='Pakku' -a manversion=0.14-36g22678d2", 'doc/pakku.conf.5.txt'],
+ (
+ ['-v', "--asciidoc-opts=-v -f doc/asciidoc.conf -a manmanual='Pakku Manual' -a mansource='Pakku' -a manversion=0.14-36g22678d2", 'doc/pakku.conf.5.txt'],
+ {'attributes': [], 'asciidoc_opts': ['-v', '-f', 'doc/asciidoc.conf', '-a', 'manmanual=Pakku Manual', '-a', 'mansource=Pakku', '-a', 'manversion=0.14-36g22678d2'], 'copy': False, 'conf_file': None, 'destination_dir': None, 'doctype': None, 'backend': None, 'epubcheck': False, 'format': 'pdf', 'icons': False, 'icons_dir': None, 'keep_artifacts': False, 'lynx': False, 'no_xmllint': False, 'dry_run': False, 'resources': [], 'resource_manifest': None, 'skip_asciidoc': False, 'stylesheet': None, 'safe': False, 'dblatex_opts': '', 'backend_opts': '', 'fop': False, 'fop_opts': '', 'xsltproc_opts': '', 'xsl_file': None, 'verbose': 1},
+ ['doc/pakku.conf.5.txt'],
+ ),
+ ),
+ )
+)
+def test_parse_args(input, expected):
+ argv, opts, args = a2x.parse_args(input)
+ assert argv == expected[0]
+ assert opts == expected[1]
+ assert args == expected[2]