1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

handle lack of color/emoji support

This commit is contained in:
checktheroads
2020-02-15 12:18:03 -07:00
parent 25aff69cf6
commit ed24ef73be
3 changed files with 20 additions and 7 deletions

View File

@@ -1,4 +1,6 @@
FROM ubuntu:bionic as base
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
RUN apt-get update && apt-get install -y \
git \
curl \
@@ -10,7 +12,8 @@ ENV PATH="$PATH:$HOME/.poetry/bin"
FROM base
WORKDIR ./hyperglass
ENV python=python3
RUN ln -s $(which python3) /usr/bin/python \
RUN bash -c 'BASH_ENV=/etc/profile exec bash' \
&& ln -s $(which python3) /usr/bin/python \
&& python --version \
&& $HOME/.poetry/bin/poetry install --no-ansi \
&& $HOME/.poetry/bin/poetry run hyperglass setup -d

View File

@@ -2,6 +2,7 @@
# Standard Library
import os
import sys
from pathlib import Path
# Third Party
@@ -17,10 +18,13 @@ from hyperglass.cli.formatting import HelpColorsGroup, HelpColorsCommand, random
# Define working directory
WORKING_DIR = Path(__file__).parent
supports_color = "utf" in sys.getfilesystemencoding().lower()
@group(
cls=HelpColorsGroup,
help=CLI_HELP,
context_settings={"color": supports_color},
help_headers_color=LABEL,
help_options_custom_colors=random_colors("build-ui", "start", "secret", "setup"),
)
@@ -29,7 +33,9 @@ def hg():
pass
@hg.command("build-ui", help=cmd_help(E.BUTTERFLY, "Create a new UI build"))
@hg.command(
"build-ui", help=cmd_help(E.BUTTERFLY, "Create a new UI build", supports_color)
)
def build_frontend():
"""Create a new UI build.
@@ -41,7 +47,7 @@ def build_frontend():
@hg.command(
"start",
help=cmd_help(E.ROCKET, "Start web server"),
help=cmd_help(E.ROCKET, "Start web server", supports_color),
cls=HelpColorsCommand,
help_options_custom_colors=random_colors("-b"),
)
@@ -65,7 +71,7 @@ def start(build):
@hg.command(
"secret",
help=cmd_help(E.LOCK, "Generate agent secret"),
help=cmd_help(E.LOCK, "Generate agent secret", supports_color),
cls=HelpColorsCommand,
help_options_custom_colors=random_colors("-l"),
)
@@ -86,7 +92,7 @@ def generate_secret(length):
@hg.command(
"setup",
help=cmd_help(E.TOOLBOX, "Run the setup wizard"),
help=cmd_help(E.TOOLBOX, "Run the setup wizard", supports_color),
cls=HelpColorsCommand,
help_options_custom_colors=random_colors("-d"),
)

View File

@@ -10,9 +10,13 @@ from hyperglass.cli.static import CMD_HELP, Message
from hyperglass.cli.exceptions import CliError
def cmd_help(emoji="", help_text=""):
def cmd_help(emoji="", help_text="", supports_color=False):
"""Print formatted command help."""
return emoji + style(help_text, **CMD_HELP)
if supports_color:
help_str = emoji + style(help_text, **CMD_HELP)
else:
help_str = help_text
return help_str
def _base_formatter(state, text, callback, **kwargs):