File tree Expand file tree Collapse file tree
src/datadog_slo_overrides_cli Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717[ ![ Changelog] ( https://img.shields.io/badge/changelog-Keep%20a%20Changelog%201.1.0-orange )] ( https://keepachangelog.com/en/1.1.0/ )
1818[ ![ Documentation: Diátaxis] ( https://img.shields.io/badge/docs-Di%C3%A1taxis-009485?logo=readthedocs&logoColor=white )] ( https://diataxis.fr/ )
1919[ ![ Build] ( https://img.shields.io/badge/build-unknown-lightgrey )] ( https://github.com/features/actions )
20- [ ![ Coverage] ( https://img.shields.io/badge/coverage-61 %25-orange )] ( https://coverage.readthedocs.io/ )
20+ [ ![ Coverage] ( https://img.shields.io/badge/coverage-62 %25-orange )] ( https://coverage.readthedocs.io/ )
2121[ ![ pyscn quality] ( https://img.shields.io/badge/pyscn-not%20rated-lightgrey )] ( https://pyscn.ludo-tech.org )
2222
2323CLI to set overrides idempotently for multiple SLO's
Original file line number Diff line number Diff line change 2626import tomllib
2727from dataclasses import dataclass
2828from datetime import datetime
29+ from importlib .metadata import PackageNotFoundError
30+ from importlib .metadata import version as package_version
2931from pathlib import Path
3032from zoneinfo import ZoneInfo , ZoneInfoNotFoundError
3133
6971APP_KEY_ENV = 'DD_APP_KEY'
7072
7173APP_NAME = 'datadog-slo-overrides'
74+ PACKAGE_NAME = 'datadog_slo_overrides_cli'
7275
7376
7477def config_dir () -> Path :
@@ -739,6 +742,34 @@ def execute(cfg: RunConfig) -> int:
739742)
740743
741744
745+ def _version_callback (value : bool ) -> None :
746+ """Print the package version and exit when ``--version`` is passed."""
747+ if not value :
748+ return
749+ try :
750+ installed = package_version (PACKAGE_NAME )
751+ except PackageNotFoundError :
752+ installed = 'unknown'
753+ typer .echo (f'{ APP_NAME } { installed } ' )
754+ raise typer .Exit
755+
756+
757+ @app .callback ()
758+ def _root (
759+ _version : bool = typer .Option (
760+ False ,
761+ '--version' ,
762+ callback = _version_callback ,
763+ is_eager = True ,
764+ help = 'Show the version and exit.' ,
765+ ),
766+ ) -> None :
767+ """Set Datadog SLO corrections on multiple SLOs, selected by tag.
768+
769+ Dry-run by default; --apply to write. See README.md.
770+ """
771+
772+
742773@app .command (no_args_is_help = True )
743774def run (
744775 tag : list [str ] = typer .Option (
Original file line number Diff line number Diff line change @@ -190,6 +190,13 @@ def test_init_config_writes_template_and_guards_overwrite(tmp_path: Path) -> Non
190190 assert second .exit_code != 0
191191
192192
193+ def test_version_option () -> None :
194+ """--version prints the app name and version, then exits 0."""
195+ result = runner .invoke (app , ['--version' ])
196+ assert result .exit_code == 0
197+ assert 'datadog-slo-overrides' in result .output
198+
199+
193200def test_load_direnv_env_success (tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> None :
194201 """A successful ``direnv export json`` is parsed into the exported variables."""
195202 (tmp_path / '.envrc' ).write_text ('export DD_API_KEY=k\n ' )
You can’t perform that action at this time.
0 commit comments