Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 09:04:14 +08:00
commit 70c36b5eff
248 changed files with 47482 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
"""{{CLI_NAME}} - {{CLI_DESCRIPTION}}
Basic Fire CLI template with single-class structure.
"""
import fire
from rich.console import Console
console = Console()
class {{CLASS_NAME}}:
"""{{CLI_DESCRIPTION}}"""
def __init__(self):
self.version = "{{VERSION}}"
self.verbose = False
def init(self, name='{{DEFAULT_PROJECT_NAME}}'):
"""Initialize a new project
Args:
name: Project name (default: {{DEFAULT_PROJECT_NAME}})
"""
console.print(f"[green]✓[/green] Initializing project: {name}")
console.print(f"[dim]Version: {self.version}[/dim]")
return {"status": "success", "project": name}
def build(self, verbose=False):
"""Build the project
Args:
verbose: Enable verbose output (default: False)
"""
self.verbose = verbose
if self.verbose:
console.print("[dim]Verbose mode enabled[/dim]")
console.print("[cyan]Building project...[/cyan]")
# Add build logic here
console.print("[green]✓[/green] Build complete!")
def version_info(self):
"""Display version information"""
console.print(f"[bold]{{CLI_NAME}}[/bold] version {self.version}")
return {"version": self.version}
def main():
fire.Fire({{CLASS_NAME}})
if __name__ == '__main__':
main()
# Usage examples:
# python {{CLI_NAME_LOWER}}.py init --name=my-project
# python {{CLI_NAME_LOWER}}.py build --verbose
# python {{CLI_NAME_LOWER}}.py version-info

View File

