Rename project from SmartTools to CmdForge
Major rename operation: - Rename Python package: smarttools -> cmdforge - Update CLI entry point: smarttools -> cmdforge - Update all imports and module references - Update pyproject.toml with new name, URLs, entry point - Update all HTML templates with new branding - Update documentation (CLAUDE.md, README.md, docs/*, wiki/*) - Update environment variables: - SMARTTOOLS_ENV -> CMDFORGE_ENV - SMARTTOOLS_REGISTRY_DB -> CMDFORGE_REGISTRY_DB - SMARTTOOLS_TOKEN -> CMDFORGE_TOKEN - SMARTTOOLS_REGISTRY_* -> CMDFORGE_REGISTRY_* - Update Dockerfile and docker-compose.yml - Update tests to use new package name - Update scripts and examples - Update package.json and tailwind.config.js All 158 unit tests pass. The CLI is working correctly with the new cmdforge command. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
"""Global configuration handling for CmdForge.
|
||||
|
||||
Manages ~/.cmdforge/config.yaml with registry settings, tokens, and preferences.
|
||||
"""
|
||||
|
||||
import uuid
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
# Default configuration directory
|
||||
CONFIG_DIR = Path.home() / ".cmdforge"
|
||||
CONFIG_FILE = CONFIG_DIR / "config.yaml"
|
||||
|
||||
# Default registry URL (canonical base path)
|
||||
DEFAULT_REGISTRY_URL = "https://gitea.brrd.tech/api/v1"
|
||||
|
||||
|
||||
@dataclass
|
||||
class RegistryConfig:
|
||||
"""Registry-related configuration."""
|
||||
url: str = DEFAULT_REGISTRY_URL
|
||||
token: Optional[str] = None
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
d = {"url": self.url}
|
||||
if self.token:
|
||||
d["token"] = self.token
|
||||
return d
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict) -> "RegistryConfig":
|
||||
return cls(
|
||||
url=data.get("url", DEFAULT_REGISTRY_URL),
|
||||
token=data.get("token")
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
"""Global CmdForge configuration."""
|
||||
registry: RegistryConfig = field(default_factory=RegistryConfig)
|
||||
client_id: str = ""
|
||||
auto_fetch_from_registry: bool = True
|
||||
default_provider: Optional[str] = None
|
||||
|
||||
def __post_init__(self):
|
||||
# Generate client_id if not set
|
||||
if not self.client_id:
|
||||
self.client_id = f"anon_{uuid.uuid4().hex[:16]}"
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
d = {
|
||||
"registry": self.registry.to_dict(),
|
||||
"client_id": self.client_id,
|
||||
"auto_fetch_from_registry": self.auto_fetch_from_registry,
|
||||
}
|
||||
if self.default_provider:
|
||||
d["default_provider"] = self.default_provider
|
||||
return d
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict) -> "Config":
|
||||
registry_data = data.get("registry", {})
|
||||
return cls(
|
||||
registry=RegistryConfig.from_dict(registry_data),
|
||||
client_id=data.get("client_id", ""),
|
||||
auto_fetch_from_registry=data.get("auto_fetch_from_registry", True),
|
||||
default_provider=data.get("default_provider")
|
||||
)
|
||||
|
||||
|
||||
def get_config_dir() -> Path:
|
||||
"""Get the config directory, creating it if needed."""
|
||||
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
||||
return CONFIG_DIR
|
||||
|
||||
|
||||
def load_config() -> Config:
|
||||
"""Load configuration from disk, creating defaults if needed."""
|
||||
config_path = get_config_dir() / "config.yaml"
|
||||
|
||||
if not config_path.exists():
|
||||
# Create default config
|
||||
config = Config()
|
||||
save_config(config)
|
||||
return config
|
||||
|
||||
try:
|
||||
data = yaml.safe_load(config_path.read_text()) or {}
|
||||
return Config.from_dict(data)
|
||||
except Exception as e:
|
||||
print(f"Warning: Error loading config, using defaults: {e}")
|
||||
return Config()
|
||||
|
||||
|
||||
def save_config(config: Config) -> Path:
|
||||
"""Save configuration to disk."""
|
||||
config_path = get_config_dir() / "config.yaml"
|
||||
config_path.write_text(yaml.dump(config.to_dict(), default_flow_style=False, sort_keys=False))
|
||||
return config_path
|
||||
|
||||
|
||||
def get_registry_url() -> str:
|
||||
"""Get the configured registry URL."""
|
||||
config = load_config()
|
||||
return config.registry.url
|
||||
|
||||
|
||||
def get_registry_token() -> Optional[str]:
|
||||
"""Get the configured registry token."""
|
||||
config = load_config()
|
||||
return config.registry.token
|
||||
|
||||
|
||||
def set_registry_token(token: str) -> None:
|
||||
"""Set and save the registry token."""
|
||||
config = load_config()
|
||||
config.registry.token = token
|
||||
save_config(config)
|
||||
|
||||
|
||||
def get_client_id() -> str:
|
||||
"""Get the client ID for anonymous usage tracking."""
|
||||
config = load_config()
|
||||
return config.client_id
|
||||
|
||||
|
||||
def is_auto_fetch_enabled() -> bool:
|
||||
"""Check if auto-fetch from registry is enabled."""
|
||||
config = load_config()
|
||||
return config.auto_fetch_from_registry
|
||||
Reference in New Issue
Block a user