1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-01-17 08:48:05 +00:00

Add devices CLI

This commit is contained in:
thatmattlove 2021-10-03 23:15:32 -07:00
parent 2589c5fa06
commit 5e1f96448e

View file

@ -1,6 +1,7 @@
"""hyperglass Command Line Interface."""
# Standard Library
import re
import sys
import typing as t
@ -128,6 +129,55 @@ def clear_cache():
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()
def setup():
"""Initialize hyperglass setup."""