diff --git a/src/reviewllama/cli.py b/src/reviewllama/cli.py index ceaffd9..12afab5 100644 --- a/src/reviewllama/cli.py +++ b/src/reviewllama/cli.py @@ -1,26 +1,8 @@ import argparse -from dataclasses import dataclass from typing import List, Optional from pathlib import Path import sys - - -@dataclass(frozen=True) -class OllamaConfig: - """Configuration for Ollama client.""" - - model: str - server_url: str - timeout: int - max_retries: int - - -@dataclass(frozen=True) -class ReviewConfig: - """Complete configuration for ReviewLlama.""" - - paths: List[Path] - ollama: OllamaConfig +from .configs import OllamaConfig, ReviewConfig, create_config_from_vars def normalize_server_url(url: str) -> str: @@ -30,25 +12,6 @@ def normalize_server_url(url: str) -> str: return url.rstrip("/") -def create_ollama_config( - model: str, server_url: str, timeout: int, max_retries: int -) -> OllamaConfig: - """Create OllamaConfig with validated parameters.""" - return OllamaConfig( - model=model, - server_url=normalize_server_url(server_url), - timeout=timeout, - max_retries=max_retries, - ) - - -def create_review_config( - paths: List[Path], ollama_config: OllamaConfig -) -> ReviewConfig: - """Create complete ReviewConfig from validated components.""" - return ReviewConfig(paths=paths, ollama=ollama_config) - - def create_argument_parser() -> argparse.ArgumentParser: """Create and configure the argument parser.""" parser = argparse.ArgumentParser( @@ -110,15 +73,14 @@ def transform_namespace_to_config(namespace: argparse.Namespace) -> ReviewConfig """Transform argparse namespace into ReviewConfig.""" paths = [Path(path_str) for path_str in namespace.paths] - ollama_config = create_ollama_config( + return create_config_from_vars( + paths=paths, model=namespace.model, - server_url=namespace.server_url, + server_url=normalize_server_url(namespace.server_url), timeout=namespace.timeout, max_retries=namespace.max_retries, ) - return create_review_config(paths=paths, ollama_config=ollama_config) - def parse_arguments(args: Optional[List[str]] = None) -> ReviewConfig: """Parse command line arguments and return validated configuration.""" @@ -140,7 +102,3 @@ def cli() -> None: except Exception as e: print(f"Error: {e}", file=sys.stderr) sys.exit(1) - - -if __name__ == "__main__": - main() diff --git a/src/reviewllama/configs.py b/src/reviewllama/configs.py new file mode 100644 index 0000000..b4e882d --- /dev/null +++ b/src/reviewllama/configs.py @@ -0,0 +1,53 @@ +from dataclasses import dataclass +from typing import List +from pathlib import Path + + +@dataclass(frozen=True) +class OllamaConfig: + """Configuration for Ollama client.""" + + model: str + server_url: str + timeout: int + max_retries: int + + +@dataclass(frozen=True) +class ReviewConfig: + """Complete configuration for ReviewLlama.""" + + paths: List[Path] + ollama: OllamaConfig + + +def create_ollama_config( + model: str, server_url: str, timeout: int, max_retries: int +) -> OllamaConfig: + """Create OllamaConfig with validated parameters.""" + return OllamaConfig( + model=model, + server_url=normalize_server_url(server_url), + timeout=timeout, + max_retries=max_retries, + ) + + +def create_review_config( + paths: List[Path], ollama_config: OllamaConfig +) -> ReviewConfig: + """Create complete ReviewConfig from validated components.""" + return ReviewConfig(paths=paths, ollama=ollama_config) + + +def create_config_from_vars( + paths: List[Path], model: str, server_url: str, timeout: int, max_retries: int +): + ollama_config = OllamaConfig( + model=model, + server_url=server_url, + timeout=timeout, + max_retries=max_retries, + ) + + return create_review_config(paths, ollama_config)