@@ -0,0 +1,228 @@
"""{{CLI_NAME}} - {{CLI_DESCRIPTION}}
Fire CLI with comprehensive configuration management.
"""
import fire
from rich.console import Console
from pathlib import Path
import json
from typing import Dict, Any, Optional
console = Console()
class ConfigManager:
"""Configuration management with file persistence"""
def __init__(self, config_file: Path):
self.config_file = config_file
self._ensure_config_exists()
def _ensure_config_exists(self) -> None:
"""Create config file if it doesn't exist"""
self.config_file.parent.mkdir(parents=True, exist_ok=True)
if not self.config_file.exists():
self.config_file.write_text(json.dumps({}, indent=2))
def load(self) -> Dict[str, Any]:
"""Load configuration from file"""
try:
return json.loads(self.config_file.read_text())
except Exception as e:
console.print(f"[red]Error loading config: {e}[/red]")
return {}
def save(self, config: Dict[str, Any]) -> None:
"""Save configuration to file"""
try:
self.config_file.write_text(json.dumps(config, indent=2))
except Exception as e:
console.print(f"[red]Error saving config: {e}[/red]")
class {{CLASS_NAME}}:
"""{{CLI_DESCRIPTION}}"""
def __init__(self):
self.version = "{{VERSION}}"
self.config_file = Path.home() / ".{{CLI_NAME_LOWER}}" / "config.json"
self.config_manager = ConfigManager(self.config_file)
class Config:
"""Configuration management commands"""
def __init__(self, parent):
self.parent = parent
self.manager = parent.config_manager
def get(self, key: str, default: Optional[str] = None) -> Optional[str]:
"""Get configuration value
Args:
key: Configuration key to retrieve
default: Default value if key not found
"""
config = self.manager.load()
value = config.get(key, default)
if value is None:
console.print(f"[yellow]Key '{key}' not found[/yellow]")
else:
console.print(f"[blue]{key}[/blue]: {value}")
return value
def set(self, key: str, value: str) -> None:
"""Set configuration value
Args:
key: Configuration key to set
value: Configuration value
"""
config = self.manager.load()
config[key] = value
self.manager.save(config)
console.print(f"[green]✓[/green] Set {key} = {value}")
def unset(self, key: str) -> None:
"""Remove configuration key
Args:
key: Configuration key to remove
"""
config = self.manager.load()
if key in config:
del config[key]
self.manager.save(config)
console.print(f"[green]✓[/green] Removed {key}")
else:
console.print(f"[yellow]Key '{key}' not found[/yellow]")
def list(self) -> Dict[str, Any]:
"""List all configuration values"""
config = self.manager.load()
if not config:
console.print("[yellow]No configuration values set[/yellow]")
return {}
console.print("[bold]Configuration:[/bold]")
for key, value in sorted(config.items()):
console.print(f" [blue]{key}[/blue]: {value}")
return config
def reset(self, confirm: bool = False) -> None:
"""Reset configuration to defaults
Args:
confirm: Confirm reset operation
"""
if not confirm:
console.print("[yellow]Use --confirm to reset configuration[/yellow]")
return
self.manager.save({})
console.print("[green]✓[/green] Configuration reset")
def path(self) -> str:
"""Show configuration file path"""
console.print(f"[blue]Config file:[/blue] {self.parent.config_file}")
return str(self.parent.config_file)
def edit(self) -> None:
"""Open configuration file in editor"""
import os
editor = os.environ.get('EDITOR', 'vim')
console.print(f"[dim]Opening {self.parent.config_file} in {editor}[/dim]")
os.system(f"{editor} {self.parent.config_file}")
def validate(self) -> bool:
"""Validate configuration file"""
try:
config = self.manager.load()
console.print("[green]✓[/green] Configuration is valid")
console.print(f"[dim]Found {len(config)} keys[/dim]")
return True
except Exception as e:
console.print(f"[red]✗ Configuration is invalid: {e}[/red]")
return False
def export(self, output_file: Optional[str] = None) -> str:
"""Export configuration to file
Args:
output_file: Output file path (default: stdout)
"""
config = self.manager.load()
output = json.dumps(config, indent=2)
if output_file:
Path(output_file).write_text(output)
console.print(f"[green]✓[/green] Exported to {output_file}")
else:
console.print(output)
return output
def import_config(self, input_file: str, merge: bool = False) -> None:
"""Import configuration from file
Args:
input_file: Input file path
merge: Merge with existing config (default: False)
"""
try:
new_config = json.loads(Path(input_file).read_text())
if merge:
config = self.manager.load()
config.update(new_config)
else:
config = new_config
self.manager.save(config)
console.print(f"[green]✓[/green] Imported configuration from {input_file}")
except Exception as e:
console.print(f"[red]Error importing config: {e}[/red]")
def __init__(self):
self.version = "{{VERSION}}"
self.config_file = Path.home() / ".{{CLI_NAME_LOWER}}" / "config.json"
self.config_manager = ConfigManager(self.config_file)
self.config = self.Config(self)
def info(self) -> Dict[str, Any]:
"""Display CLI information"""
console.print(f"[bold]{{CLI_NAME}}[/bold] v{self.version}")
console.print(f"Config file: {self.config_file}")
config = self.config_manager.load()
console.print(f"Config keys: {len(config)}")
return {
"version": self.version,
"config_file": str(self.config_file),
"config_keys": len(config)
}
def main():
fire.Fire({{CLASS_NAME}})
if __name__ == '__main__':
main()
# Usage examples:
# python {{CLI_NAME_LOWER}}.py config get api_key
# python {{CLI_NAME_LOWER}}.py config set api_key abc123
# python {{CLI_NAME_LOWER}}.py config unset api_key
# python {{CLI_NAME_LOWER}}.py config list
# python {{CLI_NAME_LOWER}}.py config reset --confirm
# python {{CLI_NAME_LOWER}}.py config path
# python {{CLI_NAME_LOWER}}.py config validate
# python {{CLI_NAME_LOWER}}.py config export output.json
# python {{CLI_NAME_LOWER}}.py config import-config input.json --merge

View File

