From ac53cea3590708ea733df95076fa1aea0977d055 Mon Sep 17 00:00:00 2001 From: jgart Date: Tue, 25 Jul 2023 18:27:59 -0500 Subject: [PATCH] feat: Add `--version` and `-V` cli flag Issue #: https://github.com/mkdocstrings/griffe/issues/186 PR #174: https://github.com/mkdocstrings/griffe/pull/187 --- src/griffe/cli.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/griffe/cli.py b/src/griffe/cli.py index bb195408..3dce3b0e 100644 --- a/src/griffe/cli.py +++ b/src/griffe/cli.py @@ -19,6 +19,7 @@ import os import sys from datetime import datetime, timezone +from importlib.metadata import version as get_version from pathlib import Path from typing import IO, TYPE_CHECKING, Any, Callable, Sequence @@ -34,6 +35,8 @@ from griffe.logger import get_logger from griffe.stats import _format_stats +version = get_version("griffe") + if TYPE_CHECKING: from griffe.extensions import Extensions, ExtensionType @@ -122,6 +125,7 @@ def get_parser() -> argparse.ArgumentParser: global_options = parser.add_argument_group(title="Global options") global_options.add_argument("-h", "--help", action="help", help=main_help) + global_options.add_argument("-V", "--version", action="version", version="%(prog)s " + version) def add_common_options(subparser: argparse.ArgumentParser) -> None: common_options = subparser.add_argument_group(title="Common options")