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

Function TestHelpFlagInHelp

command_test.go:1092–1104  ·  view source on GitHub ↗

TestHelpFlagInHelp checks, if '--help' flag is shown in help for child (executing `parent help child`), that has no other flags. Related to https://github.com/spf13/cobra/issues/302.

(t *testing.T)

Source from the content-addressed store, hash-verified

1090// that has no other flags.
1091// Related to https://github.com/spf13/cobra/issues/302.
1092func TestHelpFlagInHelp(t *testing.T) {
1093 parentCmd := &Command{Use: "parent", Run: func(*Command, []string) {}}
1094
1095 childCmd := &Command{Use: "child", Run: func(*Command, []string) {}}
1096 parentCmd.AddCommand(childCmd)
1097
1098 output, err := executeCommand(parentCmd, "help", "child")
1099 if err != nil {
1100 t.Errorf("Unexpected error: %v", err)
1101 }
1102
1103 checkStringContains(t, output, "[flags]")
1104}
1105
1106func TestFlagsInUsage(t *testing.T) {
1107 rootCmd := &Command{Use: "root", Args: NoArgs, Run: func(*Command, []string) {}}

Callers

nothing calls this directly

Calls 3

AddCommandMethod · 0.95
executeCommandFunction · 0.85
checkStringContainsFunction · 0.70

Tested by

no test coverage detected