Solizardking/clawd-bot / .agents/skills/golang-cli
golang-cli
VerifiedGolang CLI application development. Use when building, modifying, or reviewing a Go CLI tool — especially for command structure, flag handling, configuration layering, version embedding, exit codes, I/O patterns, signal handling, shell completion, argument validation, and CLI unit testing. Also triggers when code uses cobra, viper, or urfave/cli. For cobra-specific APIs → See `samber/cc-skills-golang@golang-spf13-cobra` skill; for viper configuration layering → See `samber/cc-skills-golang@golang-spf13-viper` skill.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 10.0 KB |
| assets/examples/args.go | script | 1020 B |
| assets/examples/cli_test.go | script | 1.2 KB |
| assets/examples/completion.go | script | 1.6 KB |
| assets/examples/config.go | script | 1.7 KB |
| assets/examples/exit_codes.go | script | 494 B |
| assets/examples/flags.go | script | 1.3 KB |
| assets/examples/main.go | script | 120 B |
| assets/examples/output.go | script | 1.7 KB |
| assets/examples/root.go | script | 1.8 KB |
| assets/examples/serve.go | script | 735 B |
| assets/examples/signal.go | script | 831 B |
| assets/examples/version.go | script | 871 B |
| evals/evals.json | config | 16.0 KB |
assets/examples/root.go
View on GitHub// cmd/myapp/root.go
package main
import (
"fmt"
"log/slog"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var cfgFile string
var rootCmd = &cobra.Command{
Use: "myapp",
Short: "A brief description of your application",
Long: "A longer description with usage examples.",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return initConfig()
},
SilenceUsage: true, // don't print usage on errors from RunE
SilenceErrors: true, // handle error printing yourself
}
func Execute() error {
return rootCmd.Execute()
}
func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default $HOME/.myapp.yaml)")
rootCmd.PersistentFlags().String("log-level", "info", "log level (debug, info, warn, error)")
viper.BindPFlag("log-level", rootCmd.PersistentFlags().Lookup("log-level"))
}
func initConfig() error {
if cfgFile != "" {
viper.SetConfigFile(cfgFile)
} else {
home, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("finding home directory: %w", err)
}
viper.AddConfigPath(home)
viper.AddConfigPath(".")
viper.SetConfigName(".myapp")
viper.SetConfigType("yaml")
}
viper.SetEnvPrefix("MYAPP")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
return fmt.Errorf("reading config: %w", err)
}
}
// Set up logging based on config
level := slog.LevelInfo
switch strings.ToLower(viper.GetString("log-level")) {
case "debug":
level = slog.LevelDebug
case "warn":
level = slog.LevelWarn
case "error":
level = slog.LevelError
}
slog.SetDefault(slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: level})))
return nil
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |