remove --debug flag, replace it with --loglevel

This commit is contained in:
onyx-and-iris 2026-02-07 08:32:17 +00:00
parent 45479563a0
commit 13a2443d48
2 changed files with 15 additions and 12 deletions

View File

@ -28,11 +28,15 @@ def version_callback(value: bool):
raise typer.Exit() raise typer.Exit()
def setup_logging(debug: bool): def setup_logging(loglevel: str):
"""Set up logging for the application.""" """Set up logging for the application."""
log_level = logging.DEBUG if debug else logging.CRITICAL loglevel = loglevel.upper()
if loglevel not in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
raise typer.BadParameter(
f'Invalid log level: {loglevel}. Choose from DEBUG, INFO, WARNING, ERROR, CRITICAL.'
)
logging.basicConfig( logging.basicConfig(
level=log_level, level=loglevel,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
) )
@ -121,19 +125,18 @@ def main(
callback=version_callback, callback=version_callback,
), ),
] = False, ] = False,
debug: Annotated[ loglevel: Annotated[
bool, str,
typer.Option( typer.Option(
'--debug', '--loglevel',
'-d', '-l',
envvar='OBSWS_CLI_DEBUG', envvar='OBSWS_CLI_LOGLEVEL',
is_eager=True, is_eager=True,
help='Enable debug logging', help='Set the logging level',
show_default=False, show_default=False,
callback=setup_logging, callback=setup_logging,
hidden=True,
), ),
] = envconfig.get('debug'), ] = envconfig.get('loglevel'),
): ):
"""obsws_cli is a command line interface for the OBS WebSocket API.""" """obsws_cli is a command line interface for the OBS WebSocket API."""
ctx.ensure_object(dict) ctx.ensure_object(dict)

View File

@ -124,7 +124,7 @@ _envconfig = EnvConfig(
OBSWS_CLI_PORT=4455, OBSWS_CLI_PORT=4455,
OBSWS_CLI_PASSWORD='', OBSWS_CLI_PASSWORD='',
OBSWS_CLI_TIMEOUT=5, OBSWS_CLI_TIMEOUT=5,
OBSWS_CLI_DEBUG=False, OBSWS_CLI_LOGLEVEL='WARNING',
OBSWS_CLI_STYLE='disabled', OBSWS_CLI_STYLE='disabled',
OBSWS_CLI_STYLE_NO_BORDER=False, OBSWS_CLI_STYLE_NO_BORDER=False,
) )