Skip to content

v3: cluttered usage text for subcommands #2135

@burdiyan

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())
}

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