Skip to content

v3: cluttered usage text for subcommands #2135

Closed

Description

@burdiyan

The default help message for subcommands that don't have further subcommands seems cluttered with extra [command [command options]] part.

Example

Got:

NAME:
   app hello - Prints hello message.

USAGE:
   app hello [command [command options]] name

OPTIONS:
   --lang string
   --help, -h     show help

GLOBAL OPTIONS:
   --global-flag string

Want:

NAME:
   app hello - Prints hello message.

USAGE:
   app hello [options] name

OPTIONS:
   --lang string
   --help, -h     show help

GLOBAL OPTIONS:
   --global-flag string

Reproduction code:

Playground.

package main

import (
	"bytes"
	"context"
	"fmt"

	"github.com/urfave/cli/v3"
)

func main() {
	var b bytes.Buffer
	app := &cli.Command{
		Name:  "app",
		Usage: "Sample app to reproduce a cluttered subcommand help.",
		Action: func(ctx context.Context, cmd *cli.Command) error {
			fmt.Println("root command")
			return nil
		},
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name: "global-flag",
			},
		},
		Commands: []*cli.Command{
			{
				Name:  "hello",
				Usage: "Prints hello message.",
				Action: func(ctx context.Context, cmd *cli.Command) error {
					fmt.Println("Hello", cmd.StringArg("name"))
					return nil
				},
				Arguments: []cli.Argument{
					&cli.StringArg{
						Name: "name",
					},
				},
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name: "lang",
					},
				},
			},
		},
		Writer: &b,
	}

	if err := app.Run(context.Background(), []string{"app", "hello", "--help"}); err != nil {
		panic(err)
	}

	fmt.Println(b.String())
}

Activity

  1. zzspoon commented on May 19, 2025

    @zzspoon
    Contributor

    in template.go usageTemplate

    {{if .VisibleFlags}} [command [command options]]{{end}}

    should be

    {{if .VisibleFlags}} [options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}}

  2. dearchap commented on May 19, 2025

    @dearchap
    Contributor

    @zzspoon want to submit a PR for this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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