diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2022-11-25 12:28:29 +0300 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2022-11-25 12:35:05 +0300 |
commit | 176da025af39e788877446183b530701a54f5057 (patch) | |
tree | cb06373dcab8f7330643dcf795a2fe6ac5b2e12d /generator | |
parent | 9a8776022f9c874c3736a46ac700645dc9cacf9b (diff) |
Fix handling of spaces in arguments passed through protoc (#810)
Nanopb has traditionally supported spaces as separator in command
line arguments. Protoc uses comma as the separator.
There is automatic detection that tries to handle this, but previously
it got tripped on any space character in the arguments.
Changed the detection so that only space followed by dash is taken
as a space-separated argument.
Preferred usage through protoc is:
protoc --nanopb_out=outdir [--nanopb_opt=option] ['--nanopb_opt=option with spaces'] file.proto
Diffstat (limited to 'generator')
-rwxr-xr-x | generator/nanopb_generator.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 42e87f9..1fc9f73 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -13,6 +13,7 @@ import copy import itertools import tempfile import shutil +import shlex import os from functools import reduce @@ -2521,19 +2522,19 @@ def main_plugin(): except UnicodeEncodeError: params = request.parameter - import shlex - args = shlex.split(params) - - if len(args) == 1 and ',' in args[0]: - # For compatibility with other protoc plugins, support options - # separated by comma. + if ',' not in params and ' -' in params: + # Nanopb has traditionally supported space as separator in options + args = shlex.split(params) + else: + # Protoc separates options passed to plugins by comma + # This allows also giving --nanopb_opt option multiple times. lex = shlex.shlex(params) lex.whitespace_split = True lex.whitespace = ',' lex.commenters = '' args = list(lex) - optparser.usage = "Usage: protoc --nanopb_out=[options][,more_options]:outdir file.proto" + optparser.usage = "protoc --nanopb_out=outdir [--nanopb_opt=option] ['--nanopb_opt=option with spaces'] file.proto" optparser.epilog = "Output will be written to file.pb.h and file.pb.c." if '-h' in args or '--help' in args: |