mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-06-07 20:20:32 +01:00
add version_callback
rename version command to obs-version upd version unit test
This commit is contained in:
parent
370c82f393
commit
ec444d9cdd
@ -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(
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user