From 0d1db1fc657bb8e596c8d3d82c19a8c0afe029eb Mon Sep 17 00:00:00 2001 From: enriquezgarc Date: Wed, 22 Nov 2023 15:11:09 +0100 Subject: [PATCH] tools/psoc6/mpy-psoc6.py: Added script version. Signed-off-by: enriquezgarc --- tools/psoc6/mpy-psoc6.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/psoc6/mpy-psoc6.py b/tools/psoc6/mpy-psoc6.py index bdf11a0568fa4..82978887ce4b6 100644 --- a/tools/psoc6/mpy-psoc6.py +++ b/tools/psoc6/mpy-psoc6.py @@ -6,6 +6,7 @@ ] opsys = "" +version = "0.1.0" def colour_str_success(msg): @@ -32,7 +33,7 @@ def set_environment(): opsys = "linux" elif sys.platform == "win32" or sys.platform == "cygwin": opsys = "win" - os.system('color') + os.system("color") # Enable colouring in cmd and powershell elif sys.platform == "darwin": opsys = "mac" raise Exception(colour_str_error("OS unsupported")) @@ -348,7 +349,7 @@ def device_setup(board, version, update_dbg_fw=False, quiet=False): if not quiet: wait_and_request_board_connect() - + if update_dbg_fw: fwloader_download_install() fwloader_update_kitprog() @@ -495,6 +496,16 @@ def parser_device_erase(args): device_erase(args.board, args.q) # Main parser + class ver_action(argparse.Action): + def __init__(self, option_strings, dest, **kwargs): + return super().__init__( + option_strings, dest, nargs=0, default=argparse.SUPPRESS, **kwargs + ) + + def __call__(self, parser, namespace, values, option_string, **kwargs): + print("mpy-psoc6 version: " + version) + parser.exit() + main_parser_desc = """ Micropython PSoC6 utility script @@ -510,6 +521,7 @@ def parser_device_erase(args): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter, description=main_parser_desc ) + parser.add_argument("-v", "--version", action=ver_action, help="mpy-psoc6 version") subparser = parser.add_subparsers() parser.set_defaults(func=main_parser_func)