MCPcopy
hub / github.com/spf13/cobra / TestSetHelpCommand

Function TestSetHelpCommand

command_test.go:998–1019  ·  command_test.go::TestSetHelpCommand
(t *testing.T)

Source from the content-addressed store, hash-verified

996}
997
998func TestSetHelpCommand(t *testing.T) {
999 c := &Command{Use: "c", Run: emptyRun}
1000 c.AddCommand(&Command{Use: "empty", Run: emptyRun})
1001
1002 expected := "WORKS"
1003 c.SetHelpCommand(&Command{
1004 Use: "help [command]",
1005 Short: "Help about any command",
1006 Long: `Help provides help for any command in the application.
1007 Simply type ` + c.Name() + ` help [path to command] for full details.`,
1008 Run: func(c *Command, _ []string) { c.Print(expected) },
1009 })
1010
1011 got, err := executeCommand(c, "help")
1012 if err != nil {
1013 t.Errorf("Unexpected error: %v", err)
1014 }
1015
1016 if got != expected {
1017 t.Errorf("Expected to contain %q, got %q", expected, got)
1018 }
1019}
1020
1021func TestSetHelpTemplate(t *testing.T) {
1022 rootCmd := &Command{Use: "root", Run: emptyRun}

Callers

nothing calls this directly

Calls 5

AddCommandMethod · 0.95
SetHelpCommandMethod · 0.95
NameMethod · 0.95
PrintMethod · 0.95
executeCommandFunction · 0.85

Tested by

no test coverage detected