@@ -0,0 +1,268 @@
"""{{CLI_NAME}} - {{CLI_DESCRIPTION}}
Complex multi-command Fire CLI with multiple command groups.
"""
import fire
from rich.console import Console
from rich.table import Table
from pathlib import Path
from typing import Optional, List
import json
console = Console()
class {{CLASS_NAME}}:
"""{{CLI_DESCRIPTION}}"""
def __init__(self):
self.version = "{{VERSION}}"
self.config_file = Path.home() / ".{{CLI_NAME_LOWER}}" / "config.json"
class Project:
"""Project management commands"""
def create(self, name: str, template: str = 'default', path: Optional[str] = None):
"""Create a new project
Args:
name: Project name
template: Project template (default: default)
path: Project path (default: current directory)
"""
project_path = Path(path) if path else Path.cwd() / name
console.print(f"[green]✓[/green] Creating project: {name}")
console.print(f"[dim]Template: {template}[/dim]")
console.print(f"[dim]Path: {project_path}[/dim]")
def delete(self, name: str, confirm: bool = False):
"""Delete a project
Args:
name: Project name
confirm: Confirm deletion
"""
if not confirm:
console.print("[yellow]Use --confirm to delete project[/yellow]")
return
console.print(f"[red]Deleting project: {name}[/red]")
def list(self):
"""List all projects"""
projects = [
{"name": "project-a", "status": "active", "version": "1.0.0"},
{"name": "project-b", "status": "archived", "version": "2.1.0"},
]
table = Table(title="Projects")
table.add_column("Name", style="cyan")
table.add_column("Status", style="green")
table.add_column("Version", style="yellow")
for proj in projects:
table.add_row(proj['name'], proj['status'], proj['version'])
console.print(table)
return projects
class Build:
"""Build management commands"""
def start(self, target: str, parallel: bool = False, workers: int = 4):
"""Start build process
Args:
target: Build target
parallel: Enable parallel builds
workers: Number of parallel workers
"""
console.print(f"[cyan]Building target: {target}[/cyan]")
if parallel:
console.print(f"[dim]Parallel mode with {workers} workers[/dim]")
def clean(self, deep: bool = False):
"""Clean build artifacts
Args:
deep: Perform deep clean (includes cache)
"""
console.print("[yellow]Cleaning build artifacts...[/yellow]")
if deep:
console.print("[dim]Deep clean: removing cache[/dim]")
def status(self):
"""Show build status"""
console.print("[bold]Build Status:[/bold]")
console.print(" Last build: [green]Success[/green]")
console.print(" Artifacts: 42 files")
class Deploy:
"""Deployment commands"""
def start(
self,
environment: str,
service: Optional[str] = None,
force: bool = False,
mode: str = 'safe'
):
"""Deploy to environment
Args:
environment: Target environment (dev, staging, prod)
service: Specific service to deploy (default: all)
force: Force deployment
mode: Deployment mode (fast, safe, rollback)
"""
console.print(f"[cyan]Deploying to {environment}[/cyan]")
if service:
console.print(f"[dim]Service: {service}[/dim]")
console.print(f"[dim]Mode: {mode}[/dim]")
if force:
console.print("[yellow]⚠ Force mode enabled[/yellow]")
def rollback(self, environment: str, version: Optional[str] = None):
"""Rollback deployment
Args:
environment: Target environment
version: Version to rollback to (default: previous)
"""
target = version or "previous"
console.print(f"[yellow]Rolling back {environment} to {target}[/yellow]")
def status(self, environment: str):
"""Show deployment status
Args:
environment: Target environment
"""
console.print(f"[bold]Deployment Status: {environment}[/bold]")
console.print(" Status: [green]Active[/green]")
console.print(" Version: 1.2.3")
console.print(" Last deployed: 2 hours ago")
def history(self, environment: str, limit: int = 10):
"""Show deployment history
Args:
environment: Target environment
limit: Number of records to show
"""
console.print(f"[bold]Deployment History: {environment}[/bold]")
for i in range(limit):
console.print(f" {i+1}. Version 1.{i}.0 - 2 days ago")
class Database:
"""Database management commands"""
def migrate(self, direction: str = 'up', steps: Optional[int] = None):
"""Run database migrations
Args:
direction: Migration direction (up, down)
steps: Number of migrations to run (default: all)
"""
console.print(f"[cyan]Running migrations {direction}[/cyan]")
if steps:
console.print(f"[dim]Steps: {steps}[/dim]")
def seed(self, dataset: str = 'default'):
"""Seed database
Args:
dataset: Dataset to use (default, test, production)
"""
console.print(f"[green]Seeding database with {dataset} dataset[/green]")
def reset(self, confirm: bool = False):
"""Reset database
Args:
confirm: Confirm reset operation
"""
if not confirm:
console.print("[yellow]Use --confirm to reset database[/yellow]")
return
console.print("[red]Resetting database...[/red]")
def backup(self, output: Optional[str] = None):
"""Backup database
Args:
output: Output file path (default: auto-generated)
"""
filename = output or f"backup-{self._timestamp()}.sql"
console.print(f"[cyan]Creating backup: {filename}[/cyan]")
@staticmethod
def _timestamp():
from datetime import datetime
return datetime.now().strftime("%Y%m%d-%H%M%S")
class Config:
"""Configuration commands"""
def __init__(self, parent):
self.parent = parent
def get(self, key: str):
"""Get configuration value"""
console.print(f"[blue]{key}[/blue]: value")
def set(self, key: str, value: str):
"""Set configuration value"""
console.print(f"[green]✓[/green] Set {key} = {value}")
def list(self):
"""List all configuration"""
console.print("[bold]Configuration:[/bold]")
console.print(" api_key: abc123")
console.print(" endpoint: https://api.example.com")
def __init__(self):
self.version = "{{VERSION}}"
self.config_file = Path.home() / ".{{CLI_NAME_LOWER}}" / "config.json"
self.project = self.Project()
self.build = self.Build()
self.deploy = self.Deploy()
self.database = self.Database()
self.config = self.Config(self)
def version_info(self):
"""Display version information"""
console.print(f"[bold]{{CLI_NAME}}[/bold] version {self.version}")
return {"version": self.version}
def info(self):
"""Display CLI information"""
console.print(f"[bold]{{CLI_NAME}}[/bold] v{self.version}")
console.print(f"Config: {self.config_file}")
console.print("\n[bold]Available Commands:[/bold]")
console.print(" project - Project management")
console.print(" build - Build management")
console.print(" deploy - Deployment commands")
console.print(" database - Database operations")
console.print(" config - Configuration management")
def main():
fire.Fire({{CLASS_NAME}})
if __name__ == '__main__':
main()
# Usage examples:
# python {{CLI_NAME_LOWER}}.py project create my-app --template=react
# python {{CLI_NAME_LOWER}}.py project list
# python {{CLI_NAME_LOWER}}.py build start production --parallel
# python {{CLI_NAME_LOWER}}.py build clean --deep
# python {{CLI_NAME_LOWER}}.py deploy start staging --service=api
# python {{CLI_NAME_LOWER}}.py deploy rollback production --version=1.2.0
# python {{CLI_NAME_LOWER}}.py database migrate --direction=up
# python {{CLI_NAME_LOWER}}.py database backup
# python {{CLI_NAME_LOWER}}.py config get api_key

