Merge pull request #463 from urfave/help-command-categorization
Help command categorization
This commit is contained in:
commit
4205e9c4ee
14
app.go
14
app.go
@ -140,13 +140,6 @@ func (a *App) Setup() {
|
|||||||
}
|
}
|
||||||
a.Commands = newCmds
|
a.Commands = newCmds
|
||||||
|
|
||||||
a.categories = CommandCategories{}
|
|
||||||
for _, command := range a.Commands {
|
|
||||||
a.categories = a.categories.AddCommand(command.Category, command)
|
|
||||||
}
|
|
||||||
sort.Sort(a.categories)
|
|
||||||
|
|
||||||
// append help to commands
|
|
||||||
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
|
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
|
||||||
a.Commands = append(a.Commands, helpCommand)
|
a.Commands = append(a.Commands, helpCommand)
|
||||||
if (HelpFlag != BoolFlag{}) {
|
if (HelpFlag != BoolFlag{}) {
|
||||||
@ -154,7 +147,6 @@ func (a *App) Setup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//append version/help flags
|
|
||||||
if a.EnableBashCompletion {
|
if a.EnableBashCompletion {
|
||||||
a.appendFlag(BashCompletionFlag)
|
a.appendFlag(BashCompletionFlag)
|
||||||
}
|
}
|
||||||
@ -162,6 +154,12 @@ func (a *App) Setup() {
|
|||||||
if !a.HideVersion {
|
if !a.HideVersion {
|
||||||
a.appendFlag(VersionFlag)
|
a.appendFlag(VersionFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.categories = CommandCategories{}
|
||||||
|
for _, command := range a.Commands {
|
||||||
|
a.categories = a.categories.AddCommand(command.Category, command)
|
||||||
|
}
|
||||||
|
sort.Sort(a.categories)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run is the entry point to the cli app. Parses the arguments slice and routes
|
// Run is the entry point to the cli app. Parses the arguments slice and routes
|
||||||
|
@ -1125,6 +1125,7 @@ func TestApp_Run_Version(t *testing.T) {
|
|||||||
func TestApp_Run_Categories(t *testing.T) {
|
func TestApp_Run_Categories(t *testing.T) {
|
||||||
app := NewApp()
|
app := NewApp()
|
||||||
app.Name = "categories"
|
app.Name = "categories"
|
||||||
|
app.HideHelp = true
|
||||||
app.Commands = []Command{
|
app.Commands = []Command{
|
||||||
{
|
{
|
||||||
Name: "command1",
|
Name: "command1",
|
||||||
@ -1174,6 +1175,7 @@ func TestApp_Run_Categories(t *testing.T) {
|
|||||||
func TestApp_VisibleCategories(t *testing.T) {
|
func TestApp_VisibleCategories(t *testing.T) {
|
||||||
app := NewApp()
|
app := NewApp()
|
||||||
app.Name = "visible-categories"
|
app.Name = "visible-categories"
|
||||||
|
app.HideHelp = true
|
||||||
app.Commands = []Command{
|
app.Commands = []Command{
|
||||||
{
|
{
|
||||||
Name: "command1",
|
Name: "command1",
|
||||||
@ -1213,6 +1215,7 @@ func TestApp_VisibleCategories(t *testing.T) {
|
|||||||
|
|
||||||
app = NewApp()
|
app = NewApp()
|
||||||
app.Name = "visible-categories"
|
app.Name = "visible-categories"
|
||||||
|
app.HideHelp = true
|
||||||
app.Commands = []Command{
|
app.Commands = []Command{
|
||||||
{
|
{
|
||||||
Name: "command1",
|
Name: "command1",
|
||||||
@ -1247,6 +1250,7 @@ func TestApp_VisibleCategories(t *testing.T) {
|
|||||||
|
|
||||||
app = NewApp()
|
app = NewApp()
|
||||||
app.Name = "visible-categories"
|
app.Name = "visible-categories"
|
||||||
|
app.HideHelp = true
|
||||||
app.Commands = []Command{
|
app.Commands = []Command{
|
||||||
{
|
{
|
||||||
Name: "command1",
|
Name: "command1",
|
||||||
|
17
help_test.go
17
help_test.go
@ -141,6 +141,23 @@ func Test_helpCommand_Action_ErrorIfNoTopic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_helpCommand_InHelpOutput(t *testing.T) {
|
||||||
|
app := NewApp()
|
||||||
|
output := &bytes.Buffer{}
|
||||||
|
app.Writer = output
|
||||||
|
app.Run([]string{"test", "--help"})
|
||||||
|
|
||||||
|
s := output.String()
|
||||||
|
|
||||||
|
if strings.Contains(s, "\nCOMMANDS:\nGLOBAL OPTIONS:\n") {
|
||||||
|
t.Fatalf("empty COMMANDS section detected: %q", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(s, "help, h") {
|
||||||
|
t.Fatalf("missing \"help, h\": %q", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Test_helpSubcommand_Action_ErrorIfNoTopic(t *testing.T) {
|
func Test_helpSubcommand_Action_ErrorIfNoTopic(t *testing.T) {
|
||||||
app := NewApp()
|
app := NewApp()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user