forked from mirrors/thatmattlove-hyperglass
Add devices CLI
This commit is contained in:
parent
2589c5fa06
commit
5e1f96448e
1 changed files with 50 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
"""hyperglass Command Line Interface."""
|
"""hyperglass Command Line Interface."""
|
||||||
|
|
||||||
# Standard Library
|
# Standard Library
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import typing as t
|
import typing as t
|
||||||
|
|
||||||
|
|
@ -128,6 +129,55 @@ def clear_cache():
|
||||||
raise typer.Exit(1)
|
raise typer.Exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
def devices(
|
||||||
|
search: t.Optional[str] = typer.Argument(None, help="Device ID or Name Search Pattern")
|
||||||
|
):
|
||||||
|
"""Show all configured devices"""
|
||||||
|
# Third Party
|
||||||
|
from rich.columns import Columns
|
||||||
|
from rich._inspect import Inspect
|
||||||
|
|
||||||
|
# Project
|
||||||
|
from hyperglass.state import use_state
|
||||||
|
|
||||||
|
devices = use_state("devices")
|
||||||
|
if search is not None:
|
||||||
|
pattern = re.compile(search, re.IGNORECASE)
|
||||||
|
for device in devices:
|
||||||
|
if pattern.match(device.id) or pattern.match(device.name):
|
||||||
|
echo._console.print(
|
||||||
|
Inspect(
|
||||||
|
device,
|
||||||
|
title=device.name,
|
||||||
|
docs=False,
|
||||||
|
methods=False,
|
||||||
|
dunder=False,
|
||||||
|
sort=True,
|
||||||
|
all=False,
|
||||||
|
value=True,
|
||||||
|
help=False,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
raise typer.Exit(0)
|
||||||
|
|
||||||
|
panels = [
|
||||||
|
Inspect(
|
||||||
|
device,
|
||||||
|
title=device.name,
|
||||||
|
docs=False,
|
||||||
|
methods=False,
|
||||||
|
dunder=False,
|
||||||
|
sort=True,
|
||||||
|
all=False,
|
||||||
|
value=True,
|
||||||
|
help=False,
|
||||||
|
)
|
||||||
|
for device in devices
|
||||||
|
]
|
||||||
|
echo._console.print(Columns(panels))
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
def setup():
|
def setup():
|
||||||
"""Initialize hyperglass setup."""
|
"""Initialize hyperglass setup."""
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue