From 3c073878fa7405c74908531966f39c4871d4a447 Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Sun, 3 Oct 2021 23:39:17 -0700 Subject: [PATCH] Add directives CLI --- hyperglass/cli/main.py | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/hyperglass/cli/main.py b/hyperglass/cli/main.py index 86f19a9..c7cea19 100644 --- a/hyperglass/cli/main.py +++ b/hyperglass/cli/main.py @@ -187,6 +187,55 @@ def _devices( echo._console.print(Columns(panels)) +@cli.command(name="directives") +def _directives( + search: t.Optional[str] = typer.Argument(None, help="Directive 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 + + directives = use_state("directives") + if search is not None: + pattern = re.compile(search, re.IGNORECASE) + for directive in directives: + if pattern.match(directive.id) or pattern.match(directive.name): + echo._console.print( + Inspect( + directive, + title=directive.name, + docs=False, + methods=False, + dunder=False, + sort=True, + all=False, + value=True, + help=False, + ) + ) + raise typer.Exit(0) + + panels = [ + Inspect( + directive, + title=directive.name, + docs=False, + methods=False, + dunder=False, + sort=True, + all=False, + value=True, + help=False, + ) + for directive in directives + ] + echo._console.print(Columns(panels)) + + @cli.command(name="params") def _params( path: t.Optional[str] = typer.Argument(