package cmd import ( "fmt" "os" "git.wntrmute.dev/kyle/arca/internal/config" "github.com/spf13/cobra" ) var configCmd = &cobra.Command{ Use: "config", Short: "Manage arca configuration", } var configCheckCmd = &cobra.Command{ Use: "check", Short: "Validate the config file", RunE: runConfigCheck, } func init() { configCmd.AddCommand(configCheckCmd) rootCmd.AddCommand(configCmd) } func runConfigCheck(cmd *cobra.Command, args []string) error { cfg := config.Load() if len(cfg.Devices) == 0 { fmt.Println("No devices configured.") return nil } errs := config.Validate(cfg) if len(errs) == 0 { fmt.Printf("Config OK (%d device(s))\n", len(cfg.Devices)) return nil } for _, e := range errs { fmt.Fprintln(os.Stderr, e) } return fmt.Errorf("config has %d issue(s)", len(errs)) }