From 62658ba214ce35f5797c0244f49711e98f7e36d9 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Sun, 13 Nov 2022 22:30:34 +0000 Subject: [PATCH] Rearranging how main() works (#73) - Instead of duplicating the code in main() and the __main__ condition this uses only main() - main() now takes a list as input (the argv list) - main() returns the exit code instead of calling sys.exit() --- pcpp/pcmd.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pcpp/pcmd.py b/pcpp/pcmd.py index 5688e9a..2825741 100644 --- a/pcpp/pcmd.py +++ b/pcpp/pcmd.py @@ -247,10 +247,11 @@ def on_comment(self,tok): return True # Pass through return super(CmdPreprocessor, self).on_comment(tok) -def main(): - p = CmdPreprocessor(sys.argv) - sys.exit(p.return_code) +def main(argv=None): + if argv is None: + argv = sys.argv + p = CmdPreprocessor(argv) + return p.return_code if __name__ == "__main__": - p = CmdPreprocessor(sys.argv) - sys.exit(p.return_code) + sys.exit(main(sys.argv))