Skip to content

Commit 4ea8da6

Browse files
author
Prabhakar Kumar
committed
Introducing -v or --version command line argument to print version and exit.
1 parent 1e2e57e commit 4ea8da6

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

matlab_proxy/app.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -846,15 +846,9 @@ def create_app(config_name=matlab_proxy.get_default_config_name()):
846846
return app
847847

848848

849-
def main():
850-
"""Starting point of the integration. Creates the web app and runs indefinitely."""
851-
852-
# The integration needs to be called with --config flag.
853-
# Parse the passed cli arguments.
854-
desired_configuration_name = util.parse_cli_args()["config"]
855-
849+
def create_and_start_app(config_name):
856850
# Create, configure and start the app.
857-
app = create_app(config_name=desired_configuration_name)
851+
app = create_app(config_name)
858852
app = configure_and_start(app)
859853

860854
loop = util.get_event_loop()
@@ -884,3 +878,25 @@ async def shutdown():
884878
logger.info("Finished shutting down. Thank you for using the MATLAB proxy.")
885879
loop.close()
886880
sys.exit(0)
881+
882+
883+
def print_version_and_exit():
884+
"""prints the version of the package and exits"""
885+
from importlib.metadata import version
886+
887+
matlab_proxy_version = version("matlab-proxy")
888+
print(f"{matlab_proxy_version}")
889+
sys.exit(0)
890+
891+
892+
def main():
893+
"""Starting point of the integration. Creates the web app and runs indefinitely."""
894+
895+
if util.parse_cli_args()["version"]:
896+
print_version_and_exit()
897+
898+
# The integration needs to be called with --config flag.
899+
# Parse the passed cli arguments.
900+
desired_configuration_name = util.parse_cli_args()["config"]
901+
902+
create_and_start_app(config_name=desired_configuration_name)

matlab_proxy/util/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Copyright (c) 2020-2023 The MathWorks, Inc.
1+
# Copyright 2020-2024 The MathWorks, Inc.
2+
23
import argparse
34
import os
45
import socket
@@ -30,9 +31,18 @@ def parse_cli_args():
3031
help="A json file which stores the config specific to the environment.",
3132
default=matlab_proxy.get_default_config_name(),
3233
)
34+
35+
parser.add_argument(
36+
"-v",
37+
"--version",
38+
help="prints the version of matlab-proxy.",
39+
action="store_true",
40+
)
41+
3342
args = parser.parse_args()
3443

3544
parsed_args["config"] = args.config
45+
parsed_args["version"] = args.version
3646

3747
return parsed_args
3848

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020-2023 The MathWorks, Inc.
1+
# Copyright 2020-2024 The MathWorks, Inc.
22
import os
33
from pathlib import Path
44
from shutil import which

0 commit comments

Comments
 (0)