View File

@@ -0,0 +1,148 @@
"""{{CLI_NAME}} - {{CLI_DESCRIPTION}}
Nested Fire CLI template with command groups.
"""
import fire
from rich.console import Console
from pathlib import Path
import json
console = Console()
class {{CLASS_NAME}}:
"""{{CLI_DESCRIPTION}}"""
def __init__(self):
self.version = "{{VERSION}}"
self.config_file = Path.home() / ".{{CLI_NAME_LOWER}}" / "config.json"
class Config:
"""Configuration management commands"""
def __init__(self, parent):
self.parent = parent
def get(self, key):
"""Get configuration value
Args:
key: Configuration key to retrieve
"""
config = self._load_config()
value = config.get(key)
if value is None:
console.print(f"[yellow]Key '{key}' not found[/yellow]")
else:
console.print(f"[blue]{key}[/blue]: {value}")
return value
def set(self, key, value):
"""Set configuration value
Args:
key: Configuration key to set
value: Configuration value
"""
config = self._load_config()
config[key] = value
self._save_config(config)
console.print(f"[green]✓[/green] Set {key} = {value}")
def list(self):
"""List all configuration values"""
config = self._load_config()
if not config:
console.print("[yellow]No configuration values set[/yellow]")
return
console.print("[bold]Configuration:[/bold]")
for key, value in config.items():
console.print(f" [blue]{key}[/blue]: {value}")
return config
def reset(self):
"""Reset configuration to defaults"""
self._save_config({})
console.print("[green]✓[/green] Configuration reset")
def _load_config(self):
"""Load configuration from file"""
if not self.parent.config_file.exists():
return {}
try:
return json.loads(self.parent.config_file.read_text())
except Exception as e:
console.print(f"[red]Error loading config: {e}[/red]")
return {}
def _save_config(self, config):
"""Save configuration to file"""
self.parent.config_file.parent.mkdir(parents=True, exist_ok=True)
self.parent.config_file.write_text(json.dumps(config, indent=2))
class {{SUBCOMMAND_GROUP_NAME}}:
"""{{SUBCOMMAND_GROUP_DESCRIPTION}}"""
def create(self, name, template='default'):
"""Create new {{RESOURCE_NAME}}
Args:
name: {{RESOURCE_NAME}} name
template: Template to use (default: default)
"""
console.print(f"[cyan]Creating {{RESOURCE_NAME}}: {name}[/cyan]")
console.print(f"[dim]Using template: {template}[/dim]")
console.print("[green]✓[/green] {{RESOURCE_NAME}} created successfully")
def delete(self, name, confirm=False):
"""Delete {{RESOURCE_NAME}}
Args:
name: {{RESOURCE_NAME}} name
confirm: Confirm deletion (default: False)
"""
if not confirm:
console.print("[yellow]⚠ Use --confirm to delete {{RESOURCE_NAME}}[/yellow]")
return
console.print(f"[red]Deleting {{RESOURCE_NAME}}: {name}[/red]")
console.print("[green]✓[/green] {{RESOURCE_NAME}} deleted")
def list(self):
"""List all {{RESOURCE_NAME}}s"""
console.print("[bold]{{RESOURCE_NAME}}s:[/bold]")
# Add list logic here
items = ["item1", "item2", "item3"]
for item in items:
console.print(f" • {item}")
return items
def __init__(self):
self.version = "{{VERSION}}"
self.config_file = Path.home() / ".{{CLI_NAME_LOWER}}" / "config.json"
self.config = self.Config(self)
self.{{SUBCOMMAND_GROUP_NAME_LOWER}} = self.{{SUBCOMMAND_GROUP_NAME}}()
def info(self):
"""Display CLI information"""
console.print(f"[bold]{{CLI_NAME}}[/bold] v{self.version}")
console.print(f"Config file: {self.config_file}")
return {"version": self.version, "config_file": str(self.config_file)}
def main():
fire.Fire({{CLASS_NAME}})
if __name__ == '__main__':
main()
# Usage examples:
# python {{CLI_NAME_LOWER}}.py config get api_key
# python {{CLI_NAME_LOWER}}.py config set api_key abc123
# python {{CLI_NAME_LOWER}}.py config list
# python {{CLI_NAME_LOWER}}.py {{SUBCOMMAND_GROUP_NAME_LOWER}} create my-item
# python {{CLI_NAME_LOWER}}.py {{SUBCOMMAND_GROUP_NAME_LOWER}} delete my-item --confirm
# python {{CLI_NAME_LOWER}}.py {{SUBCOMMAND_GROUP_NAME_LOWER}} list

