refactor(application): refactor questions to separate class (#7)

* refactor(application): refactor questions to separate class
* test(application): add tests for`Application` class
This commit is contained in:
Nathaniel Landau
2023-01-25 12:20:59 -05:00
committed by GitHub
parent 1e4fbcb4e2
commit 455a2c9e86
11 changed files with 1169 additions and 304 deletions

View File

@@ -2,7 +2,6 @@
from obsidian_metadata._utils import alerts
from obsidian_metadata._utils.alerts import LoggerManager
from obsidian_metadata._utils.questions import Questions
from obsidian_metadata._utils.utilities import (
clean_dictionary,
clear_screen,
@@ -21,7 +20,6 @@ __all__ = [
"dict_contains",
"docstring_parameter",
"LoggerManager",
"Questions",
"remove_markdown_sections",
"vault_validation",
"version_callback",

View File

@@ -1,33 +0,0 @@
"""Functions for asking questions to the user and validating responses."""
from pathlib import Path
import questionary
import typer
class Questions:
"""Class for asking questions to the user and validating responses."""
@staticmethod
def ask_for_vault_path() -> Path: # pragma: no cover
"""Ask the user for the path to their vault."""
vault_path = questionary.path(
"Enter a path to Obsidian vault:",
only_directories=True,
validate=Questions._validate_vault,
).ask()
if vault_path is None:
raise typer.Exit(code=1)
return Path(vault_path).expanduser().resolve()
@staticmethod
def _validate_vault(path: str) -> bool | str:
"""Validates the vault path."""
path_to_validate: Path = Path(path).expanduser().resolve()
if not path_to_validate.exists():
return f"Path does not exist: {path_to_validate}"
if not path_to_validate.is_dir():
return f"Path is not a directory: {path_to_validate}"
return True