print list as rich table

swap out typer.echo for rich consoles

add filter status command

add util function

minor bump
This commit is contained in:
onyx-and-iris 2025-05-23 21:29:18 +01:00
parent eaa66f0bd5
commit 37dbbdf4e2
5 changed files with 70 additions and 16 deletions

View File

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# [0.12.0] - 2025-05-23
### Added
- filter commands, see [Filter](https://github.com/onyx-and-iris/obsws-cli?tab=readme-ov-file#filter)
# [0.11.0] - 2025-05-22
### Added

View File

@ -516,6 +516,13 @@ obsws-cli filter disable "Mic/Aux" "Test Compression Filter"
obsws-cli filter toggle "Mic/Aux" "Test Compression Filter"
```
- status: Get the status of a filter for a source.
- args: <source_name> <filter_name>
```console
obsws-cli filter status "Mic/Aux" "Test Compression Filter"
```
## License
`obsws-cli` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.

View File

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
#
# SPDX-License-Identifier: MIT
__version__ = "0.11.0"
__version__ = "0.12.0"

View File

@ -1,10 +1,15 @@
"""module containing commands for manipulating filters in scenes."""
import typer
from rich.console import Console
from rich.table import Table
from . import util
from .alias import AliasGroup
app = typer.Typer(cls=AliasGroup)
out_console = Console()
err_console = Console(stderr=True)
@app.callback()
@ -18,14 +23,28 @@ def list(ctx: typer.Context, source_name: str):
resp = ctx.obj.get_source_filter_list(source_name)
if not resp.filters:
typer.echo(f'No filters found for source {source_name}')
out_console.print(f'No filters found for source {source_name}')
return
table = Table(title=f'Filters for Source: {source_name}')
for column in ('Name', 'Kind', 'Enabled', 'Settings'):
table.add_column(column, justify='center', style='cyan')
for filter in resp.filters:
typer.echo(f'Filter: {filter["filterName"]}')
for key, value in filter.items():
if key != 'filterName':
typer.echo(f' {key}: {value}')
table.add_row(
filter['filterName'],
util.snakecase_to_titlecase(filter['filterKind']),
':heavy_check_mark:' if filter['filterEnabled'] else ':x:',
'\n'.join(
[
f'{util.snakecase_to_titlecase(k):<20} {v:>10}'
for k, v in filter['filterSettings'].items()
]
),
)
out_console.print(table)
def _get_filter_enabled(ctx: typer.Context, source_name: str, filter_name: str):
@ -42,14 +61,13 @@ def enable(
):
"""Enable a filter for a source."""
if _get_filter_enabled(ctx, source_name, filter_name):
typer.echo(
f'Filter {filter_name} is already enabled for source {source_name}',
err=True,
err_console.print(
f'Filter {filter_name} is already enabled for source {source_name}'
)
raise typer.Exit(1)
ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=True)
typer.echo(f'Enabled filter {filter_name} for source {source_name}')
out_console.print(f'Enabled filter {filter_name} for source {source_name}')
@app.command('disable | off')
@ -60,14 +78,13 @@ def disable(
):
"""Disable a filter for a source."""
if not _get_filter_enabled(ctx, source_name, filter_name):
typer.echo(
f'Filter {filter_name} is already disabled for source {source_name}',
err=True,
err_console.print(
f'Filter {filter_name} is already disabled for source {source_name}'
)
raise typer.Exit(1)
ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=False)
typer.echo(f'Disabled filter {filter_name} for source {source_name}')
out_console.print(f'Disabled filter {filter_name} for source {source_name}')
@app.command('toggle | tg')
@ -82,6 +99,24 @@ def toggle(
ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=new_state)
if new_state:
typer.echo(f'Enabled filter {filter_name} for source {source_name}')
out_console.print(f'Enabled filter {filter_name} for source {source_name}')
else:
typer.echo(f'Disabled filter {filter_name} for source {source_name}')
out_console.print(f'Disabled filter {filter_name} for source {source_name}')
@app.command('status | ss')
def status(
ctx: typer.Context,
source_name: str = typer.Argument(
..., help='The source to get the filter status for'
),
filter_name: str = typer.Argument(
..., help='The name of the filter to get the status for'
),
):
"""Get the status of a filter for a source."""
is_enabled = _get_filter_enabled(ctx, source_name, filter_name)
if is_enabled:
out_console.print(f'Filter {filter_name} is enabled for source {source_name}')
else:
out_console.print(f'Filter {filter_name} is disabled for source {source_name}')

6
obsws_cli/util.py Normal file
View File

@ -0,0 +1,6 @@
"""module contains utility functions for the obsws_cli package."""
def snakecase_to_titlecase(snake_str):
"""Convert a snake_case string to a title case string."""
return snake_str.replace('_', ' ').title()