package util import ( "context" "fmt" "os" "github.com/spf13/cobra" "github.com/wild-cloud/wild-cli/internal/environment" "github.com/wild-cloud/wild-cli/internal/external" "github.com/wild-cloud/wild-cli/internal/output" ) func runStatus(cmd *cobra.Command, args []string) error { output.Header("Wild Cloud Status") // Initialize environment env := environment.New() // Check if we're in a project directory detected, _ := env.DetectWCHome() if detected != "" { env.SetWCHome(detected) output.Success("Found Wild Cloud project: " + detected) } else { output.Warning("Not in a Wild Cloud project directory") } // Check environment output.Info("\n=== Environment ===") if env.WCRoot() != "" { output.Success("WC_ROOT: " + env.WCRoot()) } else { output.Warning("WC_ROOT: Not set") } if env.WCHome() != "" { output.Success("WC_HOME: " + env.WCHome()) } else { output.Warning("WC_HOME: Not set") } // Check external tools output.Info("\n=== External Tools ===") toolManager := external.NewManager() tools := toolManager.ListTools() for toolName, installed := range tools { if installed { version, err := toolManager.GetToolVersion(toolName) if err != nil { output.Success(fmt.Sprintf("%-12s: Installed (version unknown)", toolName)) } else { output.Success(fmt.Sprintf("%-12s: %s", toolName, version)) } } else { output.Warning(fmt.Sprintf("%-12s: Not installed", toolName)) } } // Check project structure if in project if env.WCHome() != "" { output.Info("\n=== Project Structure ===") // Check config files if fileExists(env.ConfigPath()) { output.Success("config.yaml: Found") } else { output.Warning("config.yaml: Missing") } if fileExists(env.SecretsPath()) { output.Success("secrets.yaml: Found") } else { output.Warning("secrets.yaml: Missing") } if dirExists(env.AppsDir()) { output.Success("apps/ directory: Found") } else { output.Warning("apps/ directory: Missing") } if dirExists(env.WildCloudDir()) { output.Success(".wildcloud/ directory: Found") } else { output.Warning(".wildcloud/ directory: Missing") } // Check cluster connectivity if tools are available if tools["kubectl"] { output.Info("\n=== Cluster Status ===") kubectl := toolManager.Kubectl() ctx := context.Background() nodes, err := kubectl.GetNodes(ctx) if err != nil { output.Warning("Cluster: Not accessible (" + err.Error() + ")") } else { output.Success("Cluster: Connected") output.Info("Nodes:\n" + string(nodes)) } } } output.Info("\n=== Summary ===") if detected != "" { output.Success("Wild Cloud project is properly configured") } else { output.Warning("Run 'wild setup scaffold' to initialize a project") } return nil } // Helper functions func fileExists(path string) bool { info, err := os.Stat(path) return err == nil && !info.IsDir() } func dirExists(path string) bool { info, err := os.Stat(path) return err == nil && info.IsDir() }