Skip to content

Commit

Permalink
Add option to accept default install/data paths
Browse files Browse the repository at this point in the history
Also made it more clear that the path in brackets for path prompts is
the default path.
  • Loading branch information
velovix committed Jul 7, 2020
1 parent bcc6974 commit 28e7272
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
16 changes: 16 additions & 0 deletions brainframe/cli/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,23 @@ def install():
os_utils.add_to_group("docker")
added_to_any_group = True

use_default_paths = False
if not args.noninteractive:
# Ask the user if they want to specify special paths for installation
print_utils.translate(
"install.default-paths",
default_install_path=env_vars.install_path.default,
default_data_path=env_vars.data_path.default,
)
use_default_paths = print_utils.ask_yes_no(
"install.ask-use-default-paths",
)

# Set up the install path
if args.noninteractive:
install_path = args.install_path
elif use_default_paths:
install_path = env_vars.install_path.default
else:
install_path = print_utils.ask_path(
"install.ask-brainframe-install-path",
Expand All @@ -63,6 +77,8 @@ def install():
# Set up the data path
if args.noninteractive:
data_path = args.data_path
elif use_default_paths:
data_path = env_vars.data_path.default
else:
data_path = print_utils.ask_path(
"install.ask-data-path", env_vars.data_path.default
Expand Down
9 changes: 5 additions & 4 deletions brainframe/cli/print_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ class Color(Enum):
UNDERLINE = "\033[4m"


def ask_yes_no(message_id) -> bool:
def ask_yes_no(message_id, **kwargs) -> bool:
"""Prompts the user with a yes or no question. The default value is yes.
:param message_id: The ID of the question to print
:return: The user's choice
"""
while True:
choice = input_color(f"{i18n.t(message_id)} [Y/n] ", Color.BLUE)
question = i18n.t(message_id, **kwargs)
choice = input_color(f"{question} [Y/n] ", Color.BLUE)
choice = choice.strip().lower()
if choice not in ["y", "n", ""]:
translate("general.invalid-yes-no-input")
Expand All @@ -39,7 +40,7 @@ def ask_yes_no(message_id) -> bool:

def ask_path(message_id, default: Path) -> Path:
message = i18n.t(message_id) + "\n"
message += f"[{default}] "
message += f"[{i18n.t('general.default')}: {default}] "
choice = input_color(message, Color.BLUE)

print()
Expand All @@ -59,7 +60,7 @@ def translate(message_id, color=Color.END, **kwargs):


def warning_translate(message_id, color=Color.YELLOW, **kwargs):
print_color(i18n.t(message_id), color, **kwargs)
print_color(i18n.t(message_id, **kwargs), color)


def fail_translate(message_id, **kwargs):
Expand Down
5 changes: 5 additions & 0 deletions brainframe/cli/translations/install.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ en:
install-dependency-manually: "Please install %{dependency} and try again"
docker-compose-download-error: "Error while downloading the
docker-compose.yml file: {error}"
default-paths: "By default, the BrainFrame docker-compose.yml will be
installed to %{default_install_path} and data will be saved to
%{default_data_path}."
ask-use-default-paths: "Would you like to install BrainFrame to the default
locations?"
ask-brainframe-install-path: "What path should BrainFrame install the
docker-compose.yml to?"
ask-data-path: "What path should BrainFrame write data to?"
Expand Down

0 comments on commit 28e7272

Please sign in to comment.