Skip to content

help subcommand doesn't show subcommands of topic #764

@nhooyr

Description

@nhooyr

With example code:

package main

import (
	"fmt"
	"os"

	"gopkg.in/urfave/cli.v2"
)

func main() {
	app := &cli.App{
		Commands: []*cli.Command{
			{
				Name:    "add",
				Aliases: []string{"a"},
				Usage:   "add a task to the list",
				Action:  func(c *cli.Context) error {
					fmt.Println("added task: ", c.Args().First())
					return nil
				},
			},
			{
				Name:    "complete",
				Aliases: []string{"c"},
				Usage:   "complete a task on the list",
				Action:  func(c *cli.Context) error {
					fmt.Println("completed task: ", c.Args().First())
					return nil
				},
			},
			{
				Name:        "template",
				Aliases:     []string{"t"},
				Usage:       "options for task templates",
				Subcommands: []*cli.Command{
					{
						Name:  "add",
						Usage: "add a new template",
						Action: func(c *cli.Context) error {
							fmt.Println("new task template: ", c.Args().First())
							return nil
						},
					},
					{
						Name:  "remove",
						Usage: "remove an existing template",
						Action: func(c *cli.Context) error {
							fmt.Println("removed task template: ", c.Args().First())
							return nil
						},
					},
				},
			},
		},
	}

	app.Run(os.Args)
}

gives

$ go run scratch.go help template
NAME:
   scratch template - options for task templates

USAGE:
   scratch template [arguments...]

Whereas this shows the subcommands

NAME:
   scratch template - options for task templates

USAGE:
   scratch template [global options] command [command options] [arguments...]

VERSION:
   0.0.0

COMMANDS:
     add      add a new template
     remove   remove an existing template
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help (default: false)
   --version, -v  print the version (default: false)

Output should be the same in both cases imo

edit: lol, not sure what the second command is supposed to be. probably --help flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions