Skip to content

Commit

Permalink
feat: Add -V, --version CLI flag to show version
Browse files Browse the repository at this point in the history
Issue #186: #186
PR #187: #187
Co-authored-by: Timothée Mazzucotelli <[email protected]>
  • Loading branch information
jgarte authored Aug 4, 2023
1 parent 0ffedf9 commit a41515f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/griffe/c3linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def head(self) -> T | None:

@property
def tail(self) -> islice:
"""Tail od the dependency.
"""Tail of the dependency.
The `islice` object is sufficient for iteration or testing membership (`in`).
"""
Expand Down
10 changes: 10 additions & 0 deletions src/griffe/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import os
import sys
from datetime import datetime, timezone
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as get_dist_version
from pathlib import Path
from typing import IO, TYPE_CHECKING, Any, Callable, Sequence

Expand All @@ -42,6 +44,13 @@
logger = get_logger(__name__)


def _get_griffe_version() -> str:
try:
return get_dist_version("griffe")
except PackageNotFoundError:
return "0.0.0"


def _print_data(data: str, output_file: str | IO | None) -> None:
if isinstance(output_file, str):
with open(output_file, "w") as fd:
Expand Down Expand Up @@ -122,6 +131,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 " + _get_griffe_version())

def add_common_options(subparser: argparse.ArgumentParser) -> None:
common_options = subparser.add_argument_group(title="Common options")
Expand Down
2 changes: 1 addition & 1 deletion src/griffe/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def as_json(self, *, full: bool = False, **kwargs: Any) -> str:
**kwargs: Additional serialization options passed to encoder.
Returns:
A string.
A JSON string.
"""
from griffe.encoders import JSONEncoder # avoid circular import

Expand Down

0 comments on commit a41515f

Please sign in to comment.