diff --git a/news/TEMPLATE.rst b/news/TEMPLATE.rst index 790d30b..67da92d 100644 --- a/news/TEMPLATE.rst +++ b/news/TEMPLATE.rst @@ -16,7 +16,7 @@ **Fixed:** -* +* Updated the existing code to return the version when pytentiostat --version is executed **Security:** diff --git a/news/version-implemented.rst b/news/version-implemented.rst new file mode 100644 index 0000000..98ba0f8 --- /dev/null +++ b/news/version-implemented.rst @@ -0,0 +1,19 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Updated the existing code to return the version when pytentiostat --version is executed diff --git a/scripts/pytentiostat b/scripts/pytentiostat index 8f87228..827fc8f 100644 --- a/scripts/pytentiostat +++ b/scripts/pytentiostat @@ -1,4 +1,37 @@ #!/usr/bin/env python +import argparse +from importlib.metadata import PackageNotFoundError, version + from pytentiostat.main import main main() + + +def print_version(): + """Print the version of the pytentiostat package.""" + try: + pkg_version = version("pytentiostat") + print(f"Pytentiostat version: {pkg_version}") + except PackageNotFoundError: + print("Error: pytentiostat package is not installed.") + + +def main(): + # Set up argument parsing + parser = argparse.ArgumentParser( + description="Pytentiostat Command Line Interface" + ) + parser.add_argument( + "--version", + action="store_true", + help="Show the version of pytentiostat", + ) + + # Parse the arguments + args = parser.parse_args() + + # Check if the version flag is set + if args.version: + print_version() + else: + main()