Split all cmd/* packages for maintainability, following the pattern established in cmd/php. Each package now has: - Main file with styles (using cmd/shared) and Add*Commands function - Separate files for logical command groupings Packages refactored: - cmd/dev: 13 files (was 2779 lines in one file) - cmd/build: 5 files (was 913 lines) - cmd/setup: 6 files (was 961 lines) - cmd/go: 5 files (was 655 lines) - cmd/pkg: 5 files (was 634 lines) - cmd/vm: 4 files (was 717 lines) - cmd/ai: 5 files (was 800 lines) - cmd/docs: 5 files (was 379 lines) - cmd/doctor: 5 files (was 301 lines) - cmd/test: 3 files (was 429 lines) - cmd/ci: 5 files (was 272 lines) All packages now import shared styles from cmd/shared instead of redefining them locally. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
package gocmd
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
|
|
"github.com/leaanthony/clir"
|
|
)
|
|
|
|
func addGoFmtCommand(parent *clir.Command) {
|
|
var (
|
|
fix bool
|
|
diff bool
|
|
check bool
|
|
)
|
|
|
|
fmtCmd := parent.NewSubCommand("fmt", "Format Go code")
|
|
fmtCmd.LongDescription("Format Go code using gofmt or goimports.\n\n" +
|
|
"Examples:\n" +
|
|
" core go fmt # Check formatting\n" +
|
|
" core go fmt --fix # Fix formatting\n" +
|
|
" core go fmt --diff # Show diff")
|
|
|
|
fmtCmd.BoolFlag("fix", "Fix formatting in place", &fix)
|
|
fmtCmd.BoolFlag("diff", "Show diff of changes", &diff)
|
|
fmtCmd.BoolFlag("check", "Check only, exit 1 if not formatted", &check)
|
|
|
|
fmtCmd.Action(func() error {
|
|
args := []string{}
|
|
if fix {
|
|
args = append(args, "-w")
|
|
}
|
|
if diff {
|
|
args = append(args, "-d")
|
|
}
|
|
if !fix && !diff {
|
|
args = append(args, "-l")
|
|
}
|
|
args = append(args, ".")
|
|
|
|
// Try goimports first, fall back to gofmt
|
|
var cmd *exec.Cmd
|
|
if _, err := exec.LookPath("goimports"); err == nil {
|
|
cmd = exec.Command("goimports", args...)
|
|
} else {
|
|
cmd = exec.Command("gofmt", args...)
|
|
}
|
|
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
return cmd.Run()
|
|
})
|
|
}
|
|
|
|
func addGoLintCommand(parent *clir.Command) {
|
|
var fix bool
|
|
|
|
lintCmd := parent.NewSubCommand("lint", "Run golangci-lint")
|
|
lintCmd.LongDescription("Run golangci-lint on the codebase.\n\n" +
|
|
"Examples:\n" +
|
|
" core go lint\n" +
|
|
" core go lint --fix")
|
|
|
|
lintCmd.BoolFlag("fix", "Fix issues automatically", &fix)
|
|
|
|
lintCmd.Action(func() error {
|
|
args := []string{"run"}
|
|
if fix {
|
|
args = append(args, "--fix")
|
|
}
|
|
|
|
cmd := exec.Command("golangci-lint", args...)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
return cmd.Run()
|
|
})
|
|
}
|