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 print_formatted_text as print
|
||||||
from prompt_toolkit import HTML
|
from prompt_toolkit import HTML
|
||||||
from prompt_toolkit import prompt
|
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.lexers import PygmentsLexer
|
||||||
from prompt_toolkit.styles import style_from_pygments_cls
|
from prompt_toolkit.styles import style_from_pygments_cls
|
||||||
from pygments.lexers.promql import PromQLLexer
|
from pygments.lexers.promql import PromQLLexer
|
||||||
|
@ -77,24 +77,28 @@ def cli(ctx, user, password, promhost, use_netrc):
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
@click.option("-q", "--query")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def query(ctx):
|
def query(ctx, query):
|
||||||
promclio = ctx.obj['promcli']
|
promclio = ctx.obj['promcli']
|
||||||
query = prompt(
|
if not query:
|
||||||
"query: ",
|
query = prompt(
|
||||||
completer=FuzzyWordCompleter(promclio.get_series()),
|
"query: ",
|
||||||
lexer=PygmentsLexer(PromQLLexer),
|
completer=FuzzyWordCompleter(promclio.get_series()),
|
||||||
style=style_from_pygments_cls(SolarizedLightStyle),
|
lexer=PygmentsLexer(PromQLLexer),
|
||||||
)
|
style=style_from_pygments_cls(SolarizedLightStyle),
|
||||||
params = prompt(
|
)
|
||||||
"{ ",
|
if '{' not in query:
|
||||||
completer=FuzzyWordCompleter(promclio.get_labels(query)),
|
params = prompt(
|
||||||
complete_in_thread=True,
|
"{ ",
|
||||||
lexer=PygmentsLexer(PromQLLexer),
|
completer=FuzzyWordCompleter(promclio.get_labels(query)),
|
||||||
style=style_from_pygments_cls(SolarizedLightStyle),
|
complete_in_thread=True,
|
||||||
)
|
lexer=PygmentsLexer(PromQLLexer),
|
||||||
print(HTML(f"Querying <lightblue>{query}{{{params}}}</lightblue>"))
|
style=style_from_pygments_cls(SolarizedLightStyle),
|
||||||
print(promclio.format_query(promclio.get_query(f"{query}{{{params}}}")))
|
)
|
||||||
|
query = f"{query}{{{params}}}"
|
||||||
|
print(HTML(f"Querying <lightblue>{query}</lightblue>"))
|
||||||
|
print(promclio.format_query(promclio.get_query(f"{query}")))
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
|
Loading…
Reference in a new issue