From 39f62a3d3fd594ab8fd7a087a499a6a2e2aa866a Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 22 Feb 2024 20:25:37 -0500 Subject: [PATCH] Cli now displays usage information for subcommands correctly --- cli/cli.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/cli.go b/cli/cli.go index 2b3b2e3..447475e 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -68,7 +68,7 @@ func (this *Cli) AddSub (name string, sub *Cli) { func (this *Cli) Parse (args []string) (*Cli, error) { // try to find a sub-command if this.Sub != nil && len(args) > 0 { - if sub, ok := this.Sub[args[0]]; ok { + if sub, ok := this.Sub[args[1]]; ok { return sub.Parse(args[1:]) } } @@ -184,10 +184,10 @@ func (this *Cli) LongFlag (long string) (*Flag, bool) { func (this *Cli) Usage () { // syntax fmt.Fprint(os.Stderr, "Usage:") - if this.Super != "" { - fmt.Fprint(os.Stderr, "", this.Super) - } fmt.Fprint(os.Stderr, " ", os.Args[0]) + if this.Super != "" { + fmt.Fprint(os.Stderr, " ", this.Super) + } hasSubCommands := this.Sub != nil && len(this.Sub) > 0 if hasSubCommands { fmt.Fprint(os.Stderr, " [COMMAND]")