Merge remote-tracking branch 'origin/v2' into declarativeness
This commit is contained in:
commit
99621d571e
14
app.go
14
app.go
@ -128,13 +128,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)
|
||||||
|
|
||||||
@ -143,7 +136,6 @@ func (a *App) Setup() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//append version/help flags
|
|
||||||
if a.EnableBashCompletion {
|
if a.EnableBashCompletion {
|
||||||
a.appendFlag(BashCompletionFlag)
|
a.appendFlag(BashCompletionFlag)
|
||||||
}
|
}
|
||||||
@ -151,6 +143,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
|
||||||
|
12
app_test.go
12
app_test.go
@ -1131,7 +1131,8 @@ func TestApp_Run_Categories(t *testing.T) {
|
|||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
app := &App{
|
app := &App{
|
||||||
Name: "categories",
|
Name: "categories",
|
||||||
|
HideHelp: true,
|
||||||
Commands: []*Command{
|
Commands: []*Command{
|
||||||
{
|
{
|
||||||
Name: "command1",
|
Name: "command1",
|
||||||
@ -1181,7 +1182,8 @@ func TestApp_Run_Categories(t *testing.T) {
|
|||||||
|
|
||||||
func TestApp_VisibleCategories(t *testing.T) {
|
func TestApp_VisibleCategories(t *testing.T) {
|
||||||
app := &App{
|
app := &App{
|
||||||
Name: "visible-categories",
|
Name: "visible-categories",
|
||||||
|
HideHelp: true,
|
||||||
Commands: []*Command{
|
Commands: []*Command{
|
||||||
{
|
{
|
||||||
Name: "command1",
|
Name: "command1",
|
||||||
@ -1221,7 +1223,8 @@ func TestApp_VisibleCategories(t *testing.T) {
|
|||||||
expect(t, expected, app.VisibleCategories())
|
expect(t, expected, app.VisibleCategories())
|
||||||
|
|
||||||
app = &App{
|
app = &App{
|
||||||
Name: "visible-categories",
|
Name: "visible-categories",
|
||||||
|
HideHelp: true,
|
||||||
Commands: []*Command{
|
Commands: []*Command{
|
||||||
{
|
{
|
||||||
Name: "command1",
|
Name: "command1",
|
||||||
@ -1256,7 +1259,8 @@ func TestApp_VisibleCategories(t *testing.T) {
|
|||||||
expect(t, expected, app.VisibleCategories())
|
expect(t, expected, app.VisibleCategories())
|
||||||
|
|
||||||
app = &App{
|
app = &App{
|
||||||
Name: "visible-categories",
|
Name: "visible-categories",
|
||||||
|
HideHelp: true,
|
||||||
Commands: []*Command{
|
Commands: []*Command{
|
||||||
{
|
{
|
||||||
Name: "command1",
|
Name: "command1",
|
||||||
|
17
help_test.go
17
help_test.go
@ -140,6 +140,23 @@ func Test_helpCommand_Action_ErrorIfNoTopic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_helpCommand_InHelpOutput(t *testing.T) {
|
||||||
|
app := &App{}
|
||||||
|
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 := &App{}
|
app := &App{}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user