xcad 5 місяців тому
батько
коміт
a5a1a15191
3 змінених файлів з 26 додано та 26 видалено
  1. 16 16
      archetypes/__main__.py
  2. 3 3
      cli/core/module/base_commands.py
  3. 7 7
      cli/core/module/helpers.py

+ 16 - 16
archetypes/__main__.py

@@ -9,7 +9,6 @@ from __future__ import annotations
 import builtins
 import importlib
 import logging
-import os
 import sys
 from collections import OrderedDict
 from pathlib import Path
@@ -20,7 +19,7 @@ import yaml
 
 # Add parent directory to Python path for CLI imports
 # This allows archetypes to import from cli module when run as `python3 -m archetypes`
-sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
+sys.path.insert(0, str(Path(__file__).parent.parent.resolve()))
 
 # Import CLI components
 from jinja2 import Environment, FileSystemLoader, StrictUndefined
@@ -93,7 +92,7 @@ class ArchetypeTemplate:
             # Load archetype config to get schema version
             archetype_config = self._load_archetype_config()
             schema_version = archetype_config.get("schema", "1.0") if archetype_config else "1.0"
-            
+
             # Import module spec with correct schema
             spec = self._import_module_spec(schema_version)
             if spec is None:
@@ -106,7 +105,7 @@ class ArchetypeTemplate:
             # Merge variables from archetypes.yaml
             if archetype_config and "vars" in archetype_config:
                 self._merge_archetype_vars(spec_dict, archetype_config["vars"])
-            
+
             return VariableCollection(spec_dict)
         except Exception as e:
             logging.warning(f"Could not load spec for module {self.module_name}: {e}")
@@ -117,7 +116,7 @@ class ArchetypeTemplate:
         config_file = self.template_dir / "archetypes.yaml"
         if not config_file.exists():
             return None
-        
+
         try:
             with config_file.open() as f:
                 return yaml.safe_load(f)
@@ -130,7 +129,7 @@ class ArchetypeTemplate:
         module_path = f"cli.modules.{self.module_name}"
         try:
             module = importlib.import_module(module_path)
-            
+
             # Try to get schema-specific spec if module supports it
             if hasattr(module, "SCHEMAS") and schema_version in module.SCHEMAS:
                 spec = module.SCHEMAS[schema_version]
@@ -138,7 +137,7 @@ class ArchetypeTemplate:
             else:
                 # Fall back to default spec
                 spec = getattr(module, "spec", None)
-            
+
             if spec is None:
                 logging.warning(f"Module {self.module_name} has no 'spec' attribute")
             return spec
@@ -161,11 +160,8 @@ class ArchetypeTemplate:
         try:
             applied_count, new_vars = self._apply_archetype_vars(spec_dict, archetype_vars)
             self._add_testing_section(spec_dict, new_vars)
-            
-            logging.debug(
-                f"Applied {applied_count} archetype var overrides, "
-                f"added {len(new_vars)} new test variables"
-            )
+
+            logging.debug(f"Applied {applied_count} archetype var overrides, added {len(new_vars)} new test variables")
         except Exception as e:
             logging.warning(f"Failed to merge archetype vars: {e}")
 
@@ -181,6 +177,7 @@ class ArchetypeTemplate:
                 new_vars[var_name] = var_spec
 
         return applied_count, new_vars
+
     def _update_existing_var(self, spec_dict: OrderedDict, var_name: str, var_spec: dict) -> bool:
         """Update existing variable with extension default."""
         if "default" not in var_spec:
@@ -330,12 +327,12 @@ def _display_archetype_content(archetype_path: Path) -> None:
 
 def _parse_var_overrides(var: list[str] | None) -> dict[str, Any]:
     """Parse --var options into a dictionary with type conversion.
-    
+
     Uses the CLI's parse_var_inputs function to ensure consistent behavior.
     """
     if not var:
         return {}
-    
+
     # Use CLI's parse_var_inputs function (no extra_args for archetypes)
     return parse_var_inputs(var, [])
 
@@ -392,9 +389,12 @@ def create_module_commands(module_name: str) -> Typer:
     def generate(
         id: str = Argument(..., help="Archetype ID (filename without .j2)"),
         directory: str | None = Argument(None, help="Output directory (for reference only - no files are written)"),
-        var: builtins.list[str] | None = Option(None, "--var", "-v", help="Set variable (KEY=VALUE format, can be used multiple times)"),
+        var: builtins.list[str] | None = None,
     ) -> None:
-        """Generate output from an archetype file (always in preview mode)."""
+        """Generate output from an archetype file (always in preview mode).
+
+        Use --var/-v to set variables in KEY=VALUE format.
+        """
         archetypes = find_archetypes(module_name)
         archetype_path = _find_archetype_by_id(archetypes, id)
 

+ 3 - 3
cli/core/module/base_commands.py

@@ -3,7 +3,6 @@
 from __future__ import annotations
 
 import logging
-import os
 from dataclasses import dataclass
 from pathlib import Path
 
@@ -303,7 +302,7 @@ def execute_dry_run(
     display: DisplayManager,
 ) -> None:
     """Execute dry run mode - preview files without writing."""
-    file_operations, total_size, new_files, overwrite_files = _analyze_file_operations(output_dir, rendered_files)
+    _file_operations, total_size, _new_files, overwrite_files = _analyze_file_operations(output_dir, rendered_files)
     size_str = _format_size(total_size)
 
     # Show file contents if requested
@@ -320,7 +319,8 @@ def execute_dry_run(
     display.text("")
     if overwrite_files > 0:
         display.warning(
-            f"Dry run: {len(rendered_files)} files ({size_str}) would be written to '{output_dir}' ({overwrite_files} files would be overwritten)"
+            f"Dry run: {len(rendered_files)} files ({size_str}) would be written to '{output_dir}' "
+            f"({overwrite_files} files would be overwritten)"
         )
     else:
         display.success(f"Dry run: {len(rendered_files)} files ({size_str}) would be written to '{output_dir}'")

+ 7 - 7
cli/core/module/helpers.py

@@ -55,31 +55,31 @@ def parse_var_inputs(var_options: list[str], extra_args: list[str]) -> dict[str,
 
 def _convert_string_to_type(value: str) -> Any:
     """Convert string value to appropriate Python type.
-    
+
     Args:
         value: String value to convert
-    
+
     Returns:
         Converted value (bool, int, float, or str)
     """
     # Boolean conversion
-    if value.lower() in ('true', 'yes', '1'):
+    if value.lower() in ("true", "yes", "1"):
         return True
-    if value.lower() in ('false', 'no', '0'):
+    if value.lower() in ("false", "no", "0"):
         return False
-    
+
     # Integer conversion
     try:
         return int(value)
     except ValueError:
         pass
-    
+
     # Float conversion
     try:
         return float(value)
     except ValueError:
         pass
-    
+
     # Return as string
     return value