Skip to content

Commit 45b9fc8

Browse files
committed
Allow tools to report it's version
Fixes #10 Signed-off-by: Pedro Algarvio <[email protected]>
1 parent cb41a1f commit 45b9fc8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

changelog/10.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow `tools` to report it's version

src/ptscripts/parser.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
from ptscripts import logs
2929
from ptscripts import process
3030

31+
try:
32+
import importlib.metadata
33+
34+
__version__ = importlib.metadata.version("python-tools-scripts")
35+
except ImportError:
36+
import importlib_metadata
37+
38+
__version__ = importlib_metadata.version("python-tools-scripts")
39+
3140
if TYPE_CHECKING:
3241
from argparse import ArgumentParser
3342
from argparse import _SubParsersAction
@@ -192,6 +201,7 @@ def __new__(cls):
192201
epilog="These tools are discovered under `<repo-root>/tools`.",
193202
allow_abbrev=False,
194203
)
204+
instance.parser.add_argument("--version", action="version", version=__version__)
195205
log_group = instance.parser.add_argument_group("Logging")
196206
timestamp_meg = log_group.add_mutually_exclusive_group()
197207
timestamp_meg.add_argument(

0 commit comments

Comments
 (0)