Skip to content

Commit

Permalink
Merge pull request #487 from axif0/testinginter
Browse files Browse the repository at this point in the history
feat enhancement Interactive UI language & data-type
  • Loading branch information
andrewtavis authored Oct 26, 2024
2 parents a487a18 + fa02437 commit 6bf37ca
Showing 1 changed file with 59 additions and 58 deletions.
117 changes: 59 additions & 58 deletions src/scribe_data/cli/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import logging
from pathlib import Path
from typing import List
from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter

import questionary
from questionary import Choice
Expand Down Expand Up @@ -104,76 +106,75 @@ def configure_settings():
- Whether to overwrite
"""
# MARK: Languages

language_completer = WordCompleter(["All"] + config.languages, ignore_case=True)
if not config.selected_languages:
language_selected = False
language_choices = ["All"] + config.languages
selected_languages = questionary.checkbox(
message="Select languages and press enter:",
choices=language_choices,
).ask()
selected_languages = prompt(
"Select languages (comma-separated or type 'All'): ",
completer=language_completer,
)

if "All" in selected_languages:
config.selected_languages = config.languages
language_selected = True

elif selected_languages:
config.selected_languages = selected_languages
language_selected = True

else:
rprint(
"[yellow]No language selected. Please select at least one option with space followed by enter.[/yellow]"
)
if questionary.confirm("Continue?", default=True).ask():
return configure_settings()
config.selected_languages = [
lang.strip()
for lang in selected_languages.split(",")
if lang.strip() in config.languages
]

if not config.selected_languages:
rprint("[yellow]No language selected. Please try again.[/yellow]")
return configure_settings()

# MARK: Data Types

data_type_completer = WordCompleter(["All"] + config.data_types, ignore_case=True)
selected_data_types = prompt(
"Select data types (comma-separated or type 'All'): ",
completer=data_type_completer,
)

if "All" in selected_data_types.capitalize():
config.selected_data_types = config.data_types
else:
language_selected = True
config.selected_data_types = [
dt.strip()
for dt in selected_data_types.split(",")
if dt.strip() in config.data_types
]

if language_selected:
# MARK: Data Types
if not config.selected_data_types:
rprint("[yellow]No data type selected. Please try again.[/yellow]")
return configure_settings()

data_type_selected = False
data_type_choices = ["All"] + config.data_types
selected_data_types = questionary.checkbox(
"Select data types and press enter:",
choices=data_type_choices,
).ask()
# MARK: Output Type

if "All" in selected_data_types:
config.selected_data_types = config.data_types
data_type_selected = True
output_type_completer = WordCompleter(["json", "csv", "tsv"], ignore_case=True)
config.output_type = prompt(
"Select output type (json/csv/tsv): ", completer=output_type_completer
)
while config.output_type not in ["json", "csv", "tsv"]:
rprint("[yellow]Invalid output type selected. Please try again.[/yellow]")
config.output_type = prompt(
"Select output type (json/csv/tsv): ", completer=output_type_completer
)

elif selected_data_types:
config.selected_data_types = selected_data_types
data_type_selected = True
# MARK: Output Directory

else:
rprint(
"[yellow]No data type selected. Please select at least one option with space followed by enter.[/yellow]"
)
if questionary.confirm("Continue?", default=True).ask():
return configure_settings()

if data_type_selected:
# MARK: Output Type

config.output_type = questionary.select(
"Select output type:", choices=["json", "csv", "tsv"]
).ask()

config.output_dir = Path(
questionary.text(
"Enter output directory:", default=str(config.output_dir)
).ask()
)

config.overwrite = questionary.confirm(
"Overwrite existing files?", default=config.overwrite
).ask()

display_summary()
output_dir = prompt(f"Enter output directory (default: {config.output_dir}): ")
if output_dir:
config.output_dir = Path(output_dir)

# MARK: Overwrite Confirmation

overwrite_completer = WordCompleter(["Y", "n"], ignore_case=True)
overwrite = (
prompt("Overwrite existing files? (Y/n): ", completer=overwrite_completer)
or "y"
)
config.overwrite = overwrite.lower() == "y"

display_summary()


def run_request():
Expand Down

0 comments on commit 6bf37ca

Please sign in to comment.