First commit of golang CLI.
This commit is contained in:
93
wild-cli/internal/external/manager.go
vendored
Normal file
93
wild-cli/internal/external/manager.go
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
package external
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Manager coordinates external tools
|
||||
type Manager struct {
|
||||
kubectl *KubectlTool
|
||||
talosctl *TalosctlTool
|
||||
restic *ResticTool
|
||||
tools map[string]Tool
|
||||
}
|
||||
|
||||
// NewManager creates a new tool manager
|
||||
func NewManager() *Manager {
|
||||
kubectl := NewKubectlTool()
|
||||
talosctl := NewTalosctlTool()
|
||||
restic := NewResticTool()
|
||||
|
||||
tools := map[string]Tool{
|
||||
"kubectl": kubectl,
|
||||
"talosctl": talosctl,
|
||||
"restic": restic,
|
||||
}
|
||||
|
||||
return &Manager{
|
||||
kubectl: kubectl,
|
||||
talosctl: talosctl,
|
||||
restic: restic,
|
||||
tools: tools,
|
||||
}
|
||||
}
|
||||
|
||||
// Kubectl returns the kubectl tool
|
||||
func (m *Manager) Kubectl() *KubectlTool {
|
||||
return m.kubectl
|
||||
}
|
||||
|
||||
// Talosctl returns the talosctl tool
|
||||
func (m *Manager) Talosctl() *TalosctlTool {
|
||||
return m.talosctl
|
||||
}
|
||||
|
||||
// Restic returns the restic tool
|
||||
func (m *Manager) Restic() *ResticTool {
|
||||
return m.restic
|
||||
}
|
||||
|
||||
// CheckTools verifies that required tools are available
|
||||
func (m *Manager) CheckTools(ctx context.Context, required []string) error {
|
||||
missing := make([]string, 0)
|
||||
|
||||
for _, toolName := range required {
|
||||
tool, exists := m.tools[toolName]
|
||||
if !exists {
|
||||
missing = append(missing, toolName)
|
||||
continue
|
||||
}
|
||||
|
||||
if !tool.IsInstalled() {
|
||||
missing = append(missing, toolName)
|
||||
}
|
||||
}
|
||||
|
||||
if len(missing) > 0 {
|
||||
return fmt.Errorf("missing required tools: %v", missing)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetToolVersion returns the version of a tool
|
||||
func (m *Manager) GetToolVersion(toolName string) (string, error) {
|
||||
tool, exists := m.tools[toolName]
|
||||
if !exists {
|
||||
return "", fmt.Errorf("tool %s not found", toolName)
|
||||
}
|
||||
|
||||
return tool.Version()
|
||||
}
|
||||
|
||||
// ListTools returns information about all tools
|
||||
func (m *Manager) ListTools() map[string]bool {
|
||||
status := make(map[string]bool)
|
||||
|
||||
for name, tool := range m.tools {
|
||||
status[name] = tool.IsInstalled()
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
Reference in New Issue
Block a user