|
|
@ -90,10 +90,10 @@ func ExampleAppHelp() {
|
|
|
|
app.Run(os.Args)
|
|
|
|
app.Run(os.Args)
|
|
|
|
// Output:
|
|
|
|
// Output:
|
|
|
|
// NAME:
|
|
|
|
// NAME:
|
|
|
|
// describeit - use it to see a description
|
|
|
|
// greet describeit - use it to see a description
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// USAGE:
|
|
|
|
// USAGE:
|
|
|
|
// command describeit [arguments...]
|
|
|
|
// greet describeit [arguments...]
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// DESCRIPTION:
|
|
|
|
// DESCRIPTION:
|
|
|
|
// This is how we describe describeit the function
|
|
|
|
// This is how we describe describeit the function
|
|
|
@ -737,13 +737,75 @@ func TestApp_Run_SubcommandFullPath(t *testing.T) {
|
|
|
|
app := NewApp()
|
|
|
|
app := NewApp()
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
app.Writer = buf
|
|
|
|
app.Writer = buf
|
|
|
|
|
|
|
|
app.Name = "command"
|
|
|
|
|
|
|
|
subCmd := Command{
|
|
|
|
|
|
|
|
Name: "bar",
|
|
|
|
|
|
|
|
Usage: "does bar things",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := Command{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Description: "foo commands",
|
|
|
|
|
|
|
|
Subcommands: []Command{subCmd},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Commands = []Command{cmd}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := app.Run([]string{"command", "foo", "bar", "--help"})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output := buf.String()
|
|
|
|
|
|
|
|
if !strings.Contains(output, "command foo bar - does bar things") {
|
|
|
|
|
|
|
|
t.Errorf("expected full path to subcommand: %s", output)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(output, "command foo bar [arguments...]") {
|
|
|
|
|
|
|
|
t.Errorf("expected full path to subcommand: %s", output)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestApp_Run_SubcommandHelpName(t *testing.T) {
|
|
|
|
|
|
|
|
app := NewApp()
|
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
|
|
|
app.Writer = buf
|
|
|
|
|
|
|
|
app.Name = "command"
|
|
|
|
|
|
|
|
subCmd := Command{
|
|
|
|
|
|
|
|
Name: "bar",
|
|
|
|
|
|
|
|
HelpName: "custom",
|
|
|
|
|
|
|
|
Usage: "does bar things",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := Command{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Description: "foo commands",
|
|
|
|
|
|
|
|
Subcommands: []Command{subCmd},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Commands = []Command{cmd}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := app.Run([]string{"command", "foo", "bar", "--help"})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output := buf.String()
|
|
|
|
|
|
|
|
if !strings.Contains(output, "custom - does bar things") {
|
|
|
|
|
|
|
|
t.Errorf("expected HelpName for subcommand: %s", output)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(output, "custom [arguments...]") {
|
|
|
|
|
|
|
|
t.Errorf("expected HelpName to subcommand: %s", output)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestApp_Run_CommandHelpName(t *testing.T) {
|
|
|
|
|
|
|
|
app := NewApp()
|
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
|
|
|
app.Writer = buf
|
|
|
|
|
|
|
|
app.Name = "command"
|
|
|
|
subCmd := Command{
|
|
|
|
subCmd := Command{
|
|
|
|
Name: "bar",
|
|
|
|
Name: "bar",
|
|
|
|
Usage: "does bar things",
|
|
|
|
Usage: "does bar things",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd := Command{
|
|
|
|
cmd := Command{
|
|
|
|
Name: "foo",
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
HelpName: "custom",
|
|
|
|
Description: "foo commands",
|
|
|
|
Description: "foo commands",
|
|
|
|
Subcommands: []Command{subCmd},
|
|
|
|
Subcommands: []Command{subCmd},
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -755,7 +817,7 @@ func TestApp_Run_SubcommandFullPath(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
output := buf.String()
|
|
|
|
output := buf.String()
|
|
|
|
if !strings.Contains(output, "foo bar - does bar things") {
|
|
|
|
if !strings.Contains(output, "command foo bar - does bar things") {
|
|
|
|
t.Errorf("expected full path to subcommand: %s", output)
|
|
|
|
t.Errorf("expected full path to subcommand: %s", output)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !strings.Contains(output, "command foo bar [arguments...]") {
|
|
|
|
if !strings.Contains(output, "command foo bar [arguments...]") {
|
|
|
@ -763,6 +825,37 @@ func TestApp_Run_SubcommandFullPath(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestApp_Run_CommandSubcommandHelpName(t *testing.T) {
|
|
|
|
|
|
|
|
app := NewApp()
|
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
|
|
|
app.Writer = buf
|
|
|
|
|
|
|
|
app.Name = "base"
|
|
|
|
|
|
|
|
subCmd := Command{
|
|
|
|
|
|
|
|
Name: "bar",
|
|
|
|
|
|
|
|
HelpName: "custom",
|
|
|
|
|
|
|
|
Usage: "does bar things",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := Command{
|
|
|
|
|
|
|
|
Name: "foo",
|
|
|
|
|
|
|
|
Description: "foo commands",
|
|
|
|
|
|
|
|
Subcommands: []Command{subCmd},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
app.Commands = []Command{cmd}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := app.Run([]string{"command", "foo", "--help"})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output := buf.String()
|
|
|
|
|
|
|
|
if !strings.Contains(output, "base foo - foo commands") {
|
|
|
|
|
|
|
|
t.Errorf("expected full path to subcommand: %s", output)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(output, "base foo command [command options] [arguments...]") {
|
|
|
|
|
|
|
|
t.Errorf("expected full path to subcommand: %s", output)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestApp_Run_Help(t *testing.T) {
|
|
|
|
func TestApp_Run_Help(t *testing.T) {
|
|
|
|
var helpArguments = [][]string{{"boom", "--help"}, {"boom", "-h"}, {"boom", "help"}}
|
|
|
|
var helpArguments = [][]string{{"boom", "--help"}, {"boom", "-h"}, {"boom", "help"}}
|
|
|
|
|
|
|
|
|
|
|
|