feat: migrate from docopt to cobra for CLI argument parsing

Replace docopt-go with spf13/cobra, giving cheat a built-in
`--completion` flag that dynamically generates shell completions for
bash, zsh, fish, and powershell. This replaces the manually-maintained
static completion scripts and resolves the root cause of multiple
completion issues (#768, #705, #633, #632, #476).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Christopher Allen Lane
2026-02-15 17:33:47 -05:00
parent ca1ec0e38d
commit 9b92261604
119 changed files with 14204 additions and 3127 deletions

View File

@@ -7,7 +7,7 @@ import (
)
// Color indicates whether colorization should be applied to the output
func (c *Config) Color(opts map[string]interface{}) bool {
func (c *Config) Color(forceColorize bool) bool {
// default to the colorization specified in the configs...
colorize := c.Colorize
@@ -18,7 +18,7 @@ func (c *Config) Color(opts map[string]interface{}) bool {
}
// ... *unless* the --colorize flag was passed
if opts["--colorize"] == true {
if forceColorize {
colorize = true
}

View File

@@ -10,13 +10,11 @@ func TestColor(t *testing.T) {
// mock a config
conf := Config{}
opts := map[string]interface{}{"--colorize": false}
if conf.Color(opts) {
t.Errorf("failed to respect --colorize (false)")
if conf.Color(false) {
t.Errorf("failed to respect forceColorize (false)")
}
opts = map[string]interface{}{"--colorize": true}
if !conf.Color(opts) {
t.Errorf("failed to respect --colorize (true)")
if !conf.Color(true) {
t.Errorf("failed to respect forceColorize (true)")
}
}

20
internal/config/env.go Normal file
View File

@@ -0,0 +1,20 @@
package config
import (
"os"
"runtime"
"strings"
)
// EnvVars reads environment variables into a map of strings.
func EnvVars() map[string]string {
envvars := map[string]string{}
for _, e := range os.Environ() {
pair := strings.SplitN(e, "=", 2)
if runtime.GOOS == "windows" {
pair[0] = strings.ToUpper(pair[0])
}
envvars[pair[0]] = pair[1]
}
return envvars
}