diff --git a/obsws_cli/app.py b/obsws_cli/app.py index e6b9483..a7e4ea0 100644 --- a/obsws_cli/app.py +++ b/obsws_cli/app.py @@ -6,6 +6,8 @@ import obsws_python as obsws import typer from rich.console import Console +from obsws_cli.__about__ import __version__ as obsws_cli_version + from . import ( filter, group, @@ -48,6 +50,13 @@ out_console = Console() err_console = Console(stderr=True) +def version_callback(value: bool): + """Show the version of the CLI.""" + if value: + typer.echo(f'obsws_cli version: {obsws_cli_version}') + raise typer.Exit() + + @app.callback() def main( ctx: typer.Context, @@ -68,13 +77,24 @@ def main( int, typer.Option(envvar='OBS_TIMEOUT', help='WebSocket timeout', show_default=5), ] = settings.get('TIMEOUT'), + version: Annotated[ + bool, + typer.Option( + '--version', + '-v', + is_eager=True, + help='Show the CLI version and exit', + show_default=False, + callback=version_callback, + ), + ] = False, ): """obsws_cli is a command line interface for the OBS WebSocket API.""" ctx.obj = ctx.with_resource(obsws.ReqClient(**ctx.params)) @app.command() -def version(ctx: typer.Context): +def obs_version(ctx: typer.Context): """Get the OBS Client and WebSocket versions.""" resp = ctx.obj.get_version() out_console.print( diff --git a/tests/test_version.py b/tests/test_version.py index d068014..f1a35e2 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -8,8 +8,15 @@ runner = CliRunner(mix_stderr=False) def test_version(): - """Test the version command.""" - result = runner.invoke(app, ['version']) + """Test the version option.""" + result = runner.invoke(app, ['--version']) + assert result.exit_code == 0 + assert 'obsws_cli version:' in result.stdout + + +def test_obs_version(): + """Test the obs-version command.""" + result = runner.invoke(app, ['obs-version']) assert result.exit_code == 0 assert 'OBS Client version' in result.stdout assert 'WebSocket version' in result.stdout