View File

@@ -0,0 +1,161 @@
"""{{CLI_NAME}} - {{CLI_DESCRIPTION}}
Fire CLI with rich console formatting and output.
"""
import fire
from rich.console import Console
from rich.table import Table
from rich.panel import Panel
from rich.progress import track
from rich.tree import Tree
import time
console = Console()
class {{CLASS_NAME}}:
"""{{CLI_DESCRIPTION}}"""
def __init__(self):
self.version = "{{VERSION}}"
def status(self):
"""Display application status with rich formatting"""
panel = Panel(
"[bold green]Application Running[/bold green]\n"
f"Version: {self.version}\n"
"Status: [green]Active[/green]",
title="{{CLI_NAME}} Status",
border_style="green"
)
console.print(panel)
return {
"status": "active",
"version": self.version
}
def list_items(self, format='table'):
"""List items with formatted output
Args:
format: Output format - table, tree, or json (default: table)
"""
items = [
{"id": 1, "name": "Item Alpha", "status": "active", "count": 42},
{"id": 2, "name": "Item Beta", "status": "pending", "count": 23},
{"id": 3, "name": "Item Gamma", "status": "completed", "count": 67},
]
if format == 'table':
table = Table(title="{{CLI_NAME}} Items", show_header=True, header_style="bold magenta")
table.add_column("ID", style="cyan", width=6)
table.add_column("Name", style="green")
table.add_column("Status", style="yellow")
table.add_column("Count", justify="right", style="blue")
for item in items:
status_color = {
"active": "green",
"pending": "yellow",
"completed": "blue"
}.get(item['status'], "white")
table.add_row(
str(item['id']),
item['name'],
f"[{status_color}]{item['status']}[/{status_color}]",
str(item['count'])
)
console.print(table)
elif format == 'tree':
tree = Tree("{{CLI_NAME}} Items")
for item in items:
branch = tree.add(f"[bold]{item['name']}[/bold]")
branch.add(f"ID: {item['id']}")
branch.add(f"Status: {item['status']}")
branch.add(f"Count: {item['count']}")
console.print(tree)
else: # json
import json
output = json.dumps(items, indent=2)
console.print(output)
return items
def process(self, count=100, delay=0.01):
"""Process items with progress bar
Args:
count: Number of items to process (default: 100)
delay: Delay between items in seconds (default: 0.01)
"""
console.print(Panel(
f"[bold cyan]Processing {count} items[/bold cyan]",
border_style="cyan"
))
results = []
for i in track(range(count), description="Processing..."):
time.sleep(delay)
results.append(i)
console.print("[green]✓[/green] Processing complete!")
console.print(f"[dim]Processed {len(results)} items[/dim]")
return {"processed": len(results)}
def build(self, target='production', verbose=False):
"""Build project with formatted output
Args:
target: Build target environment (default: production)
verbose: Show detailed build information (default: False)
"""
console.print(Panel(
f"[bold]Building for {target}[/bold]",
title="Build Process",
border_style="blue"
))
steps = [
"Cleaning build directory",
"Installing dependencies",
"Compiling source files",
"Running tests",
"Packaging artifacts"
]
for step in steps:
console.print(f"[cyan]→[/cyan] {step}...")
if verbose:
console.print(f" [dim]Details for: {step}[/dim]")
time.sleep(0.3)
console.print("\n[green]✓[/green] Build successful!")
return {
"status": "success",
"target": target,
"steps_completed": len(steps)
}
def main():
fire.Fire({{CLASS_NAME}})
if __name__ == '__main__':
main()
# Usage examples:
# python {{CLI_NAME_LOWER}}.py status
# python {{CLI_NAME_LOWER}}.py list-items
# python {{CLI_NAME_LOWER}}.py list-items --format=tree
# python {{CLI_NAME_LOWER}}.py process --count=50
# python {{CLI_NAME_LOWER}}.py build --target=staging --verbose

