Added python and macOS versions to --version (#1008)

This commit is contained in:
Rhet Turnbull 2023-02-28 06:43:06 -08:00 committed by GitHub
parent 56ca54ad0d
commit a08680ed02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 6 deletions

View File

@ -14,7 +14,7 @@ from .about import about
from .add_locations import add_locations
from .albums import albums
from .batch_edit import batch_edit
from .cli_params import DB_OPTION, DEBUG_OPTIONS, JSON_OPTION
from .cli_params import DB_OPTION, DEBUG_OPTIONS, JSON_OPTION, VERSION_OPTION
from .common import OSXPHOTOS_HIDDEN
from .debug_dump import debug_dump
from .docs import docs_command
@ -58,7 +58,7 @@ CTX_SETTINGS = dict(help_option_names=["-h", "--help"])
@click.group(context_settings=CTX_SETTINGS)
@click.version_option(__version__, "--version", "-v")
@VERSION_OPTION
@DB_OPTION
@JSON_OPTION
@DEBUG_OPTIONS

View File

@ -7,7 +7,7 @@ from typing import Any, Callable
import click
from .common import OSXPHOTOS_HIDDEN
from .common import OSXPHOTOS_HIDDEN, print_version
from .param_types import *
__all__ = [
@ -19,8 +19,9 @@ __all__ = [
"JSON_OPTION",
"QUERY_OPTIONS",
"THEME_OPTION",
"VERBOSE_OPTION",
"TIMESTAMP_OPTION",
"VERBOSE_OPTION",
"VERSION_OPTION",
]
@ -676,3 +677,12 @@ _TIMESTAMP_PARAMETER = click.Option(
["--timestamp"], is_flag=True, help="Add time stamp to verbose output"
)
TIMESTAMP_OPTION = make_click_option_decorator(_TIMESTAMP_PARAMETER)
_VERSION_PARAMETER = click.Option(
["--version", "-v", "_version_flag"],
is_flag=True,
help="Show the version and exit.",
callback=print_version,
)
VERSION_OPTION = make_click_option_decorator(_VERSION_PARAMETER)

View File

@ -4,6 +4,8 @@ from __future__ import annotations
import os
import pathlib
import platform
import sys
from datetime import datetime
import click
@ -13,7 +15,7 @@ from xdg import xdg_config_home, xdg_data_home
import osxphotos
from osxphotos._constants import APP_NAME
from osxphotos._version import __version__
from osxphotos.utils import get_latest_version
from osxphotos.utils import get_latest_version, get_macos_version
# used to show/hide hidden commands
OSXPHOTOS_HIDDEN = not bool(os.getenv("OSXPHOTOS_SHOW_HIDDEN", default=False))
@ -106,3 +108,13 @@ def check_version():
"to suppress this message and prevent osxphotos from checking for latest version.",
err=True,
)
def print_version(ctx, param, value):
"""Print version, this is a callback for the --version option"""
if not value:
return
click.echo(f"osxphotos, version {__version__}")
click.echo(f"Python {sys.version}")
click.echo(f"macOS {'.'.join(get_macos_version())}, {platform.machine()}")
ctx.exit()

View File

@ -31,10 +31,11 @@ __all__ = [
"dd_to_dms_str",
"expand_and_validate_filepath",
"get_last_library_path",
"get_macos_version",
"get_system_library_path",
"hexdigest",
"increment_filename",
"increment_filename_with_count",
"increment_filename",
"lineno",
"list_directory",
"list_photo_libraries",