From 4a17bebb311a03e40e0c0b3069fd3c4c9dfc1554 Mon Sep 17 00:00:00 2001 From: Federico Oro Vojacek Date: Mon, 12 May 2025 09:25:31 -0300 Subject: [PATCH] [usage] prints full usage text [validation] show errors when --I, --D, or --P are given empty arguments --- src/pycppgen.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/pycppgen.py b/src/pycppgen.py index dc2cb9d..3c09be7 100644 --- a/src/pycppgen.py +++ b/src/pycppgen.py @@ -1452,11 +1452,20 @@ def ProcessFile(file : str, compilerOptions) : if needsParseTU or needsCodeGen : FilesToCodeGen.add(file) +def show_usage() : + print("usage pycppgen.py ") + print("options:") + print(" -I") + print(" -D") + print(" --I") + print(" --D") + print(" --P") + def main(args : list) : global FilesToParse, PerFileData, ProjectPath, CacheFile, OutdatedFiles, CachedPerFileData, FilesToCodeGen if len(args) < 1 : - atomic_print("usage py main.py ") + show_usage() exit(-1) ProjectPath = str(pathlib.Path(args[0]).resolve()) @@ -1466,6 +1475,10 @@ def main(args : list) : if arg.startswith("--I") : args.remove(arg) arg = arg[3:] + if not arg: + print("error: no includes after --I. Did you add a space?") + print("Expected format: --I") + exit(-1) for i in arg.split(";") : if not pathlib.Path(i).is_absolute() : i = ResolvePath(os.path.join(ProjectPath, i)) @@ -1473,11 +1486,19 @@ def main(args : list) : if arg.startswith("--D") : args.remove(arg) arg = arg[3:] + if not arg: + print("error: no defines after --D. Did you add a space?") + print("Expected format: --D") + exit(-1) for i in arg.split(";") : args.append(f"-D{i}") if arg.startswith("--P") : args.remove(arg) arg = arg[3:] + if not arg: + print("error: no dependencies after --P. Did you add a space?") + print("Expected format: --P") + exit(-1) for i in arg.split(";") : if not pathlib.Path(i).is_absolute() : i = ResolvePath(os.path.join(ProjectPath, i)) @@ -1593,9 +1614,5 @@ def main(args : list) : os.remove(file) if __name__ == "__main__": - if len(sys.argv) < 2 : - atomic_print("usage py main.py ") - exit(-1) - main(sys.argv[1:])