commit
ef7fea16bc
14
app.go
14
app.go
@ -113,13 +113,6 @@ func (a *App) Setup() {
|
|||||||
}
|
}
|
||||||
a.Commands = newCmds
|
a.Commands = newCmds
|
||||||
|
|
||||||
a.Categories = newCommandCategories()
|
|
||||||
for _, command := range a.Commands {
|
|
||||||
a.Categories.AddCommand(command.Category, command)
|
|
||||||
}
|
|
||||||
sort.Sort(a.Categories.(*commandCategories))
|
|
||||||
|
|
||||||
// append help to commands
|
|
||||||
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
|
if a.Command(helpCommand.Name) == nil && !a.HideHelp {
|
||||||
a.appendCommand(helpCommand)
|
a.appendCommand(helpCommand)
|
||||||
|
|
||||||
@ -128,7 +121,6 @@ func (a *App) Setup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//append version/help flags
|
|
||||||
if a.EnableBashCompletion {
|
if a.EnableBashCompletion {
|
||||||
a.appendFlag(BashCompletionFlag)
|
a.appendFlag(BashCompletionFlag)
|
||||||
}
|
}
|
||||||
@ -136,6 +128,12 @@ func (a *App) Setup() {
|
|||||||
if !a.HideVersion {
|
if !a.HideVersion {
|
||||||
a.appendFlag(VersionFlag)
|
a.appendFlag(VersionFlag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.Categories = newCommandCategories()
|
||||||
|
for _, command := range a.Commands {
|
||||||
|
a.Categories.AddCommand(command.Category, command)
|
||||||
|
}
|
||||||
|
sort.Sort(a.Categories.(*commandCategories))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -1123,6 +1123,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",
|
||||||
@ -1173,6 +1174,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",
|
||||||
@ -1212,6 +1214,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",
|
||||||
@ -1246,6 +1249,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
@ -143,6 +143,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