Add service enable/disable helper

This commit is contained in:
up-n-atom
2023-12-30 04:23:09 -05:00
committed by GitHub
parent e67a4db6da
commit 461133a178
2 changed files with 14 additions and 6 deletions
+11 -1
View File
@@ -60,7 +60,6 @@ async def get_value(ctx: click.Context, path: list[str]) -> None:
except Exception as e:
click.echo(e, err=True)
continue
#raise click.Abort()
else:
click.echo(json.dumps(value, indent=2))
@@ -78,3 +77,14 @@ async def set_value(ctx: click.Context, path: str, value: str) -> None:
click.echo(e, err=True)
raise click.Abort()
@asynccontextmanager
async def flipflop(xpath: str) -> None:
if (client := click.get_current_context().find_object(SagemcomClient)) is None:
raise ValueError('client not found')
await client.set_value_by_xpath(xpath, False)
try:
yield client
finally:
await client.set_value_by_xpath(xpath, True)