Consolidate subcommand registration

This commit is contained in:
2021-02-02 18:37:26 -06:00
parent 1a99e03f88
commit f63c90db2b
9 changed files with 178 additions and 216 deletions

View File

@ -1,23 +1,10 @@
package lumecmd
import (
"flag"
"fmt"
"sort"
)
func init() {
RegisterCommand("help", Command{
Func: HelpCmd,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("help", flag.ExitOnError)
return fs
}(),
Use: "<command>",
Short: "Show help for a command",
})
}
func HelpCmd(args CmdArgs) (int, error) {
argv := args.Flags.Args()
@ -47,7 +34,7 @@ func printHelp(commands map[string]Command) {
fmt.Println("\ncommands:")
sort.Strings(keys)
for _, k = range keys {
for _, k := range keys {
c := commands[k]
fmt.Printf(" %-*s %s\n", maxLen, c.Name, c.Short)
}