add -q parameter to query
This commit is contained in:
parent
d0c7622dc6
commit
c86f25f562
1 changed files with 21 additions and 17 deletions
38
promcli.py
38
promcli.py
|
@ -9,7 +9,7 @@ from tabulate import tabulate
|
|||
from prompt_toolkit import print_formatted_text as print
|
||||
from prompt_toolkit import HTML
|
||||
from prompt_toolkit import prompt
|
||||
from prompt_toolkit.completion import ThreadedCompleter, FuzzyWordCompleter
|
||||
from prompt_toolkit.completion import FuzzyWordCompleter
|
||||
from prompt_toolkit.lexers import PygmentsLexer
|
||||
from prompt_toolkit.styles import style_from_pygments_cls
|
||||
from pygments.lexers.promql import PromQLLexer
|
||||
|
@ -77,24 +77,28 @@ def cli(ctx, user, password, promhost, use_netrc):
|
|||
|
||||
|
||||
@cli.command()
|
||||
@click.option("-q", "--query")
|
||||
@click.pass_context
|
||||
def query(ctx):
|
||||
def query(ctx, query):
|
||||
promclio = ctx.obj['promcli']
|
||||
query = prompt(
|
||||
"query: ",
|
||||
completer=FuzzyWordCompleter(promclio.get_series()),
|
||||
lexer=PygmentsLexer(PromQLLexer),
|
||||
style=style_from_pygments_cls(SolarizedLightStyle),
|
||||
)
|
||||
params = prompt(
|
||||
"{ ",
|
||||
completer=FuzzyWordCompleter(promclio.get_labels(query)),
|
||||
complete_in_thread=True,
|
||||
lexer=PygmentsLexer(PromQLLexer),
|
||||
style=style_from_pygments_cls(SolarizedLightStyle),
|
||||
)
|
||||
print(HTML(f"Querying <lightblue>{query}{{{params}}}</lightblue>"))
|
||||
print(promclio.format_query(promclio.get_query(f"{query}{{{params}}}")))
|
||||
if not query:
|
||||
query = prompt(
|
||||
"query: ",
|
||||
completer=FuzzyWordCompleter(promclio.get_series()),
|
||||
lexer=PygmentsLexer(PromQLLexer),
|
||||
style=style_from_pygments_cls(SolarizedLightStyle),
|
||||
)
|
||||
if '{' not in query:
|
||||
params = prompt(
|
||||
"{ ",
|
||||
completer=FuzzyWordCompleter(promclio.get_labels(query)),
|
||||
complete_in_thread=True,
|
||||
lexer=PygmentsLexer(PromQLLexer),
|
||||
style=style_from_pygments_cls(SolarizedLightStyle),
|
||||
)
|
||||
query = f"{query}{{{params}}}"
|
||||
print(HTML(f"Querying <lightblue>{query}</lightblue>"))
|
||||
print(promclio.format_query(promclio.get_query(f"{query}")))
|
||||
|
||||
|
||||
@cli.command()
|
||||
|
|
Loading…
Reference in a new issue