Skip to content

Commit

Permalink
treat flag options as special
Browse files Browse the repository at this point in the history
Instead of requiring the user to provide a value for a flag option,
use the presence of the option on the command line as a "true" value,
just as is done in rst.

Signed-off-by: Doug Hellmann <[email protected]>
  • Loading branch information
dhellmann committed Sep 6, 2020
1 parent a46c224 commit 69c2d99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions doc/source/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Command Line

.. code-block:: bat
datatemplate -o multiple-documents:1 doc/source/_templates/sample-multiple.tmpl doc/source/sample-multiple.yaml
datatemplate -o multiple-documents doc/source/_templates/sample-multiple.tmpl doc/source/sample-multiple.yaml
Output
======

.. runcmd:: datatemplate -o multiple-documents:1 doc/source/_templates/sample-multiple.tmpl doc/source/sample-multiple.yaml
.. runcmd:: datatemplate -o multiple-documents doc/source/_templates/sample-multiple.tmpl doc/source/sample-multiple.yaml
15 changes: 10 additions & 5 deletions sphinxcontrib/datatemplates/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ def main():
with io.open(args.config_file, 'r', encoding='utf-8-sig') as f:
config_body = f.read()
exec(config_body, config_globals)
# add options
config_globals.update({
k.replace("-", "_"): v
for k, _, v in (s.partition(':') for s in args.option)
})
# Add options. If there is a colon, use it to separate the option
# name from its value. If there is no colon, treat the option as a
# flag.
for opt in args.option:
if ':' in opt:
k, _, v = opt.partition(':')
else:
k = opt
v = True
config_globals[k.replace('-', '_')] = v
# add special options
config_globals.update({
"source":
Expand Down

0 comments on commit 69c2d99

Please sign in to comment.