Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix description of subcommand more consistent #1054

Merged
merged 1 commit into from Jan 29, 2020

Conversation

itchyny
Copy link
Contributor

@itchyny itchyny commented Jan 28, 2020

What type of PR is this?

(REQUIRED)

  • bug
  • cleanup
  • documentation
  • feature

What this PR does / why we need it:

Consider a cli with subcommands. I want to specify descriptions for both cmd task -h and cmd task list -h.

package main

import (
	"fmt"
	"log"
	"os"

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

func main() {
	app := &cli.App{
		Commands: []*cli.Command{
			&cli.Command{
				Name:    "task",
				Aliases: []string{"a"},
				Usage:   "task commands",
				Description: `This is a description of task.
   For example, bla bla bla...`,
				Action: func(c *cli.Context) error {
					fmt.Println("tasks")
					return nil
				},
				Subcommands: []*cli.Command{
					&cli.Command{
						Name:  "list",
						Usage: "list tasks",
						Description: `This is a description of listing tasks.
   For example, bla bla bla...`,
						Action: func(c *cli.Context) error {
							fmt.Println("list tasks")
							return nil
						},
					},
				},
			},
		},
	}

	err := app.Run(os.Args)
	if err != nil {
		log.Fatal(err)
	}
}

Current behavior

When I run the command, I got the following results. Note that the description of go run . task -h appears at unexpected position.

 % go run . task -h
NAME:
   mycmd task - This is a description of task.
   For example, bla bla bla...

USAGE:
   mycmd task command [command options] [arguments...]

COMMANDS:
   list     list tasks
   help, h  Shows a list of commands or help for one command

OPTIONS:
   --help, -h  show help (default: false)

 % go run . task list -h # is fine!
NAME:
   mycmd task list - list tasks

USAGE:
   mycmd task list [command options] [arguments...]

DESCRIPTION:
   This is a description of listing tasks.
   For example, bla bla bla...

OPTIONS:
   --help, -h  show help (default: false)

Expected bahavior

I think this is more consistent. Shows both [command] - {{Usage}} and DESCRIPTION: {{Description}}.

 % go run . task -h
NAME:
   mycmd task - task commands

USAGE:
   mycmd task command [command options] [arguments...]

DESCRIPTION:
   This is a description of task.
   For example, bla bla bla...

COMMANDS:
   list     list tasks
   help, h  Shows a list of commands or help for one command

OPTIONS:
   --help, -h  show help (default: false)

 % go run . task list -h
NAME:
   mycmd task list - list tasks

USAGE:
   mycmd task list [command options] [arguments...]

DESCRIPTION:
   This is a description of listing tasks.
   For example, bla bla bla...

OPTIONS:
   --help, -h  show help (default: false)

Which issue(s) this PR fixes:

This pull request fixes the above problem.

Special notes for your reviewer:

Testing

(fill-in or delete this section)

Release Notes

(REQUIRED)


@itchyny itchyny requested a review from a team as a code owner January 28, 2020 08:51
@itchyny itchyny requested review from saschagrunert and rliebz and removed request for a team January 28, 2020 08:51
@codecov
Copy link

codecov bot commented Jan 28, 2020

Codecov Report

Merging #1054 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1054   +/-   ##
=======================================
  Coverage   72.83%   72.83%           
=======================================
  Files          33       33           
  Lines        2474     2474           
=======================================
  Hits         1802     1802           
  Misses        565      565           
  Partials      107      107

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3f8c3bc...aed5577. Read the comment docs.

Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants