1+ import typer
2+ from app .utils .logger import Logger
3+ from app .utils .timeout import TimeoutWrapper
4+ from .dev import DevSetup , DevSetupConfig
5+
6+ setup_app = typer .Typer (help = "Setup development and production environments" )
7+
8+ @setup_app .command ()
9+ def dev (
10+ # Port configurations from config.dev.yaml defaults
11+ api_port : int = typer .Option (8080 , "--api-port" , help = "API server port" ),
12+ view_port : int = typer .Option (7443 , "--view-port" , help = "Frontend server port" ),
13+ db_port : int = typer .Option (5432 , "--db-port" , help = "Database port" ),
14+ redis_port : int = typer .Option (6379 , "--redis-port" , help = "Redis port" ),
15+
16+ # Repository and branch configuration
17+ branch : str = typer .Option ("feat/develop" , "--branch" , "-b" , help = "Git branch to clone" ),
18+ repo : str = typer .Option (None , "--repo" , "-r" , help = "Custom repository URL" ),
19+ workspace : str = typer .Option ("./nixopus-dev" , "--workspace" , "-w" , help = "Target workspace directory" ),
20+
21+ # SSH configuration
22+ ssh_key_path : str = typer .Option ("~/.ssh/id_ed25519_nixopus" , "--ssh-key-path" , help = "SSH key location" ),
23+ ssh_key_type : str = typer .Option ("ed25519" , "--ssh-key-type" , help = "SSH key type" ),
24+
25+ # Setup options
26+ skip_preflight : bool = typer .Option (False , "--skip-preflight" , help = "Skip preflight validation checks" ),
27+ skip_conflict : bool = typer .Option (False , "--skip-conflict" , help = "Skip conflict detection" ),
28+ skip_deps : bool = typer .Option (False , "--skip-deps" , help = "Skip dependency installation" ),
29+ skip_docker : bool = typer .Option (False , "--skip-docker" , help = "Skip Docker-based database setup" ),
30+ skip_ssh : bool = typer .Option (False , "--skip-ssh" , help = "Skip SSH key generation" ),
31+ skip_admin : bool = typer .Option (False , "--skip-admin" , help = "Skip admin account creation" ),
32+
33+ # Admin credentials
34+ admin_email : str = typer .Option (None , "--admin-email" , help = "Admin email (defaults to $USER@example.com)" ),
35+ admin_password : str = typer .Option ("Nixopus123!" , "--admin-password" , help = "Admin password" ),
36+
37+ # Control options
38+ force : bool = typer .Option (False , "--force" , "-f" , help = "Force overwrite existing files" ),
39+ dry_run : bool = typer .Option (False , "--dry-run" , "-d" , help = "Show what would be done" ),
40+ verbose : bool = typer .Option (False , "--verbose" , "-v" , help = "Detailed output" ),
41+ timeout : int = typer .Option (300 , "--timeout" , "-t" , help = "Operation timeout in seconds" ),
42+
43+ # Output configuration
44+ output : str = typer .Option ("text" , "--output" , "-o" , help = "Output format (text/json)" ),
45+
46+ # Configuration override
47+ config_file : str = typer .Option ("../helpers/config.dev.yaml" , "--config-file" , "-c" , help = "Configuration file path" ),
48+ ):
49+ """Setup complete development environment for Nixopus"""
50+ try :
51+ logger = Logger (verbose = verbose )
52+
53+ # Create configuration object
54+ config = DevSetupConfig (
55+ api_port = api_port ,
56+ view_port = view_port ,
57+ db_port = db_port ,
58+ redis_port = redis_port ,
59+ branch = branch ,
60+ repo = repo ,
61+ workspace = workspace ,
62+ ssh_key_path = ssh_key_path ,
63+ ssh_key_type = ssh_key_type ,
64+ skip_preflight = skip_preflight ,
65+ skip_conflict = skip_conflict ,
66+ skip_deps = skip_deps ,
67+ skip_docker = skip_docker ,
68+ skip_ssh = skip_ssh ,
69+ skip_admin = skip_admin ,
70+ admin_email = admin_email ,
71+ admin_password = admin_password ,
72+ force = force ,
73+ dry_run = dry_run ,
74+ verbose = verbose ,
75+ timeout = timeout ,
76+ output = output ,
77+ config_file = config_file ,
78+ )
79+
80+ # Initialize development setup orchestrator
81+ dev_setup = DevSetup (config = config , logger = logger )
82+
83+ # Execute setup with timeout
84+ with TimeoutWrapper (timeout ):
85+ dev_setup .run ()
86+
87+ logger .success ("Development environment setup completed successfully!" )
88+
89+ except TimeoutError as e :
90+ logger .error (f"Setup timed out after { timeout } seconds: { e } " )
91+ raise typer .Exit (1 )
92+ except Exception as e :
93+ logger .error (f"Setup failed: { e } " )
94+ if verbose :
95+ import traceback
96+ logger .error (traceback .format_exc ())
97+ raise typer .Exit (1 )
0 commit comments