From 2967b1e0fe462aa234083250107e2e00ad46b923 Mon Sep 17 00:00:00 2001 From: Erez Shinan Date: Fri, 25 Nov 2022 11:02:02 -0300 Subject: [PATCH] Added __version__ and --version switch (issue #318) --- data_diff/__init__.py | 1 + data_diff/__main__.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/data_diff/__init__.py b/data_diff/__init__.py index 8b763527..beff02b9 100644 --- a/data_diff/__init__.py +++ b/data_diff/__init__.py @@ -8,6 +8,7 @@ from .joindiff_tables import JoinDiffer from .table_segment import TableSegment +__version__ = "0.3.0rc4" def connect_to_table( db_info: Union[str, dict], diff --git a/data_diff/__main__.py b/data_diff/__main__.py index ee5eb954..3bfc9250 100644 --- a/data_diff/__main__.py +++ b/data_diff/__main__.py @@ -19,6 +19,7 @@ from .parse_time import parse_time_before_now, UNITS_STR, ParseError from .config import apply_config_from_file from .tracking import disable_tracking +from . import __version__ LOG_FORMAT = "[%(asctime)s] %(levelname)s - %(message)s" @@ -76,7 +77,7 @@ def __init__(self, **kwargs): self.indent_increment = 6 def write_usage(self, prog: str, args: str = "", prefix: Optional[str] = None) -> None: - self.write("data-diff - efficiently diff rows across database tables.\n\n") + self.write(f"data-diff v{__version__} - efficiently diff rows across database tables.\n\n") self.write("Usage:\n") self.write(f" * In-db diff: {prog} [OPTIONS]\n") self.write(f" * Cross-db diff: {prog} [OPTIONS]\n") @@ -140,6 +141,7 @@ def write_usage(self, prog: str, args: str = "", prefix: Optional[str] = None) - @click.option("-d", "--debug", is_flag=True, help="Print debug info") @click.option("--json", "json_output", is_flag=True, help="Print JSONL output for machine readability") @click.option("-v", "--verbose", is_flag=True, help="Print extra info") +@click.option("--version", is_flag=True, help="Print version info and exit") @click.option("-i", "--interactive", is_flag=True, help="Confirm queries, implies --debug") @click.option("--no-tracking", is_flag=True, help="data-diff sends home anonymous usage data. Use this to disable it.") @click.option( @@ -233,6 +235,7 @@ def _main( stats, debug, verbose, + version, interactive, no_tracking, threads, @@ -248,6 +251,9 @@ def _main( threads2=None, __conf__=None, ): + if version: + print(f"v{__version__}") + return if no_tracking: disable_tracking()