Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Generate Cobra/Viper-based Go CLI applications with persistent flags, subcommands, and configuration management. Creates production-ready Go CLI with modern patterns.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 2% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 44% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 55% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 610% | 0% |
| case-15 | ✗→✓ | ▲ Improved | 194% | 0% |
Generate a complete Cobra CLI application with Viper configuration, proper Go module structure, and best practices.
Invoke this skill when you need to:
| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | projectName | string | Yes | Name of the CLI project (kebab-case) | | modulePath | string | Yes | Go module path (e.g., github.com/user/project) | | description | string | Yes | Short description of the CLI | | commands | array | No | List of commands to scaffold | | useViper | boolean | No | Integrate Viper config (default: true) | | useCobra | boolean | No | Use cobra-cli generator patterns (default: true) |
json{ "commands": [ { "name": "serve", "description": "Start the server", "persistentFlags": [ { "name": "config", "shorthand": "c", "type": "string", "usage": "config file path" } ], "flags": [ { "name": "port", "shorthand": "p", "type": "int", "default": 8080, "usage": "port to listen on" } ], "subcommands": ["start", "stop", "status"] } ] }
<projectName>/
├── go.mod
├── go.sum
├── main.go
├── README.md
├── .goreleaser.yaml
├── cmd/
│ ├── root.go # Root command with Viper
│ ├── serve.go # Serve command
│ ├── version.go # Version command
│ └── completion.go # Completion command
├── internal/
│ ├── config/
│ │ └── config.go # Configuration structures
│ ├── server/
│ │ └── server.go # Server implementation
│ └── logger/
│ └── logger.go # Logging setup
├── pkg/
│ └── utils/
│ └── helpers.go # Public utilities
└── tests/
└── cmd/
└── root_test.gogopackage cmd import ( "fmt" "os" "github.com/spf13/cobra" "github.com/spf13/viper" ) var cfgFile string var rootCmd = &cobra.Command{ Use: "<projectName>", Short: "<description>", Long: `<long description>`, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { return initConfig() }, } func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } func init() { rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.<projectName>.yaml)") rootCmd.PersistentFlags().BoolP("verbose", "v", false, "verbose output") viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose")) } func initConfig() error { if cfgFile != "" { viper.SetConfigFile(cfgFile) } else { home, err := os.UserHomeDir() cobra.CheckErr(err) viper.AddConfigPath(home) viper.SetConfigType("yaml") viper.SetConfigName(".<projectName>") } viper.AutomaticEnv() viper.SetEnvPrefix("<PROJECT_NAME>") if err := viper.ReadInConfig(); err == nil { fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed()) } return nil }
gopackage cmd import ( "fmt" "github.com/spf13/cobra" "github.com/spf13/viper" ) var serveCmd = &cobra.Command{ Use: "serve", Short: "Start the server", Long: `Start the server with the specified configuration.`, RunE: func(cmd *cobra.Command, args []string) error { port := viper.GetInt("port") host := viper.GetString("host") fmt.Printf("Starting server on %s:%d\n", host, port) return nil }, } func init() { rootCmd.AddCommand(serveCmd) serveCmd.Flags().IntP("port", "p", 8080, "port to listen on") serveCmd.Flags().String("host", "localhost", "host to bind to") viper.BindPFlag("port", serveCmd.Flags().Lookup("port")) viper.BindPFlag("host", serveCmd.Flags().Lookup("host")) }
gomodule github.com/user/<projectName> go 1.21 require ( github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.0 )
Other measured skills in the registry, with their headline benchmark lift.