summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xftt-codegen30
1 files changed, 20 insertions, 10 deletions
diff --git a/ftt-codegen b/ftt-codegen
index bc2d28a..9f2644a 100755
--- a/ftt-codegen
+++ b/ftt-codegen
@@ -136,18 +136,18 @@ def infer_basename(markdowns):
return root
-# This only allows one markdown filename. This is crap. But I can't
-# get it work with -- otherwise. What I want is for the following to
-# work:
-# ftt-codegen --pdf foo.md bar.md -- --test-arg --other-test-arg
-# but I can't make it work.
-def parse_cli():
+# Usage example:
+# ftt-codegen foo.md bar.md -- --test-arg --other-test-arg
+def parse_cli(argv=None):
p = argparse.ArgumentParser()
p.add_argument('--run', action='store_true')
- p.add_argument('markdown', nargs=1)
- args, more_args = p.parse_known_args()
- if more_args and more_args[0] == '--':
- more_args = more_args[1:]
+ p.add_argument('markdown', nargs='A...')
+ args = p.parse_args(argv)
+ more_args = []
+ if '--' in args.markdown:
+ break_index = args.markdown.index('--')
+ more_args = args.markdown[break_index + 1:]
+ args.markdown = args.markdown[:break_index]
return args, more_args
@@ -166,6 +166,16 @@ def debug(msg):
sys.stderr.write('DEBUG: {}\n'.format(msg))
sys.stderr.flush()
+def test_parse_cli():
+ args, more_args = parse_cli([
+ 'foo.md', 'bar.md', '--', '--test-arg', '--other-test-arg'
+ ])
+ assert args.markdown == ['foo.md', 'bar.md']
+ assert more_args == ['--test-arg', '--other-test-arg']
+
+ args, more_args = parse_cli(['foo.md'])
+ assert args.markdown == ['foo.md']
+ assert not more_args
args, test_args = parse_cli()