wand/help.go

82 lines
1.3 KiB
Go
Raw Normal View History

2025-08-18 14:24:31 +02:00
package wand
import (
"fmt"
"io"
"strings"
)
type (
synopsis struct{}
docOptions struct{}
docArguments struct{}
docSubcommands struct{}
)
type doc struct {
name string
synopsis synopsis
description string
options docOptions
arguments docArguments
subcommands docSubcommands
}
func help() Cmd {
return Cmd{
name: "help",
isHelp: true,
}
}
func insertHelp(cmd Cmd) Cmd {
var hasHelpCmd bool
for i, sc := range cmd.subcommands {
cmd.subcommands[i] = insertHelp(sc)
if cmd.name == "help" {
hasHelpCmd = true
}
}
if !hasHelpCmd {
cmd.subcommands = append(cmd.subcommands, help())
}
return cmd
}
func hasHelpSubcommand(cmd Cmd) bool {
for _, sc := range cmd.subcommands {
if sc.isHelp {
return true
}
}
return false
}
func hasCustomHelpOption(cmd Cmd) bool {
mf := mapFields(cmd.impl)
_, has := mf["help"]
return has
}
func suggestHelp(out io.Writer, cmd Cmd, fullCommand []string) {
if hasHelpSubcommand(cmd) {
fmt.Fprintf(out, "Show help:\n%s help\n", strings.Join(fullCommand, " "))
return
}
if !hasCustomHelpOption(cmd) {
fmt.Fprintf(out, "Show help:\n%s --help\n", strings.Join(fullCommand, " "))
return
}
}
func constructDoc(cmd Cmd, fullCommand []string) doc {
return doc{}
}
func showHelp(out io.Writer, cmd Cmd, fullCommand []string) {
}