mirror of
https://github.com/natelandau/obsidian-metadata.git
synced 2025-11-18 09:53:40 -05:00
feat(configuration): support multiple vaults in the configuration file (#6)
When multiple vaults are added to the configuration file, the script will prompt you to select one at runtime
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
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,
|
||||
@@ -9,7 +10,6 @@ from obsidian_metadata._utils.utilities import (
|
||||
dict_values_to_lists_strings,
|
||||
docstring_parameter,
|
||||
remove_markdown_sections,
|
||||
vault_validation,
|
||||
version_callback,
|
||||
)
|
||||
|
||||
@@ -21,6 +21,7 @@ __all__ = [
|
||||
"dict_contains",
|
||||
"docstring_parameter",
|
||||
"LoggerManager",
|
||||
"Questions",
|
||||
"remove_markdown_sections",
|
||||
"vault_validation",
|
||||
"version_callback",
|
||||
|
||||
33
src/obsidian_metadata/_utils/questions.py
Normal file
33
src/obsidian_metadata/_utils/questions.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""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
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Utility functions."""
|
||||
import re
|
||||
from os import name, system
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import typer
|
||||
@@ -83,17 +82,6 @@ def version_callback(value: bool) -> None:
|
||||
raise typer.Exit()
|
||||
|
||||
|
||||
def vault_validation(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
|
||||
|
||||
|
||||
def docstring_parameter(*sub: Any) -> Any:
|
||||
"""Decorator to replace variables within docstrings.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user