View File

@@ -0,0 +1,206 @@
"""{{CLI_NAME}} - {{CLI_DESCRIPTION}}
Type-annotated Fire CLI template with full type hints.
"""
import fire
from rich.console import Console
from typing import Optional, List, Dict, Any, Literal
from pathlib import Path
from enum import Enum
console = Console()
class Environment(str, Enum):
"""Deployment environment options"""
DEV = "dev"
STAGING = "staging"
PRODUCTION = "production"
class OutputFormat(str, Enum):
"""Output format options"""
JSON = "json"
YAML = "yaml"
TEXT = "text"
class {{CLASS_NAME}}:
"""{{CLI_DESCRIPTION}}"""
def __init__(self) -> None:
self.version: str = "{{VERSION}}"
self.verbose: bool = False
def init(
self,
name: str,
template: str = 'default',
path: Optional[Path] = None
) -> Dict[str, Any]:
"""Initialize a new project
Args:
name: Project name
template: Template to use (default: default)
path: Project path (default: current directory)
Returns:
Dictionary with initialization status
"""
project_path = path or Path.cwd() / name
console.print(f"[green]✓[/green] Initializing project: {name}")
console.print(f"[dim]Template: {template}[/dim]")
console.print(f"[dim]Path: {project_path}[/dim]")
return {
"status": "success",
"project": name,
"template": template,
"path": str(project_path)
}
def deploy(
self,
environment: Environment,
force: bool = False,
mode: Literal['fast', 'safe', 'rollback'] = 'safe',
services: Optional[List[str]] = None
) -> Dict[str, Any]:
"""Deploy to specified environment
Args:
environment: Target environment (dev, staging, production)
force: Force deployment without confirmation (default: False)
mode: Deployment mode - fast, safe, or rollback (default: safe)
services: List of services to deploy (default: all)
Returns:
Dictionary with deployment status
"""
console.print(f"[cyan]Deploying to {environment.value} in {mode} mode[/cyan]")
if force:
console.print("[yellow]⚠ Force mode enabled[/yellow]")
if services:
console.print(f"[dim]Services: {', '.join(services)}[/dim]")
else:
console.print("[dim]Deploying all services[/dim]")
return {
"status": "success",
"environment": environment.value,
"mode": mode,
"force": force,
"services": services or ["all"]
}
def export(
self,
output_format: OutputFormat = OutputFormat.JSON,
output_file: Optional[Path] = None,
pretty: bool = True
) -> str:
"""Export data in specified format
Args:
output_format: Output format (json, yaml, text)
output_file: Output file path (default: stdout)
pretty: Pretty-print output (default: True)
Returns:
Exported data as string
"""
data = {
"version": self.version,
"items": [1, 2, 3],
"total": 3
}
if output_format == OutputFormat.JSON:
import json
output = json.dumps(data, indent=2 if pretty else None)
elif output_format == OutputFormat.YAML:
output = "version: {}\nitems:\n - 1\n - 2\n - 3\ntotal: 3".format(self.version)
else:
output = f"Version: {self.version}\nTotal items: {data['total']}"
if output_file:
output_file.write_text(output)
console.print(f"[green]✓[/green] Exported to {output_file}")
else:
console.print(output)
return output
def build(
self,
targets: List[str],
parallel: bool = False,
max_workers: int = 4,
verbose: bool = False
) -> Dict[str, Any]:
"""Build specified targets
Args:
targets: List of build targets
parallel: Enable parallel builds (default: False)
max_workers: Maximum parallel workers (default: 4)
verbose: Enable verbose output (default: False)
Returns:
Dictionary with build results
"""
self.verbose = verbose
console.print(f"[cyan]Building targets: {', '.join(targets)}[/cyan]")
if parallel:
console.print(f"[dim]Parallel mode with {max_workers} workers[/dim]")
if self.verbose:
console.print("[dim]Verbose mode enabled[/dim]")
return {
"status": "success",
"targets": targets,
"parallel": parallel,
"max_workers": max_workers
}
def config_get(self, key: str) -> Optional[str]:
"""Get configuration value
Args:
key: Configuration key
Returns:
Configuration value or None
"""
# Mock configuration
config = {"api_key": "abc123", "endpoint": "https://api.example.com"}
value = config.get(key)
if value:
console.print(f"[blue]{key}[/blue]: {value}")
else:
console.print(f"[yellow]Key '{key}' not found[/yellow]")
return value
def main() -> None:
fire.Fire({{CLASS_NAME}})
if __name__ == '__main__':
main()
# Usage examples:
# python {{CLI_NAME_LOWER}}.py init my-project --template=react
# python {{CLI_NAME_LOWER}}.py deploy production --force --mode=fast
# python {{CLI_NAME_LOWER}}.py export --output-format=yaml
# python {{CLI_NAME_LOWER}}.py build web api --parallel --max-workers=8
# python {{CLI_NAME_LOWER}}.py config-get api_key