cli: make bundled help self-describing
This commit is contained in:
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user