cli: make bundled help self-describing

This commit is contained in:
2026-03-22 23:37:38 +08:00
parent 5859ff219e
commit 4d8c90eb26
49 changed files with 792 additions and 29 deletions
@@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
"strings"
"sync"
)
@@ -30,6 +31,21 @@ func Execute(args []string, stdout, stderr io.Writer) int {
usage()
return 2
}
if args[0] == "help" {
if len(args) == 1 {
usage()
return 0
}
if err := runCommand([]string{args[1], "--help"}); err != nil {
_, _ = fmt.Fprintln(commandStderr, err)
return 1
}
return 0
}
if isHelpToken(args[0]) {
usage()
return 0
}
if err := runCommand(args); err != nil {
_, _ = fmt.Fprintln(commandStderr, err)
@@ -39,6 +55,15 @@ func Execute(args []string, stdout, stderr io.Writer) int {
return 0
}
func isHelpToken(value string) bool {
switch strings.TrimSpace(value) {
case "-h", "--help":
return true
default:
return false
}
}
func runCommand(args []string) error {
switch args[0] {
case "init":