mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-08-05 11:31:44 +00:00
convert text commands
This commit is contained in:
parent
eb939b735c
commit
506aff833c
@ -37,6 +37,7 @@ for sub_app in (
|
|||||||
'screenshot',
|
'screenshot',
|
||||||
'stream',
|
'stream',
|
||||||
'studiomode',
|
'studiomode',
|
||||||
|
'text',
|
||||||
):
|
):
|
||||||
module = importlib.import_module(f'.{sub_app}', package=__package__)
|
module = importlib.import_module(f'.{sub_app}', package=__package__)
|
||||||
app.command(module.app)
|
app.command(module.app)
|
||||||
|
@ -2,35 +2,34 @@
|
|||||||
|
|
||||||
from typing import Annotated, Optional
|
from typing import Annotated, Optional
|
||||||
|
|
||||||
import typer
|
from cyclopts import App, Argument, Parameter
|
||||||
|
|
||||||
from . import console, validate
|
from . import console, validate
|
||||||
from .alias import SubTyperAliasGroup
|
from .context import Context
|
||||||
|
from .enum import ExitCode
|
||||||
|
from .error import OBSWSCLIError
|
||||||
|
|
||||||
app = typer.Typer(cls=SubTyperAliasGroup)
|
app = App(name='text', help='Commands for controlling text inputs in OBS.')
|
||||||
|
|
||||||
|
|
||||||
@app.callback()
|
@app.command(name=['current', 'get'])
|
||||||
def main():
|
|
||||||
"""Control text inputs in OBS."""
|
|
||||||
|
|
||||||
|
|
||||||
@app.command('current | get')
|
|
||||||
def current(
|
def current(
|
||||||
ctx: typer.Context,
|
input_name: Annotated[str, Argument(hint='Name of the text input to get.')],
|
||||||
input_name: Annotated[str, typer.Argument(help='Name of the text input to get.')],
|
*,
|
||||||
|
ctx: Annotated[Context, Parameter(parse=False)],
|
||||||
):
|
):
|
||||||
"""Get the current text for a text input."""
|
"""Get the current text for a text input."""
|
||||||
if not validate.input_in_inputs(ctx, input_name):
|
if not validate.input_in_inputs(ctx, input_name):
|
||||||
console.err.print(f'Input [yellow]{input_name}[/yellow] not found.')
|
raise OBSWSCLIError(
|
||||||
raise typer.Exit(1)
|
f'Input [yellow]{input_name}[/yellow] not found.', code=ExitCode.ERROR
|
||||||
|
)
|
||||||
resp = ctx.obj['obsws'].get_input_settings(name=input_name)
|
|
||||||
if not resp.input_kind.startswith('text_'):
|
resp = ctx.client.get_input_settings(name=input_name)
|
||||||
console.err.print(
|
if not resp.input_kind.startswith('text_'):
|
||||||
f'Input [yellow]{input_name}[/yellow] is not a text input.',
|
raise OBSWSCLIError(
|
||||||
|
f'Input [yellow]{input_name}[/yellow] is not a text input.',
|
||||||
|
code=ExitCode.ERROR,
|
||||||
)
|
)
|
||||||
raise typer.Exit(1)
|
|
||||||
|
|
||||||
current_text = resp.input_settings.get('text', '')
|
current_text = resp.input_settings.get('text', '')
|
||||||
if not current_text:
|
if not current_text:
|
||||||
@ -40,32 +39,31 @@ def current(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.command('update | set')
|
@app.command(name=['update', 'set'])
|
||||||
def update(
|
def update(
|
||||||
ctx: typer.Context,
|
input_name: Annotated[str, Argument(hint='Name of the text input to update.')],
|
||||||
input_name: Annotated[
|
|
||||||
str, typer.Argument(help='Name of the text input to update.')
|
|
||||||
],
|
|
||||||
new_text: Annotated[
|
new_text: Annotated[
|
||||||
Optional[str],
|
Optional[str],
|
||||||
typer.Argument(
|
Argument(hint='The new text to set for the input.'),
|
||||||
help='The new text to set for the input.',
|
|
||||||
),
|
|
||||||
] = None,
|
] = None,
|
||||||
|
/,
|
||||||
|
*,
|
||||||
|
ctx: Annotated[Context, Parameter(parse=False)],
|
||||||
):
|
):
|
||||||
"""Update the text of a text input."""
|
"""Update the text of a text input."""
|
||||||
if not validate.input_in_inputs(ctx, input_name):
|
if not validate.input_in_inputs(ctx, input_name):
|
||||||
console.err.print(f'Input [yellow]{input_name}[/yellow] not found.')
|
raise OBSWSCLIError(
|
||||||
raise typer.Exit(1)
|
f'Input [yellow]{input_name}[/yellow] not found.', code=ExitCode.ERROR
|
||||||
|
|
||||||
resp = ctx.obj['obsws'].get_input_settings(name=input_name)
|
|
||||||
if not resp.input_kind.startswith('text_'):
|
|
||||||
console.err.print(
|
|
||||||
f'Input [yellow]{input_name}[/yellow] is not a text input.',
|
|
||||||
)
|
)
|
||||||
raise typer.Exit(1)
|
|
||||||
|
|
||||||
ctx.obj['obsws'].set_input_settings(
|
resp = ctx.client.get_input_settings(name=input_name)
|
||||||
|
if not resp.input_kind.startswith('text_'):
|
||||||
|
raise OBSWSCLIError(
|
||||||
|
f'Input [yellow]{input_name}[/yellow] is not a text input.',
|
||||||
|
code=ExitCode.ERROR,
|
||||||
|
)
|
||||||
|
|
||||||
|
ctx.client.set_input_settings(
|
||||||
name=input_name,
|
name=input_name,
|
||||||
settings={'text': new_text},
|
settings={'text': new_text},
|
||||||
overlay=True,
|
overlay=True,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user