style input
This commit is contained in:
parent
ac3dc44c56
commit
d0c7622dc6
1 changed files with 21 additions and 6 deletions
27
promcli.py
27
promcli.py
|
@ -2,14 +2,18 @@
|
||||||
|
|
||||||
import netrc
|
import netrc
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from tabulate import tabulate
|
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import requests
|
import requests
|
||||||
|
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 as prompt
|
from prompt_toolkit import prompt
|
||||||
from prompt_toolkit.completion import WordCompleter
|
from prompt_toolkit.completion import ThreadedCompleter, FuzzyWordCompleter
|
||||||
|
from prompt_toolkit.lexers import PygmentsLexer
|
||||||
|
from prompt_toolkit.styles import style_from_pygments_cls
|
||||||
|
from pygments.lexers.promql import PromQLLexer
|
||||||
|
from pygments.styles.solarized import SolarizedLightStyle
|
||||||
|
|
||||||
|
|
||||||
class promcli(object):
|
class promcli(object):
|
||||||
|
@ -76,9 +80,20 @@ def cli(ctx, user, password, promhost, use_netrc):
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def query(ctx):
|
def query(ctx):
|
||||||
promclio = ctx.obj['promcli']
|
promclio = ctx.obj['promcli']
|
||||||
query = prompt("query: ", completer=WordCompleter(promclio.get_series()))
|
query = prompt(
|
||||||
params = prompt("{ ", completer=WordCompleter(promclio.get_labels(query)))
|
"query: ",
|
||||||
print(HTML(f"Querying <blue>{query}{{{params}}}</blue>"))
|
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}}}")))
|
print(promclio.format_query(promclio.get_query(f"{query}{{{params}}}")))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue