Skip to content

Commit b9a4e03

Browse files
Jakub Winklerclaude
andcommitted
v0.7.1: Refactor commands into separate files
Split monolithic main.go (3550 lines) into 26 focused command files: - Each command has its own file with self-contained init() - Added domain management with store code support - Updated vhost template for MAGE_RUN_CODE Files: root.go, init_cmd.go, start.go, stop.go, status.go, php.go, shell.go, run.go, db.go, redis.go, logs.go, global.go, ssl.go, install.go, varnish.go, dns.go, domain.go, config_cmd.go, list.go, selfupdate.go, new.go + existing admin.go, bootstrap.go, check.go, xdebug.go, helpers.go 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ec9f3b0 commit b9a4e03

29 files changed

Lines changed: 3808 additions & 3264 deletions

cmd/magebox/admin.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ You will be prompted for:
6767
RunE: runAdminCreate,
6868
}
6969

70+
func init() {
71+
adminCmd.AddCommand(adminPasswordCmd)
72+
adminCmd.AddCommand(adminDisable2FACmd)
73+
adminCmd.AddCommand(adminListCmd)
74+
adminCmd.AddCommand(adminCreateCmd)
75+
rootCmd.AddCommand(adminCmd)
76+
}
77+
7078
func runAdminPassword(cmd *cobra.Command, args []string) error {
7179
cwd, err := getCwd()
7280
if err != nil {

cmd/magebox/bootstrap.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ Run this once after installing MageBox to prepare your system.`,
4545
RunE: runBootstrap,
4646
}
4747

48+
func init() {
49+
rootCmd.AddCommand(bootstrapCmd)
50+
}
51+
4852
func runBootstrap(cmd *cobra.Command, args []string) error {
4953
p, err := getPlatform()
5054
if err != nil {

cmd/magebox/check.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Run this command to diagnose issues with your development environment.`,
3939
RunE: runCheck,
4040
}
4141

42+
func init() {
43+
rootCmd.AddCommand(checkCmd)
44+
}
45+
4246
type checkResult struct {
4347
name string
4448
status string // "ok", "warning", "error"

cmd/magebox/config_cmd.go

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
9+
"github.com/qoliber/magebox/internal/cli"
10+
"github.com/qoliber/magebox/internal/config"
11+
)
12+
13+
var configCmd = &cobra.Command{
14+
Use: "config",
15+
Short: "MageBox configuration",
16+
Long: "View and modify MageBox global configuration",
17+
}
18+
19+
var configShowCmd = &cobra.Command{
20+
Use: "show",
21+
Short: "Show current configuration",
22+
Long: "Displays the current MageBox global configuration",
23+
RunE: runConfigShow,
24+
}
25+
26+
var configSetCmd = &cobra.Command{
27+
Use: "set <key> <value>",
28+
Short: "Set a configuration value",
29+
Long: `Sets a global configuration value.
30+
31+
Available keys:
32+
dns_mode - DNS resolution mode: "hosts" or "dnsmasq"
33+
default_php - Default PHP version for new projects (e.g., "8.2")
34+
tld - Top-level domain for local dev (default: "test")
35+
portainer - Enable Portainer Docker UI: "true" or "false"`,
36+
Args: cobra.ExactArgs(2),
37+
RunE: runConfigSet,
38+
}
39+
40+
var configInitCmd = &cobra.Command{
41+
Use: "init",
42+
Short: "Initialize global configuration",
43+
Long: "Creates the global configuration file with defaults",
44+
RunE: runConfigInit,
45+
}
46+
47+
func init() {
48+
configCmd.AddCommand(configShowCmd)
49+
configCmd.AddCommand(configSetCmd)
50+
configCmd.AddCommand(configInitCmd)
51+
rootCmd.AddCommand(configCmd)
52+
}
53+
54+
func runConfigShow(cmd *cobra.Command, args []string) error {
55+
homeDir, err := os.UserHomeDir()
56+
if err != nil {
57+
return err
58+
}
59+
60+
cfg, err := config.LoadGlobalConfig(homeDir)
61+
if err != nil {
62+
cli.PrintError("Failed to load config: %v", err)
63+
return nil
64+
}
65+
66+
cli.PrintTitle("MageBox Global Configuration")
67+
fmt.Println()
68+
69+
configPath := config.GlobalConfigPath(homeDir)
70+
if config.GlobalConfigExists(homeDir) {
71+
fmt.Printf("Config file: %s\n", cli.Path(configPath))
72+
} else {
73+
fmt.Printf("Config file: %s (using defaults)\n", cli.Subtitle("not created"))
74+
}
75+
fmt.Println()
76+
77+
fmt.Printf(" %-14s %s\n", "dns_mode:", cli.Highlight(cfg.DNSMode))
78+
fmt.Printf(" %-14s %s\n", "default_php:", cli.Highlight(cfg.DefaultPHP))
79+
fmt.Printf(" %-14s %s\n", "tld:", cli.Highlight(cfg.TLD))
80+
fmt.Printf(" %-14s %s\n", "portainer:", cli.Highlight(fmt.Sprintf("%v", cfg.Portainer)))
81+
fmt.Printf(" %-14s %s\n", "auto_start:", cli.Highlight(fmt.Sprintf("%v", cfg.AutoStart)))
82+
83+
fmt.Println(cli.Header("Default Services"))
84+
if cfg.DefaultServices.MySQL != "" {
85+
fmt.Printf(" %-14s %s\n", "mysql:", cli.Highlight(cfg.DefaultServices.MySQL))
86+
}
87+
if cfg.DefaultServices.MariaDB != "" {
88+
fmt.Printf(" %-14s %s\n", "mariadb:", cli.Highlight(cfg.DefaultServices.MariaDB))
89+
}
90+
fmt.Printf(" %-14s %s\n", "redis:", cli.Highlight(fmt.Sprintf("%v", cfg.DefaultServices.Redis)))
91+
if cfg.DefaultServices.OpenSearch != "" {
92+
fmt.Printf(" %-14s %s\n", "opensearch:", cli.Highlight(cfg.DefaultServices.OpenSearch))
93+
}
94+
fmt.Printf(" %-14s %s\n", "rabbitmq:", cli.Highlight(fmt.Sprintf("%v", cfg.DefaultServices.RabbitMQ)))
95+
fmt.Printf(" %-14s %s\n", "mailpit:", cli.Highlight(fmt.Sprintf("%v", cfg.DefaultServices.Mailpit)))
96+
97+
return nil
98+
}
99+
100+
func runConfigSet(cmd *cobra.Command, args []string) error {
101+
key := args[0]
102+
value := args[1]
103+
104+
homeDir, err := os.UserHomeDir()
105+
if err != nil {
106+
return err
107+
}
108+
109+
cfg, err := config.LoadGlobalConfig(homeDir)
110+
if err != nil {
111+
cli.PrintError("Failed to load config: %v", err)
112+
return nil
113+
}
114+
115+
switch key {
116+
case "dns_mode":
117+
if value != "hosts" && value != "dnsmasq" {
118+
cli.PrintError("Invalid value for dns_mode. Use 'hosts' or 'dnsmasq'")
119+
return nil
120+
}
121+
cfg.DNSMode = value
122+
case "default_php":
123+
cfg.DefaultPHP = value
124+
case "tld":
125+
cfg.TLD = value
126+
case "portainer":
127+
cfg.Portainer = (value == "true" || value == "1" || value == "yes")
128+
case "auto_start":
129+
cfg.AutoStart = (value == "true" || value == "1" || value == "yes")
130+
default:
131+
cli.PrintError("Unknown configuration key: %s", key)
132+
fmt.Println()
133+
cli.PrintInfo("Available keys: dns_mode, default_php, tld, portainer, auto_start")
134+
return nil
135+
}
136+
137+
if err := config.SaveGlobalConfig(homeDir, cfg); err != nil {
138+
cli.PrintError("Failed to save config: %v", err)
139+
return nil
140+
}
141+
142+
cli.PrintSuccess("Configuration updated: %s = %s", key, value)
143+
return nil
144+
}
145+
146+
func runConfigInit(cmd *cobra.Command, args []string) error {
147+
homeDir, err := os.UserHomeDir()
148+
if err != nil {
149+
return err
150+
}
151+
152+
configPath := config.GlobalConfigPath(homeDir)
153+
154+
if config.GlobalConfigExists(homeDir) {
155+
cli.PrintWarning("Configuration already exists at %s", configPath)
156+
return nil
157+
}
158+
159+
if err := config.InitGlobalConfig(homeDir); err != nil {
160+
cli.PrintError("Failed to initialize config: %v", err)
161+
return nil
162+
}
163+
164+
cli.PrintSuccess("Created global configuration at %s", configPath)
165+
fmt.Println()
166+
cli.PrintInfo("Edit the file or use " + cli.Command("magebox config set <key> <value>"))
167+
return nil
168+
}

0 commit comments

Comments
 (0)