Skip to content

Commit

Permalink
refactor: Start to extract functions in main.py for config validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkapfham committed Jul 18, 2023
1 parent 32a13d5 commit 2ffdc85
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions chasten/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
from trogon import Trogon # type: ignore
from typer.main import get_group

from chasten import (
configuration,
constants,
debug,
filesystem,
output,
server,
util,
validate,
)
from chasten import configuration
from chasten import constants
from chasten import debug
from chasten import filesystem
from chasten import output
from chasten import server
from chasten import util
from chasten import validate

# create a Typer object to support the command-line interface
cli = typer.Typer()
Expand Down Expand Up @@ -66,6 +64,20 @@ def interact(ctx: typer.Context) -> None:
Trogon(get_group(cli), click_context=ctx).run()


def display_configuration_details(chasten_user_config_dir_str, rich_path_tree):
output.console.print(rich_path_tree)
output.console.print()
configuration_file_str = (
f"{chasten_user_config_dir_str}/{constants.filesystem.Main_Configuration_File}"
)
configuration_file_path = Path(configuration_file_str)
configuration_file_yml = configuration_file_path.read_text()
data = None
with open(configuration_file_str) as user_configuration_file:
data = yaml.safe_load(user_configuration_file)
return configuration_file_str, configuration_file_yml, data


@cli.command()
def configure(
task: ConfigureTask = typer.Argument(ConfigureTask.VALIDATE.value),
Expand Down Expand Up @@ -103,14 +115,11 @@ def configure(
chasten_user_config_dir_path
)
# display the configuration directory
output.console.print(rich_path_tree)
output.console.print()
configuration_file_str = f"{chasten_user_config_dir_str}/{constants.filesystem.Main_Configuration_File}"
configuration_file_path = Path(configuration_file_str)
configuration_file_yml = configuration_file_path.read_text()
data = None
with open(configuration_file_str) as user_configuration_file:
data = yaml.safe_load(user_configuration_file)
(
configuration_file_str,
configuration_file_yml,
data,
) = display_configuration_details(chasten_user_config_dir_str, rich_path_tree)
# validate the user's configuration and display the results
(validated, errors) = validate.validate_configuration(data)
output.console.print(
Expand Down

0 comments on commit 2ffdc85

Please sign in to comment.