// Command agentctl is a CLI for inspecting and managing agents. package main import ( "fmt" "os" "github.com/spf13/cobra" "github.com/enmanuel/agents/internal/config" ) func main() { root := &cobra.Command{ Use: "agentctl", Short: "Manage and inspect agents", } root.AddCommand( listCmd(), validateCmd(), ) if err := root.Execute(); err != nil { os.Exit(1) } } func listCmd() *cobra.Command { return &cobra.Command{ Use: "list [config.yaml...]", Short: "List agents from config files", RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 0 { return fmt.Errorf("provide at least one config file") } for _, path := range args { cfg, err := config.Load(path) if err != nil { fmt.Fprintf(os.Stderr, "error: %s: %v\n", path, err) continue } enabled := "enabled" if !cfg.Agent.Enabled { enabled = "disabled" } fmt.Printf("%-20s %-10s %-10s %s\n", cfg.Agent.ID, cfg.Agent.Version, enabled, cfg.Agent.Description, ) } return nil }, } } func validateCmd() *cobra.Command { return &cobra.Command{ Use: "validate [config.yaml...]", Short: "Validate agent config files", RunE: func(cmd *cobra.Command, args []string) error { allOK := true for _, path := range args { _, err := config.Load(path) if err != nil { fmt.Fprintf(os.Stderr, "FAIL %s: %v\n", path, err) allOK = false } else { fmt.Printf("OK %s\n", path) } } if !allOK { os.Exit(1) } return nil }, } }