From 646fcdadbfc03c8ab3c0720ef1e656786345f258 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 7 Jun 2022 23:22:04 +1000 Subject: [PATCH] tools/mpremote: Add command to print the version. Signed-off-by: Damien George --- tools/mpremote/LICENSE | 2 +- tools/mpremote/mpremote/__init__.py | 2 +- tools/mpremote/mpremote/main.py | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/mpremote/LICENSE b/tools/mpremote/LICENSE index 5ec904cca1..a9ea6c27ef 100644 --- a/tools/mpremote/LICENSE +++ b/tools/mpremote/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2021 Damien P. George +Copyright (c) 2021-2022 Damien P. George Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/tools/mpremote/mpremote/__init__.py b/tools/mpremote/mpremote/__init__.py index 1bb8bf6d7f..d3ec452c31 100644 --- a/tools/mpremote/mpremote/__init__.py +++ b/tools/mpremote/mpremote/__init__.py @@ -1 +1 @@ -# empty +__version__ = "0.2.0" diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index ccf174bb5b..4d74743aa3 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -1,6 +1,6 @@ """ MicroPython Remote - Interaction and automation tool for MicroPython -MIT license; Copyright (c) 2019-2021 Damien P. George +MIT license; Copyright (c) 2019-2022 Damien P. George This program provides a set of utilities to interact with and automate a MicroPython device over a serial connection. Commands supported are: @@ -68,6 +68,7 @@ _COMMANDS = { "run": (True, True, 1, "run the given local script"), "fs": (True, True, 1, "execute filesystem commands on the device"), "help": (False, False, 0, "print help and exit"), + "version": (False, False, 0, "print version and exit"), } _BUILTIN_COMMAND_EXPANSIONS = { @@ -109,6 +110,7 @@ _BUILTIN_COMMAND_EXPANSIONS = { "import machine; machine.RTC().datetime((2020, 1, 1, 0, 10, 0, 0, 0))", ], "--help": "help", + "--version": "version", } for port_num in range(4): @@ -465,6 +467,12 @@ def print_help(): print_commands_help(_command_expansions, 2) +def print_version(): + from . import __version__ + + print(f"{_PROG} {__version__}") + + def main(): config = load_user_config() prepare_command_expansions(config) @@ -498,6 +506,9 @@ def main(): elif cmd == "help": print_help() sys.exit(0) + elif cmd == "version": + print_version() + sys.exit(0) elif cmd == "resume": auto_soft_reset = False continue