Cli now displays usage information for subcommands correctly

This commit is contained in:
Sasha Koshka 2024-02-22 20:25:37 -05:00
parent 367f4c5d34
commit 39f62a3d3f
1 changed files with 4 additions and 4 deletions

View File

@ -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]")