diff options
author | Tyler Cipriani <tyler@tylercipriani.com> | 2019-07-19 08:16:17 -0600 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-07-23 10:54:29 +0300 |
commit | 47413b75725b6ee3062a59f0e4b73ae723b3e92f (patch) | |
tree | c7bc237d2828513af2d27c2f8b3bbd76e4135090 /ftt-codegen | |
parent | 2d057839b52e5b3c075db71943b98182d4b23cc7 (diff) | |
download | fable-poc-47413b75725b6ee3062a59f0e4b73ae723b3e92f.tar.gz |
fcc-codegen: allow '--' in "markdown" argument
By Using the PARSER (i.e., "A...") argument for nargs, '--' becomes an
allowed value in the argument list. This should resolve the TODO comment
in the file. There is a test funciton in this file as well (I wasn't
sure where to put the test, but it's working).
Diffstat (limited to 'ftt-codegen')
-rwxr-xr-x | ftt-codegen | 30 |
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() |