From claude-resources
Go CLI development with Cobra and Viper. Subcommands, flags, config precedence, signal handling, exit codes. 100% Go-specific.
npx claudepluginhub deandum/claude-resources --plugin go-skillsThis skill uses the workspace's default tool permissions.
Use stdlib `flag` for single-command tools. Cobra for multi-command CLIs.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Guides agent creation for Claude Code plugins with file templates, frontmatter specs (name, description, model), triggering examples, system prompts, and best practices.
Use stdlib flag for single-command tools. Cobra for multi-command CLIs.
mycli/
├── cmd/
│ ├── root.go
│ ├── get.go
│ └── create.go
├── main.go # cmd.Execute()
└── go.mod
var rootCmd = &cobra.Command{
Use: "mycli",
Short: "Brief description",
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err); os.Exit(1)
}
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose"))
}
var getCmd = &cobra.Command{
Use: "get [resource]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return performGet(args[0], output, limit)
},
}
func init() {
rootCmd.AddCommand(getCmd)
getCmd.Flags().StringVarP(&output, "output", "o", "table", "Output format")
getCmd.Flags().IntVarP(&limit, "limit", "l", 10, "Limit results")
}
Flags > Env Vars > Config File > Defaults
viper.BindPFlag("api-url", cmd.Flags().Lookup("api-url"))
viper.BindEnv("api-url", "MYCLI_API_URL")
viper.AutomaticEnv()
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
return doWork(ctx)
0 success, 1 error, 2 usage error. Map error types to specific codes.
RunE — making commands read from globals (var cfg Config at package level) creates hidden coupling between subcommands and makes testing impossible. Prefer passing dependencies through a *Config closure built in init(), or use cobra.Command's SetContext/Context() to thread state through the call chain.--help works for all commands and subcommands0 success, 1 error, 2 usage errorSIGINT/SIGTERM)