Download coderank/units/cobra.jsonl from paintedwolfcode/bialy-dataset: direct link, hf CLI and curl.
- Browser
- Download file 299 kB
-
https://huggingface.co/datasets/paintedwolfcode/bialy-dataset/resolve/main/coderank/units/cobra.jsonl
- Command line
-
hf download hf://datasets/paintedwolfcode/bialy-dataset/coderank/units/cobra.jsonl
-
curl -L -o cobra.jsonl https://huggingface.co/datasets/paintedwolfcode/bialy-dataset/resolve/main/coderank/units/cobra.jsonl
299 kB
| {"repo":"cobra","file":"Makefile","line":1,"symbol":"BIN","kind":"variable","lang":"make","code":"BIN=\"./bin\""} | |
| {"repo":"cobra","file":"Makefile","line":2,"symbol":"SRC","kind":"variable","lang":"make","code":"SRC=$(shell find . -name \"*.go\")"} | |
| {"repo":"cobra","file":"Makefile","line":8,"symbol":".PHONY","kind":"target","lang":"make","code":".PHONY: fmt lint test install_deps clean"} | |
| {"repo":"cobra","file":"Makefile","line":10,"symbol":"default","kind":"target","lang":"make","code":"default: all"} | |
| {"repo":"cobra","file":"Makefile","line":12,"symbol":"all","kind":"target","lang":"make","code":"all: fmt test"} | |
| {"repo":"cobra","file":"Makefile","line":14,"symbol":"fmt","kind":"target","lang":"make","code":"fmt:\n\t$(info ******************** checking formatting ********************)\n\t@test -z $(shell gofmt -l $(SRC)) || (gofmt -d $(SRC); exit 1)"} | |
| {"repo":"cobra","file":"Makefile","line":18,"symbol":"lint","kind":"target","lang":"make","code":"lint:\n\t$(info ******************** running lint tools ********************)\n\tgolangci-lint run -v"} | |
| {"repo":"cobra","file":"Makefile","line":22,"symbol":"test","kind":"target","lang":"make","code":"test: install_deps\n\t$(info ******************** running tests ********************)\n\tgo test -v $(GO_TEST_FLAGS) ./..."} | |
| {"repo":"cobra","file":"Makefile","line":26,"symbol":"richtest","kind":"target","lang":"make","code":"richtest: install_deps\n\t$(info ******************** running tests with kyoh86/richgo ********************)\n\trichgo test -v $(GO_TEST_FLAGS) ./..."} | |
| {"repo":"cobra","file":"Makefile","line":30,"symbol":"install_deps","kind":"target","lang":"make","code":"install_deps:\n\t$(info ******************** downloading dependencies ********************)\n\tgo get -v ./..."} | |
| {"repo":"cobra","file":"Makefile","line":34,"symbol":"clean","kind":"target","lang":"make","code":"clean:\n\trm -rf $(BIN)"} | |
| {"repo":"cobra","file":"active_help.go","line":23,"symbol":"activeHelpMarker","kind":"constant","lang":"go","code":"activeHelpMarker = \"_activeHelp_ \""} | |
| {"repo":"cobra","file":"active_help.go","line":26,"symbol":"activeHelpEnvVarSuffix","kind":"constant","lang":"go","doc":"The below values should not be changed: programs will be using them explicitly in their user documentation, and users will be using them explicitly.","code":"activeHelpEnvVarSuffix = \"ACTIVE_HELP\""} | |
| {"repo":"cobra","file":"active_help.go","line":27,"symbol":"activeHelpGlobalEnvVar","kind":"constant","lang":"go","code":"activeHelpGlobalEnvVar = configEnvVarGlobalPrefix + \"_\" + activeHelpEnvVarSuffix"} | |
| {"repo":"cobra","file":"active_help.go","line":28,"symbol":"activeHelpGlobalDisable","kind":"constant","lang":"go","code":"activeHelpGlobalDisable = \"0\""} | |
| {"repo":"cobra","file":"active_help.go","line":38,"symbol":"AppendActiveHelp","kind":"function","lang":"go","doc":"Such strings will be processed by the completion script and will be shown as ActiveHelp to the user. The array parameter should be the array that will contain the completions. This function can be called multiple times before and/or after completions are added to the array. Each time this function is called with the same array, the new ActiveHelp line will be shown below the previous ones when completion is triggered.","code":"func AppendActiveHelp(compArray []Completion, activeHelpStr string) []Completion {\n\treturn append(compArray, fmt.Sprintf(\"%s%s\", activeHelpMarker, activeHelpStr))\n}"} | |
| {"repo":"cobra","file":"active_help.go","line":47,"symbol":"GetActiveHelpConfig","kind":"function","lang":"go","doc":"GetActiveHelpConfig returns the value of the ActiveHelp environment variable <PROGRAM>_ACTIVE_HELP where <PROGRAM> is the name of the root command in upper case, with all non-ASCII-alphanumeric characters replaced by `_`. It will always return \"0\" if the global environment variable COBRA_ACTIVE_HELP is set to \"0\".","code":"func GetActiveHelpConfig(cmd *Command) string {\n\tactiveHelpCfg := os.Getenv(activeHelpGlobalEnvVar)\n\tif activeHelpCfg != activeHelpGlobalDisable {\n\t\tactiveHelpCfg = os.Getenv(activeHelpEnvVar(cmd.Root().Name()))\n\t}\n\treturn activeHelpCfg\n}"} | |
| {"repo":"cobra","file":"active_help.go","line":58,"symbol":"activeHelpEnvVar","kind":"function","lang":"go","doc":"activeHelpEnvVar returns the name of the program-specific ActiveHelp environment variable. It has the format <PROGRAM>_ACTIVE_HELP where <PROGRAM> is the name of the root command in upper case, with all non-ASCII-alphanumeric characters replaced by `_`.","code":"func activeHelpEnvVar(name string) string {\n\treturn configEnvVar(name, activeHelpEnvVarSuffix)\n}"} | |
| {"repo":"cobra","file":"active_help_test.go","line":25,"symbol":"activeHelpMessage","kind":"constant","lang":"go","code":"activeHelpMessage = \"This is an activeHelp message\""} | |
| {"repo":"cobra","file":"active_help_test.go","line":26,"symbol":"activeHelpMessage2","kind":"constant","lang":"go","code":"activeHelpMessage2 = \"This is the rest of the activeHelp message\""} | |
| {"repo":"cobra","file":"active_help_test.go","line":29,"symbol":"TestActiveHelpAlone","kind":"function","lang":"go","code":"func TestActiveHelpAlone(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\n\tactiveHelpFunc := func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\tcomps := AppendActiveHelp(nil, activeHelpMessage)\n\t\treturn comps, ShellCompDirectiveDefault\n\t}\n\n\t// Test that activeHelp can be added to a root command\n\trootCmd.ValidArgsFunction = activeHelpFunc\n\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\tfmt.Sprintf(\"%s%s\", activeHelpMarker, activeHelpMessage),\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\trootCmd.ValidArgsFunction = nil\n\n\t// Test that activeHelp can be added to a child command\n\tchildCmd := &Command{\n\t\tUse: \"thechild\",\n\t\tShort: \"The child command\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\tchildCmd.ValidArgsFunction = activeHelpFunc\n\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"thechild\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)"} | |
| {"repo":"cobra","file":"active_help_test.go","line":84,"symbol":"TestActiveHelpWithComps","kind":"function","lang":"go","code":"func TestActiveHelpWithComps(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\n\tchildCmd := &Command{\n\t\tUse: \"thechild\",\n\t\tShort: \"The child command\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\t// Test that activeHelp can be added following other completions\n\tchildCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\tcomps := []string{\"first\", \"second\"}\n\t\tcomps = AppendActiveHelp(comps, activeHelpMessage)\n\t\treturn comps, ShellCompDirectiveDefault\n\t}\n\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"thechild\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"first\",\n\t\t\"second\",\n\t\tfmt.Sprintf(\"%s%s\", activeHelpMarker, activeHelpMessage),\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that activeHelp can be added preceding other completions\n\tchildCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\tvar comps []string\n\t\tcomps = AppendA"} | |
| {"repo":"cobra","file":"active_help_test.go","line":122,"symbol":"comps","kind":"variable","lang":"go","code":"comps []string"} | |
| {"repo":"cobra","file":"active_help_test.go","line":169,"symbol":"TestMultiActiveHelp","kind":"function","lang":"go","code":"func TestMultiActiveHelp(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\n\tchildCmd := &Command{\n\t\tUse: \"thechild\",\n\t\tShort: \"The child command\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\t// Test that multiple activeHelp message can be added\n\tchildCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\tcomps := AppendActiveHelp(nil, activeHelpMessage)\n\t\tcomps = AppendActiveHelp(comps, activeHelpMessage2)\n\t\treturn comps, ShellCompDirectiveNoFileComp\n\t}\n\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"thechild\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\tfmt.Sprintf(\"%s%s\", activeHelpMarker, activeHelpMessage),\n\t\tfmt.Sprintf(\"%s%s\", activeHelpMarker, activeHelpMessage2),\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that multiple activeHelp messages can be used along with completions\n\tchildCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, Shell"} | |
| {"repo":"cobra","file":"active_help_test.go","line":231,"symbol":"TestActiveHelpForFlag","kind":"function","lang":"go","code":"func TestActiveHelpForFlag(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\tflagname := \"flag\"\n\trootCmd.Flags().String(flagname, \"\", \"A flag\")\n\n\t// Test that multiple activeHelp message can be added\n\t_ = rootCmd.RegisterFlagCompletionFunc(flagname, func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\tcomps := []string{\"first\"}\n\t\tcomps = AppendActiveHelp(comps, activeHelpMessage)\n\t\tcomps = append(comps, \"second\")\n\t\tcomps = AppendActiveHelp(comps, activeHelpMessage2)\n\t\treturn comps, ShellCompDirectiveNoFileComp\n\t})\n\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"--flag\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"first\",\n\t\tfmt.Sprintf(\"%s%s\", activeHelpMarker, activeHelpMessage),\n\t\t\"second\",\n\t\tfmt.Sprintf(\"%s%s\", activeHelpMarker, activeHelpMessage2),\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n}"} | |
| {"repo":"cobra","file":"active_help_test.go","line":266,"symbol":"TestConfigActiveHelp","kind":"function","lang":"go","code":"func TestConfigActiveHelp(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\n\tchildCmd := &Command{\n\t\tUse: \"thechild\",\n\t\tShort: \"The child command\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\tactiveHelpCfg := \"someconfig,anotherconfig\"\n\t// Set the variable that the user would be setting\n\tos.Setenv(activeHelpEnvVar(rootCmd.Name()), activeHelpCfg)\n\n\tchildCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\treceivedActiveHelpCfg := GetActiveHelpConfig(cmd)\n\t\tif receivedActiveHelpCfg != activeHelpCfg {\n\t\t\tt.Errorf(\"expected activeHelpConfig: %q, but got: %q\", activeHelpCfg, receivedActiveHelpCfg)\n\t\t}\n\t\treturn nil, ShellCompDirectiveDefault\n\t}\n\n\t_, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"thechild\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\t// Test active help config for a flag\n\tactiveHelpCfg = \"a config for a flag\"\n\t// Set the variable that the completions scripts will be setting\n\tos.Setenv(activeHelpEnvVar(rootCmd.Name()), activeHelpCfg)\n\n\tflagname := \"flag\"\n\tchildCmd.Flags().String(flagname, \"\", \"A flag\")\n\n\t// Test that multiple activeHelp message c"} | |
| {"repo":"cobra","file":"active_help_test.go","line":319,"symbol":"TestDisableActiveHelp","kind":"function","lang":"go","code":"func TestDisableActiveHelp(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\n\tchildCmd := &Command{\n\t\tUse: \"thechild\",\n\t\tShort: \"The child command\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\t// Test the disabling of activeHelp using the specific program\n\t// environment variable that the completions scripts will be setting.\n\t// Make sure the disabling value is \"0\" by hard-coding it in the tests;\n\t// this is for backwards-compatibility as programs will be using this value.\n\tos.Setenv(activeHelpEnvVar(rootCmd.Name()), \"0\")\n\n\tchildCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\tcomps := []string{\"first\"}\n\t\tcomps = AppendActiveHelp(comps, activeHelpMessage)\n\t\treturn comps, ShellCompDirectiveDefault\n\t}\n\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"thechild\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\tos.Unsetenv(activeHelpEnvVar(rootCmd.Name()))\n\n\t// Make sure there is no ActiveHelp in the output\n\texpected := strings.Join([]string{\n\t\t\"first\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expe"} | |
| {"repo":"cobra","file":"args.go","line":22,"symbol":"PositionalArgs","kind":"type","lang":"go","code":"type PositionalArgs func(cmd *Command, args []string) error"} | |
| {"repo":"cobra","file":"args.go","line":28,"symbol":"legacyArgs","kind":"function","lang":"go","doc":"legacyArgs validation has the following behaviour: - root commands with no subcommands can take arbitrary arguments - root commands with subcommands will do subcommand validity checking - subcommands will always accept arbitrary arguments","code":"func legacyArgs(cmd *Command, args []string) error {\n\t// no subcommand, always take args\n\tif !cmd.HasSubCommands() {\n\t\treturn nil\n\t}\n\n\t// root command with subcommands, do subcommand checking.\n\tif !cmd.HasParent() && len(args) > 0 {\n\t\treturn fmt.Errorf(\"unknown command %q for %q%s\", args[0], cmd.CommandPath(), cmd.findSuggestions(args[0]))\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"args.go","line":42,"symbol":"NoArgs","kind":"function","lang":"go","doc":"NoArgs returns an error if any args are included.","code":"func NoArgs(cmd *Command, args []string) error {\n\tif len(args) > 0 {\n\t\treturn fmt.Errorf(\"unknown command %q for %q\", args[0], cmd.CommandPath())\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"args.go","line":51,"symbol":"OnlyValidArgs","kind":"function","lang":"go","doc":"OnlyValidArgs returns an error if there are any positional args that are not in the `ValidArgs` field of `Command`","code":"func OnlyValidArgs(cmd *Command, args []string) error {\n\tif len(cmd.ValidArgs) > 0 {\n\t\t// Remove any description that may be included in ValidArgs.\n\t\t// A description is following a tab character.\n\t\tvalidArgs := make([]string, 0, len(cmd.ValidArgs))\n\t\tfor _, v := range cmd.ValidArgs {\n\t\t\tvalidArgs = append(validArgs, strings.SplitN(v, \"\\t\", 2)[0])\n\t\t}\n\t\tfor _, v := range args {\n\t\t\tif !stringInSlice(v, validArgs) {\n\t\t\t\treturn fmt.Errorf(\"invalid argument %q for %q%s\", v, cmd.CommandPath(), cmd.findSuggestions(args[0]))\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"args.go","line":69,"symbol":"NoDuplicateArgs","kind":"function","lang":"go","doc":"NoDuplicateArgs returns an error if there are any duplicate positional args.","code":"func NoDuplicateArgs(cmd *Command, args []string) error {\n\tseen := make(map[string]struct{}, len(args))\n\tfor _, arg := range args {\n\t\tif _, ok := seen[arg]; ok {\n\t\t\treturn fmt.Errorf(\"duplicate argument %q for %q\", arg, cmd.CommandPath())\n\t\t}\n\t\tseen[arg] = struct{}{}\n\t}\n\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"args.go","line":82,"symbol":"ArbitraryArgs","kind":"function","lang":"go","doc":"ArbitraryArgs never returns an error.","code":"func ArbitraryArgs(cmd *Command, args []string) error {\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"args.go","line":87,"symbol":"MinimumNArgs","kind":"function","lang":"go","doc":"MinimumNArgs returns an error if there is not at least N args.","code":"func MinimumNArgs(n int) PositionalArgs {\n\treturn func(cmd *Command, args []string) error {\n\t\tif len(args) < n {\n\t\t\treturn fmt.Errorf(\"requires at least %d arg(s), only received %d\", n, len(args))\n\t\t}\n\t\treturn nil\n\t}\n}"} | |
| {"repo":"cobra","file":"args.go","line":97,"symbol":"MaximumNArgs","kind":"function","lang":"go","doc":"MaximumNArgs returns an error if there are more than N args.","code":"func MaximumNArgs(n int) PositionalArgs {\n\treturn func(cmd *Command, args []string) error {\n\t\tif len(args) > n {\n\t\t\treturn fmt.Errorf(\"accepts at most %d arg(s), received %d\", n, len(args))\n\t\t}\n\t\treturn nil\n\t}\n}"} | |
| {"repo":"cobra","file":"args.go","line":107,"symbol":"ExactArgs","kind":"function","lang":"go","doc":"ExactArgs returns an error if there are not exactly n args.","code":"func ExactArgs(n int) PositionalArgs {\n\treturn func(cmd *Command, args []string) error {\n\t\tif len(args) != n {\n\t\t\treturn fmt.Errorf(\"accepts %d arg(s), received %d\", n, len(args))\n\t\t}\n\t\treturn nil\n\t}\n}"} | |
| {"repo":"cobra","file":"args.go","line":117,"symbol":"RangeArgs","kind":"function","lang":"go","doc":"RangeArgs returns an error if the number of args is not within the expected range.","code":"func RangeArgs(min int, max int) PositionalArgs {\n\treturn func(cmd *Command, args []string) error {\n\t\tif len(args) < min || len(args) > max {\n\t\t\treturn fmt.Errorf(\"accepts between %d and %d arg(s), received %d\", min, max, len(args))\n\t\t}\n\t\treturn nil\n\t}\n}"} | |
| {"repo":"cobra","file":"args.go","line":127,"symbol":"MatchAll","kind":"function","lang":"go","doc":"MatchAll allows combining several PositionalArgs to work in concert.","code":"func MatchAll(pargs ...PositionalArgs) PositionalArgs {\n\treturn func(cmd *Command, args []string) error {\n\t\tfor _, parg := range pargs {\n\t\t\tif err := parg(cmd, args); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t\treturn nil\n\t}\n}"} | |
| {"repo":"cobra","file":"args.go","line":142,"symbol":"ExactValidArgs","kind":"function","lang":"go","doc":"ExactValidArgs returns an error if there are not exactly N positional args OR there are any positional args that are not in the `ValidArgs` field of `Command` Deprecated: use MatchAll(ExactArgs(n), OnlyValidArgs) instead","code":"func ExactValidArgs(n int) PositionalArgs {\n\treturn MatchAll(ExactArgs(n), OnlyValidArgs)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":23,"symbol":"getCommand","kind":"function","lang":"go","code":"func getCommand(args PositionalArgs, withValid bool) *Command {\n\tc := &Command{\n\t\tUse: \"c\",\n\t\tArgs: args,\n\t\tRun: emptyRun,\n\t}\n\tif withValid {\n\t\tc.ValidArgs = []string{\"one\", \"two\", \"three\"}\n\t}\n\treturn c\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":35,"symbol":"expectSuccess","kind":"function","lang":"go","code":"func expectSuccess(output string, err error, t *testing.T) {\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Fatalf(\"Unexpected error: %v\", err)\n\t}\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":44,"symbol":"validOnlyWithInvalidArgs","kind":"function","lang":"go","code":"func validOnlyWithInvalidArgs(err error, t *testing.T) {\n\tif err == nil {\n\t\tt.Fatal(\"Expected an error\")\n\t}\n\tgot := err.Error()\n\texpected := `invalid argument \"a\" for \"c\"`\n\tif got != expected {\n\t\tt.Errorf(\"Expected: %q, got: %q\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":55,"symbol":"noArgsWithArgs","kind":"function","lang":"go","code":"func noArgsWithArgs(err error, t *testing.T, arg string) {\n\tif err == nil {\n\t\tt.Fatal(\"Expected an error\")\n\t}\n\tgot := err.Error()\n\texpected := `unknown command \"` + arg + `\" for \"c\"`\n\tif got != expected {\n\t\tt.Errorf(\"Expected: %q, got: %q\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":66,"symbol":"minimumNArgsWithLessArgs","kind":"function","lang":"go","code":"func minimumNArgsWithLessArgs(err error, t *testing.T) {\n\tif err == nil {\n\t\tt.Fatal(\"Expected an error\")\n\t}\n\tgot := err.Error()\n\texpected := \"requires at least 2 arg(s), only received 1\"\n\tif got != expected {\n\t\tt.Fatalf(\"Expected %q, got %q\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":77,"symbol":"maximumNArgsWithMoreArgs","kind":"function","lang":"go","code":"func maximumNArgsWithMoreArgs(err error, t *testing.T) {\n\tif err == nil {\n\t\tt.Fatal(\"Expected an error\")\n\t}\n\tgot := err.Error()\n\texpected := \"accepts at most 2 arg(s), received 3\"\n\tif got != expected {\n\t\tt.Fatalf(\"Expected %q, got %q\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":88,"symbol":"exactArgsWithInvalidCount","kind":"function","lang":"go","code":"func exactArgsWithInvalidCount(err error, t *testing.T) {\n\tif err == nil {\n\t\tt.Fatal(\"Expected an error\")\n\t}\n\tgot := err.Error()\n\texpected := \"accepts 2 arg(s), received 3\"\n\tif got != expected {\n\t\tt.Fatalf(\"Expected %q, got %q\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":99,"symbol":"rangeArgsWithInvalidCount","kind":"function","lang":"go","code":"func rangeArgsWithInvalidCount(err error, t *testing.T) {\n\tif err == nil {\n\t\tt.Fatal(\"Expected an error\")\n\t}\n\tgot := err.Error()\n\texpected := \"accepts between 2 and 4 arg(s), received 1\"\n\tif got != expected {\n\t\tt.Fatalf(\"Expected %q, got %q\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":110,"symbol":"noDuplicateArgsWithDuplicate","kind":"function","lang":"go","code":"func noDuplicateArgsWithDuplicate(err error, t *testing.T, arg string) {\n\tif err == nil {\n\t\tt.Fatal(\"Expected an error\")\n\t}\n\tgot := err.Error()\n\texpected := `duplicate argument \"` + arg + `\" for \"c\"`\n\tif got != expected {\n\t\tt.Errorf(\"Expected: %q, got: %q\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":123,"symbol":"TestNoArgs","kind":"function","lang":"go","code":"func TestNoArgs(t *testing.T) {\n\tc := getCommand(NoArgs, false)\n\toutput, err := executeCommand(c)\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":129,"symbol":"TestNoArgs_WithArgs","kind":"function","lang":"go","code":"func TestNoArgs_WithArgs(t *testing.T) {\n\tc := getCommand(NoArgs, false)\n\t_, err := executeCommand(c, \"one\")\n\tnoArgsWithArgs(err, t, \"one\")\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":135,"symbol":"TestNoArgs_WithValid_WithArgs","kind":"function","lang":"go","code":"func TestNoArgs_WithValid_WithArgs(t *testing.T) {\n\tc := getCommand(NoArgs, true)\n\t_, err := executeCommand(c, \"one\")\n\tnoArgsWithArgs(err, t, \"one\")\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":141,"symbol":"TestNoArgs_WithValid_WithInvalidArgs","kind":"function","lang":"go","code":"func TestNoArgs_WithValid_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(NoArgs, true)\n\t_, err := executeCommand(c, \"a\")\n\tnoArgsWithArgs(err, t, \"a\")\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":147,"symbol":"TestNoArgs_WithValidOnly_WithInvalidArgs","kind":"function","lang":"go","code":"func TestNoArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MatchAll(OnlyValidArgs, NoArgs), true)\n\t_, err := executeCommand(c, \"a\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":155,"symbol":"TestOnlyValidArgs","kind":"function","lang":"go","code":"func TestOnlyValidArgs(t *testing.T) {\n\tc := getCommand(OnlyValidArgs, true)\n\toutput, err := executeCommand(c, \"one\", \"two\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":161,"symbol":"TestOnlyValidArgs_WithInvalidArgs","kind":"function","lang":"go","code":"func TestOnlyValidArgs_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(OnlyValidArgs, true)\n\t_, err := executeCommand(c, \"a\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":169,"symbol":"TestNoDuplicateArgs","kind":"function","lang":"go","code":"func TestNoDuplicateArgs(t *testing.T) {\n\tc := getCommand(NoDuplicateArgs, false)\n\toutput, err := executeCommand(c, \"one\", \"two\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":175,"symbol":"TestNoDuplicateArgs_WithDuplicateArgs","kind":"function","lang":"go","code":"func TestNoDuplicateArgs_WithDuplicateArgs(t *testing.T) {\n\tc := getCommand(NoDuplicateArgs, false)\n\t_, err := executeCommand(c, \"one\", \"one\")\n\tnoDuplicateArgsWithDuplicate(err, t, \"one\")\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":181,"symbol":"TestNoDuplicateArgs_WithValid_WithDuplicateArgs","kind":"function","lang":"go","code":"func TestNoDuplicateArgs_WithValid_WithDuplicateArgs(t *testing.T) {\n\tc := getCommand(NoDuplicateArgs, true)\n\t_, err := executeCommand(c, \"one\", \"one\")\n\tnoDuplicateArgsWithDuplicate(err, t, \"one\")\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":187,"symbol":"TestNoDuplicateArgs_WithValidOnly_WithInvalidArgs","kind":"function","lang":"go","code":"func TestNoDuplicateArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MatchAll(OnlyValidArgs, NoDuplicateArgs), true)\n\t_, err := executeCommand(c, \"a\", \"a\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":195,"symbol":"TestArbitraryArgs","kind":"function","lang":"go","code":"func TestArbitraryArgs(t *testing.T) {\n\tc := getCommand(ArbitraryArgs, false)\n\toutput, err := executeCommand(c, \"a\", \"b\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":201,"symbol":"TestArbitraryArgs_WithValid","kind":"function","lang":"go","code":"func TestArbitraryArgs_WithValid(t *testing.T) {\n\tc := getCommand(ArbitraryArgs, true)\n\toutput, err := executeCommand(c, \"one\", \"two\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":207,"symbol":"TestArbitraryArgs_WithValid_WithInvalidArgs","kind":"function","lang":"go","code":"func TestArbitraryArgs_WithValid_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(ArbitraryArgs, true)\n\toutput, err := executeCommand(c, \"a\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":213,"symbol":"TestArbitraryArgs_WithValidOnly_WithInvalidArgs","kind":"function","lang":"go","code":"func TestArbitraryArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MatchAll(OnlyValidArgs, ArbitraryArgs), true)\n\t_, err := executeCommand(c, \"a\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":221,"symbol":"TestMinimumNArgs","kind":"function","lang":"go","code":"func TestMinimumNArgs(t *testing.T) {\n\tc := getCommand(MinimumNArgs(2), false)\n\toutput, err := executeCommand(c, \"a\", \"b\", \"c\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":227,"symbol":"TestMinimumNArgs_WithValid","kind":"function","lang":"go","code":"func TestMinimumNArgs_WithValid(t *testing.T) {\n\tc := getCommand(MinimumNArgs(2), true)\n\toutput, err := executeCommand(c, \"one\", \"three\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":233,"symbol":"TestMinimumNArgs_WithValid__WithInvalidArgs","kind":"function","lang":"go","code":"func TestMinimumNArgs_WithValid__WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MinimumNArgs(2), true)\n\toutput, err := executeCommand(c, \"a\", \"b\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":239,"symbol":"TestMinimumNArgs_WithValidOnly_WithInvalidArgs","kind":"function","lang":"go","code":"func TestMinimumNArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MatchAll(OnlyValidArgs, MinimumNArgs(2)), true)\n\t_, err := executeCommand(c, \"a\", \"b\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":245,"symbol":"TestMinimumNArgs_WithLessArgs","kind":"function","lang":"go","code":"func TestMinimumNArgs_WithLessArgs(t *testing.T) {\n\tc := getCommand(MinimumNArgs(2), false)\n\t_, err := executeCommand(c, \"a\")\n\tminimumNArgsWithLessArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":251,"symbol":"TestMinimumNArgs_WithLessArgs_WithValid","kind":"function","lang":"go","code":"func TestMinimumNArgs_WithLessArgs_WithValid(t *testing.T) {\n\tc := getCommand(MinimumNArgs(2), true)\n\t_, err := executeCommand(c, \"one\")\n\tminimumNArgsWithLessArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":257,"symbol":"TestMinimumNArgs_WithLessArgs_WithValid_WithInvalidArgs","kind":"function","lang":"go","code":"func TestMinimumNArgs_WithLessArgs_WithValid_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MinimumNArgs(2), true)\n\t_, err := executeCommand(c, \"a\")\n\tminimumNArgsWithLessArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":263,"symbol":"TestMinimumNArgs_WithLessArgs_WithValidOnly_WithInvalidArgs","kind":"function","lang":"go","code":"func TestMinimumNArgs_WithLessArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MatchAll(OnlyValidArgs, MinimumNArgs(2)), true)\n\t_, err := executeCommand(c, \"a\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":271,"symbol":"TestMaximumNArgs","kind":"function","lang":"go","code":"func TestMaximumNArgs(t *testing.T) {\n\tc := getCommand(MaximumNArgs(3), false)\n\toutput, err := executeCommand(c, \"a\", \"b\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":277,"symbol":"TestMaximumNArgs_WithValid","kind":"function","lang":"go","code":"func TestMaximumNArgs_WithValid(t *testing.T) {\n\tc := getCommand(MaximumNArgs(2), true)\n\toutput, err := executeCommand(c, \"one\", \"three\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":283,"symbol":"TestMaximumNArgs_WithValid_WithInvalidArgs","kind":"function","lang":"go","code":"func TestMaximumNArgs_WithValid_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MaximumNArgs(2), true)\n\toutput, err := executeCommand(c, \"a\", \"b\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":289,"symbol":"TestMaximumNArgs_WithValidOnly_WithInvalidArgs","kind":"function","lang":"go","code":"func TestMaximumNArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MatchAll(OnlyValidArgs, MaximumNArgs(2)), true)\n\t_, err := executeCommand(c, \"a\", \"b\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":295,"symbol":"TestMaximumNArgs_WithMoreArgs","kind":"function","lang":"go","code":"func TestMaximumNArgs_WithMoreArgs(t *testing.T) {\n\tc := getCommand(MaximumNArgs(2), false)\n\t_, err := executeCommand(c, \"a\", \"b\", \"c\")\n\tmaximumNArgsWithMoreArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":301,"symbol":"TestMaximumNArgs_WithMoreArgs_WithValid","kind":"function","lang":"go","code":"func TestMaximumNArgs_WithMoreArgs_WithValid(t *testing.T) {\n\tc := getCommand(MaximumNArgs(2), true)\n\t_, err := executeCommand(c, \"one\", \"three\", \"two\")\n\tmaximumNArgsWithMoreArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":307,"symbol":"TestMaximumNArgs_WithMoreArgs_WithValid_WithInvalidArgs","kind":"function","lang":"go","code":"func TestMaximumNArgs_WithMoreArgs_WithValid_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MaximumNArgs(2), true)\n\t_, err := executeCommand(c, \"a\", \"b\", \"c\")\n\tmaximumNArgsWithMoreArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":313,"symbol":"TestMaximumNArgs_WithMoreArgs_WithValidOnly_WithInvalidArgs","kind":"function","lang":"go","code":"func TestMaximumNArgs_WithMoreArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MatchAll(OnlyValidArgs, MaximumNArgs(2)), true)\n\t_, err := executeCommand(c, \"a\", \"b\", \"c\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":321,"symbol":"TestExactArgs","kind":"function","lang":"go","code":"func TestExactArgs(t *testing.T) {\n\tc := getCommand(ExactArgs(3), false)\n\toutput, err := executeCommand(c, \"a\", \"b\", \"c\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":327,"symbol":"TestExactArgs_WithValid","kind":"function","lang":"go","code":"func TestExactArgs_WithValid(t *testing.T) {\n\tc := getCommand(ExactArgs(3), true)\n\toutput, err := executeCommand(c, \"three\", \"one\", \"two\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":333,"symbol":"TestExactArgs_WithValid_WithInvalidArgs","kind":"function","lang":"go","code":"func TestExactArgs_WithValid_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(ExactArgs(3), true)\n\toutput, err := executeCommand(c, \"three\", \"a\", \"two\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":339,"symbol":"TestExactArgs_WithValidOnly_WithInvalidArgs","kind":"function","lang":"go","code":"func TestExactArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MatchAll(OnlyValidArgs, ExactArgs(3)), true)\n\t_, err := executeCommand(c, \"three\", \"a\", \"two\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":345,"symbol":"TestExactArgs_WithInvalidCount","kind":"function","lang":"go","code":"func TestExactArgs_WithInvalidCount(t *testing.T) {\n\tc := getCommand(ExactArgs(2), false)\n\t_, err := executeCommand(c, \"a\", \"b\", \"c\")\n\texactArgsWithInvalidCount(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":351,"symbol":"TestExactArgs_WithInvalidCount_WithValid","kind":"function","lang":"go","code":"func TestExactArgs_WithInvalidCount_WithValid(t *testing.T) {\n\tc := getCommand(ExactArgs(2), true)\n\t_, err := executeCommand(c, \"three\", \"one\", \"two\")\n\texactArgsWithInvalidCount(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":357,"symbol":"TestExactArgs_WithInvalidCount_WithValid_WithInvalidArgs","kind":"function","lang":"go","code":"func TestExactArgs_WithInvalidCount_WithValid_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(ExactArgs(2), true)\n\t_, err := executeCommand(c, \"three\", \"a\", \"two\")\n\texactArgsWithInvalidCount(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":363,"symbol":"TestExactArgs_WithInvalidCount_WithValidOnly_WithInvalidArgs","kind":"function","lang":"go","code":"func TestExactArgs_WithInvalidCount_WithValidOnly_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MatchAll(OnlyValidArgs, ExactArgs(2)), true)\n\t_, err := executeCommand(c, \"three\", \"a\", \"two\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":371,"symbol":"TestRangeArgs","kind":"function","lang":"go","code":"func TestRangeArgs(t *testing.T) {\n\tc := getCommand(RangeArgs(2, 4), false)\n\toutput, err := executeCommand(c, \"a\", \"b\", \"c\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":377,"symbol":"TestRangeArgs_WithValid","kind":"function","lang":"go","code":"func TestRangeArgs_WithValid(t *testing.T) {\n\tc := getCommand(RangeArgs(2, 4), true)\n\toutput, err := executeCommand(c, \"three\", \"one\", \"two\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":383,"symbol":"TestRangeArgs_WithValid_WithInvalidArgs","kind":"function","lang":"go","code":"func TestRangeArgs_WithValid_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(RangeArgs(2, 4), true)\n\toutput, err := executeCommand(c, \"three\", \"a\", \"two\")\n\texpectSuccess(output, err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":389,"symbol":"TestRangeArgs_WithValidOnly_WithInvalidArgs","kind":"function","lang":"go","code":"func TestRangeArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MatchAll(OnlyValidArgs, RangeArgs(2, 4)), true)\n\t_, err := executeCommand(c, \"three\", \"a\", \"two\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":395,"symbol":"TestRangeArgs_WithInvalidCount","kind":"function","lang":"go","code":"func TestRangeArgs_WithInvalidCount(t *testing.T) {\n\tc := getCommand(RangeArgs(2, 4), false)\n\t_, err := executeCommand(c, \"a\")\n\trangeArgsWithInvalidCount(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":401,"symbol":"TestRangeArgs_WithInvalidCount_WithValid","kind":"function","lang":"go","code":"func TestRangeArgs_WithInvalidCount_WithValid(t *testing.T) {\n\tc := getCommand(RangeArgs(2, 4), true)\n\t_, err := executeCommand(c, \"two\")\n\trangeArgsWithInvalidCount(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":407,"symbol":"TestRangeArgs_WithInvalidCount_WithValid_WithInvalidArgs","kind":"function","lang":"go","code":"func TestRangeArgs_WithInvalidCount_WithValid_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(RangeArgs(2, 4), true)\n\t_, err := executeCommand(c, \"a\")\n\trangeArgsWithInvalidCount(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":413,"symbol":"TestRangeArgs_WithInvalidCount_WithValidOnly_WithInvalidArgs","kind":"function","lang":"go","code":"func TestRangeArgs_WithInvalidCount_WithValidOnly_WithInvalidArgs(t *testing.T) {\n\tc := getCommand(MatchAll(OnlyValidArgs, RangeArgs(2, 4)), true)\n\t_, err := executeCommand(c, \"a\")\n\tvalidOnlyWithInvalidArgs(err, t)\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":421,"symbol":"TestRootTakesNoArgs","kind":"function","lang":"go","code":"func TestRootTakesNoArgs(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\tchildCmd := &Command{Use: \"child\", Run: emptyRun}\n\trootCmd.AddCommand(childCmd)\n\n\t_, err := executeCommand(rootCmd, \"illegal\", \"args\")\n\tif err == nil {\n\t\tt.Fatal(\"Expected an error\")\n\t}\n\n\tgot := err.Error()\n\texpected := `unknown command \"illegal\" for \"root\"`\n\tif !strings.Contains(got, expected) {\n\t\tt.Errorf(\"expected %q, got %q\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":438,"symbol":"TestRootTakesArgs","kind":"function","lang":"go","code":"func TestRootTakesArgs(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: ArbitraryArgs, Run: emptyRun}\n\tchildCmd := &Command{Use: \"child\", Run: emptyRun}\n\trootCmd.AddCommand(childCmd)\n\n\t_, err := executeCommand(rootCmd, \"legal\", \"args\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":449,"symbol":"TestChildTakesNoArgs","kind":"function","lang":"go","code":"func TestChildTakesNoArgs(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\tchildCmd := &Command{Use: \"child\", Args: NoArgs, Run: emptyRun}\n\trootCmd.AddCommand(childCmd)\n\n\t_, err := executeCommand(rootCmd, \"child\", \"illegal\", \"args\")\n\tif err == nil {\n\t\tt.Fatal(\"Expected an error\")\n\t}\n\n\tgot := err.Error()\n\texpected := `unknown command \"illegal\" for \"root child\"`\n\tif !strings.Contains(got, expected) {\n\t\tt.Errorf(\"expected %q, got %q\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"args_test.go","line":466,"symbol":"TestChildTakesArgs","kind":"function","lang":"go","code":"func TestChildTakesArgs(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\tchildCmd := &Command{Use: \"child\", Args: ArbitraryArgs, Run: emptyRun}\n\trootCmd.AddCommand(childCmd)\n\n\t_, err := executeCommand(rootCmd, \"child\", \"legal\", \"args\")\n\tif err != nil {\n\t\tt.Fatalf(\"Unexpected error: %v\", err)\n\t}\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":30,"symbol":"BashCompFilenameExt","kind":"constant","lang":"go","code":"BashCompFilenameExt = \"cobra_annotation_bash_completion_filename_extensions\""} | |
| {"repo":"cobra","file":"bash_completions.go","line":31,"symbol":"BashCompCustom","kind":"constant","lang":"go","code":"BashCompCustom = \"cobra_annotation_bash_completion_custom\""} | |
| {"repo":"cobra","file":"bash_completions.go","line":32,"symbol":"BashCompOneRequiredFlag","kind":"constant","lang":"go","code":"BashCompOneRequiredFlag = \"cobra_annotation_bash_completion_one_required_flag\""} | |
| {"repo":"cobra","file":"bash_completions.go","line":33,"symbol":"BashCompSubdirsInDir","kind":"constant","lang":"go","code":"BashCompSubdirsInDir = \"cobra_annotation_bash_completion_subdirs_in_dir\""} | |
| {"repo":"cobra","file":"bash_completions.go","line":36,"symbol":"writePreamble","kind":"function","lang":"go","code":"func writePreamble(buf io.StringWriter, name string) {\n\tWriteStringAndCheck(buf, fmt.Sprintf(\"# bash completion for %-36s -*- shell-script -*-\\n\", name))\n\tWriteStringAndCheck(buf, fmt.Sprintf(`\n__%[1]s_debug()\n{\n if [[ -n ${BASH_COMP_DEBUG_FILE:-} ]]; then\n echo \"$*\" >> \"${BASH_COMP_DEBUG_FILE}\"\n fi\n}\n\n# Homebrew on Macs have version 1.3 of bash-completion which doesn't include\n# _init_completion. This is a very minimal version of that function.\n__%[1]s_init_completion()\n{\n COMPREPLY=()\n _get_comp_words_by_ref \"$@\" cur prev words cword\n}\n\n__%[1]s_index_of_word()\n{\n local w word=$1\n shift\n index=0\n for w in \"$@\"; do\n [[ $w = \"$word\" ]] && return\n index=$((index+1))\n done\n index=-1\n}\n\n__%[1]s_contains_word()\n{\n local w word=$1; shift\n for w in \"$@\"; do\n [[ $w = \"$word\" ]] && return\n done\n return 1\n}\n\n__%[1]s_handle_go_custom_completion()\n{\n __%[1]s_debug \"${FUNCNAME[0]}: cur is ${cur}, words[*] is ${words[*]}, #words[@] is ${#words[@]}\"\n\n local shellCompDirectiveError=%[3]d\n local shellCompDirectiveNoSpace=%[4]d\n local shellCompDirectiveNoFileComp=%[5]d\n local shellCompDirectiveFilterFileExt=%[6]d\n "} | |
| {"repo":"cobra","file":"bash_completions.go","line":404,"symbol":"writePostscript","kind":"function","lang":"go","code":"func writePostscript(buf io.StringWriter, name string) {\n\tname = strings.ReplaceAll(name, \":\", \"__\")\n\tWriteStringAndCheck(buf, fmt.Sprintf(\"__start_%s()\\n\", name))\n\tWriteStringAndCheck(buf, fmt.Sprintf(`{\n local cur prev words cword split\n declare -A flaghash 2>/dev/null || :\n declare -A aliashash 2>/dev/null || :\n if declare -F _init_completion >/dev/null 2>&1; then\n _init_completion -s || return\n else\n __%[1]s_init_completion -n \"=\" || return\n fi\n\n local c=0\n local flag_parsing_disabled=\n local flags=()\n local two_word_flags=()\n local local_nonpersistent_flags=()\n local flags_with_completion=()\n local flags_completion=()\n local commands=(\"%[1]s\")\n local command_aliases=()\n local must_have_one_flag=()\n local must_have_one_noun=()\n local has_completion_function=\"\"\n local last_command=\"\"\n local nouns=()\n local noun_aliases=()\n\n __%[1]s_handle_word\n}\n\n`, name))\n\tWriteStringAndCheck(buf, fmt.Sprintf(`if [[ $(type -t compopt) = \"builtin\" ]]; then\n complete -o default -F __start_%s %s\nelse\n complete -o default -o nospace -F __start_%s %s\nfi\n\n`, name, name, name, name))\n\tWriteStringAndCheck(buf, \"# ex: "} | |
| {"repo":"cobra","file":"bash_completions.go","line":447,"symbol":"writeCommands","kind":"function","lang":"go","code":"func writeCommands(buf io.StringWriter, cmd *Command) {\n\tWriteStringAndCheck(buf, \" commands=()\\n\")\n\tfor _, c := range cmd.Commands() {\n\t\tif !c.IsAvailableCommand() && c != cmd.helpCommand {\n\t\t\tcontinue\n\t\t}\n\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" commands+=(%q)\\n\", c.Name()))\n\t\twriteCmdAliases(buf, c)\n\t}\n\tWriteStringAndCheck(buf, \"\\n\")\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":459,"symbol":"writeFlagHandler","kind":"function","lang":"go","code":"func writeFlagHandler(buf io.StringWriter, name string, annotations map[string][]string, cmd *Command) {\n\tfor key, value := range annotations {\n\t\tswitch key {\n\t\tcase BashCompFilenameExt:\n\t\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" flags_with_completion+=(%q)\\n\", name))\n\n\t\t\tvar ext string\n\t\t\tif len(value) > 0 {\n\t\t\t\text = fmt.Sprintf(\"__%s_handle_filename_extension_flag \", cmd.Root().Name()) + strings.Join(value, \"|\")\n\t\t\t} else {\n\t\t\t\text = \"_filedir\"\n\t\t\t}\n\t\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" flags_completion+=(%q)\\n\", ext))\n\t\tcase BashCompCustom:\n\t\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" flags_with_completion+=(%q)\\n\", name))\n\n\t\t\tif len(value) > 0 {\n\t\t\t\thandlers := strings.Join(value, \"; \")\n\t\t\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" flags_completion+=(%q)\\n\", handlers))\n\t\t\t} else {\n\t\t\t\tWriteStringAndCheck(buf, \" flags_completion+=(:)\\n\")\n\t\t\t}\n\t\tcase BashCompSubdirsInDir:\n\t\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" flags_with_completion+=(%q)\\n\", name))\n\n\t\t\tvar ext string\n\t\t\tif len(value) == 1 {\n\t\t\t\text = fmt.Sprintf(\"__%s_handle_subdirs_in_dir_flag \", cmd.Root().Name()) + value[0]\n\t\t\t} else {\n\t\t\t\text = \"_filedir -d\"\n\t\t\t}\n\t\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" "} | |
| {"repo":"cobra","file":"bash_completions.go","line":465,"symbol":"ext","kind":"variable","lang":"go","code":"ext string"} | |
| {"repo":"cobra","file":"bash_completions.go","line":484,"symbol":"ext","kind":"variable","lang":"go","code":"ext string"} | |
| {"repo":"cobra","file":"bash_completions.go","line":495,"symbol":"cbn","kind":"constant","lang":"go","code":"cbn = \"\\\")\\n\""} | |
| {"repo":"cobra","file":"bash_completions.go","line":497,"symbol":"writeShortFlag","kind":"function","lang":"go","code":"func writeShortFlag(buf io.StringWriter, flag *pflag.Flag, cmd *Command) {\n\tname := flag.Shorthand\n\tformat := \" \"\n\tif len(flag.NoOptDefVal) == 0 {\n\t\tformat += \"two_word_\"\n\t}\n\tformat += \"flags+=(\\\"-%s\" + cbn\n\tWriteStringAndCheck(buf, fmt.Sprintf(format, name))\n\twriteFlagHandler(buf, \"-\"+name, flag.Annotations, cmd)\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":508,"symbol":"writeFlag","kind":"function","lang":"go","code":"func writeFlag(buf io.StringWriter, flag *pflag.Flag, cmd *Command) {\n\tname := flag.Name\n\tformat := \" flags+=(\\\"--%s\"\n\tif len(flag.NoOptDefVal) == 0 {\n\t\tformat += \"=\"\n\t}\n\tformat += cbn\n\tWriteStringAndCheck(buf, fmt.Sprintf(format, name))\n\tif len(flag.NoOptDefVal) == 0 {\n\t\tformat = \" two_word_flags+=(\\\"--%s\" + cbn\n\t\tWriteStringAndCheck(buf, fmt.Sprintf(format, name))\n\t}\n\twriteFlagHandler(buf, \"--\"+name, flag.Annotations, cmd)\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":523,"symbol":"writeLocalNonPersistentFlag","kind":"function","lang":"go","code":"func writeLocalNonPersistentFlag(buf io.StringWriter, flag *pflag.Flag) {\n\tname := flag.Name\n\tformat := \" local_nonpersistent_flags+=(\\\"--%[1]s\" + cbn\n\tif len(flag.NoOptDefVal) == 0 {\n\t\tformat += \" local_nonpersistent_flags+=(\\\"--%[1]s=\" + cbn\n\t}\n\tWriteStringAndCheck(buf, fmt.Sprintf(format, name))\n\tif len(flag.Shorthand) > 0 {\n\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" local_nonpersistent_flags+=(\\\"-%s\\\")\\n\", flag.Shorthand))\n\t}\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":536,"symbol":"prepareCustomAnnotationsForFlags","kind":"function","lang":"go","doc":"prepareCustomAnnotationsForFlags setup annotations for go completions for registered flags","code":"func prepareCustomAnnotationsForFlags(cmd *Command) {\n\tflagCompletionMutex.RLock()\n\tdefer flagCompletionMutex.RUnlock()\n\tfor flag := range flagCompletionFunctions {\n\t\t// Make sure the completion script calls the __*_go_custom_completion function for\n\t\t// every registered flag. We need to do this here (and not when the flag was registered\n\t\t// for completion) so that we can know the root command name for the prefix\n\t\t// of __<prefix>_go_custom_completion\n\t\tif flag.Annotations == nil {\n\t\t\tflag.Annotations = map[string][]string{}\n\t\t}\n\t\tflag.Annotations[BashCompCustom] = []string{fmt.Sprintf(\"__%[1]s_handle_go_custom_completion\", cmd.Root().Name())}\n\t}\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":551,"symbol":"writeFlags","kind":"function","lang":"go","code":"func writeFlags(buf io.StringWriter, cmd *Command) {\n\tprepareCustomAnnotationsForFlags(cmd)\n\tWriteStringAndCheck(buf, ` flags=()\n two_word_flags=()\n local_nonpersistent_flags=()\n flags_with_completion=()\n flags_completion=()\n\n`)\n\n\tif cmd.DisableFlagParsing {\n\t\tWriteStringAndCheck(buf, \" flag_parsing_disabled=1\\n\")\n\t}\n\n\tlocalNonPersistentFlags := cmd.LocalNonPersistentFlags()\n\tcmd.NonInheritedFlags().VisitAll(func(flag *pflag.Flag) {\n\t\tif nonCompletableFlag(flag) {\n\t\t\treturn\n\t\t}\n\t\twriteFlag(buf, flag, cmd)\n\t\tif len(flag.Shorthand) > 0 {\n\t\t\twriteShortFlag(buf, flag, cmd)\n\t\t}\n\t\t// localNonPersistentFlags are used to stop the completion of subcommands when one is set\n\t\t// if TraverseChildren is true we should allow to complete subcommands\n\t\tif localNonPersistentFlags.Lookup(flag.Name) != nil && !cmd.Root().TraverseChildren {\n\t\t\twriteLocalNonPersistentFlag(buf, flag)\n\t\t}\n\t})\n\tcmd.InheritedFlags().VisitAll(func(flag *pflag.Flag) {\n\t\tif nonCompletableFlag(flag) {\n\t\t\treturn\n\t\t}\n\t\twriteFlag(buf, flag, cmd)\n\t\tif len(flag.Shorthand) > 0 {\n\t\t\twriteShortFlag(buf, flag, cmd)\n\t\t}\n\t})\n\n\tWriteStringAndCheck(buf, \"\\n\")\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":593,"symbol":"writeRequiredFlag","kind":"function","lang":"go","code":"func writeRequiredFlag(buf io.StringWriter, cmd *Command) {\n\tWriteStringAndCheck(buf, \" must_have_one_flag=()\\n\")\n\tflags := cmd.NonInheritedFlags()\n\tflags.VisitAll(func(flag *pflag.Flag) {\n\t\tif nonCompletableFlag(flag) {\n\t\t\treturn\n\t\t}\n\t\tif _, ok := flag.Annotations[BashCompOneRequiredFlag]; ok {\n\t\t\tformat := \" must_have_one_flag+=(\\\"--%s\"\n\t\t\tif flag.Value.Type() != \"bool\" {\n\t\t\t\tformat += \"=\"\n\t\t\t}\n\t\t\tformat += cbn\n\t\t\tWriteStringAndCheck(buf, fmt.Sprintf(format, flag.Name))\n\n\t\t\tif len(flag.Shorthand) > 0 {\n\t\t\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" must_have_one_flag+=(\\\"-%s\"+cbn, flag.Shorthand))\n\t\t\t}\n\t\t}\n\t})\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":615,"symbol":"writeRequiredNouns","kind":"function","lang":"go","code":"func writeRequiredNouns(buf io.StringWriter, cmd *Command) {\n\tWriteStringAndCheck(buf, \" must_have_one_noun=()\\n\")\n\tsort.Strings(cmd.ValidArgs)\n\tfor _, value := range cmd.ValidArgs {\n\t\t// Remove any description that may be included following a tab character.\n\t\t// Descriptions are not supported by bash completion.\n\t\tvalue = strings.SplitN(value, \"\\t\", 2)[0]\n\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" must_have_one_noun+=(%q)\\n\", value))\n\t}\n\tif cmd.ValidArgsFunction != nil {\n\t\tWriteStringAndCheck(buf, \" has_completion_function=1\\n\")\n\t}\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":629,"symbol":"writeCmdAliases","kind":"function","lang":"go","code":"func writeCmdAliases(buf io.StringWriter, cmd *Command) {\n\tif len(cmd.Aliases) == 0 {\n\t\treturn\n\t}\n\n\tsort.Strings(cmd.Aliases)\n\n\tWriteStringAndCheck(buf, fmt.Sprint(` if [[ -z \"${BASH_VERSION:-}\" || \"${BASH_VERSINFO[0]:-}\" -gt 3 ]]; then`, \"\\n\"))\n\tfor _, value := range cmd.Aliases {\n\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" command_aliases+=(%q)\\n\", value))\n\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" aliashash[%q]=%q\\n\", value, cmd.Name()))\n\t}\n\tWriteStringAndCheck(buf, ` fi`)\n\tWriteStringAndCheck(buf, \"\\n\")\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":644,"symbol":"writeArgAliases","kind":"function","lang":"go","code":"func writeArgAliases(buf io.StringWriter, cmd *Command) {\n\tWriteStringAndCheck(buf, \" noun_aliases=()\\n\")\n\tsort.Strings(cmd.ArgAliases)\n\tfor _, value := range cmd.ArgAliases {\n\t\tWriteStringAndCheck(buf, fmt.Sprintf(\" noun_aliases+=(%q)\\n\", value))\n\t}\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":652,"symbol":"gen","kind":"function","lang":"go","code":"func gen(buf io.StringWriter, cmd *Command) {\n\tfor _, c := range cmd.Commands() {\n\t\tif !c.IsAvailableCommand() && c != cmd.helpCommand {\n\t\t\tcontinue\n\t\t}\n\t\tgen(buf, c)\n\t}\n\tcommandName := cmd.CommandPath()\n\tcommandName = strings.ReplaceAll(commandName, \" \", \"_\")\n\tcommandName = strings.ReplaceAll(commandName, \":\", \"__\")\n\n\tif cmd.Root() == cmd {\n\t\tWriteStringAndCheck(buf, fmt.Sprintf(\"_%s_root_command()\\n{\\n\", commandName))\n\t} else {\n\t\tWriteStringAndCheck(buf, fmt.Sprintf(\"_%s()\\n{\\n\", commandName))\n\t}\n\n\tWriteStringAndCheck(buf, fmt.Sprintf(\" last_command=%q\\n\", commandName))\n\tWriteStringAndCheck(buf, \"\\n\")\n\tWriteStringAndCheck(buf, \" command_aliases=()\\n\")\n\tWriteStringAndCheck(buf, \"\\n\")\n\n\twriteCommands(buf, cmd)\n\twriteFlags(buf, cmd)\n\twriteRequiredFlag(buf, cmd)\n\twriteRequiredNouns(buf, cmd)\n\twriteArgAliases(buf, cmd)\n\tWriteStringAndCheck(buf, \"}\\n\\n\")\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":683,"symbol":"GenBashCompletion","kind":"method","lang":"go","doc":"GenBashCompletion generates bash completion file and writes to the passed writer.","code":"func (c *Command) GenBashCompletion(w io.Writer) error {\n\tbuf := new(bytes.Buffer)\n\twritePreamble(buf, c.Name())\n\tif len(c.BashCompletionFunction) > 0 {\n\t\tbuf.WriteString(c.BashCompletionFunction + \"\\n\")\n\t}\n\tgen(buf, c)\n\twritePostscript(buf, c.Name())\n\n\t_, err := buf.WriteTo(w)\n\treturn err\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":696,"symbol":"nonCompletableFlag","kind":"function","lang":"go","code":"func nonCompletableFlag(flag *pflag.Flag) bool {\n\treturn flag.Hidden || len(flag.Deprecated) > 0\n}"} | |
| {"repo":"cobra","file":"bash_completions.go","line":701,"symbol":"GenBashCompletionFile","kind":"method","lang":"go","doc":"GenBashCompletionFile generates bash completion file.","code":"func (c *Command) GenBashCompletionFile(filename string) error {\n\toutFile, err := os.Create(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer outFile.Close()\n\n\treturn c.GenBashCompletion(outFile)\n}"} | |
| {"repo":"cobra","file":"bash_completionsV2.go","line":24,"symbol":"genBashCompletion","kind":"method","lang":"go","code":"func (c *Command) genBashCompletion(w io.Writer, includeDesc bool) error {\n\tbuf := new(bytes.Buffer)\n\tgenBashComp(buf, c.Name(), includeDesc)\n\t_, err := buf.WriteTo(w)\n\treturn err\n}"} | |
| {"repo":"cobra","file":"bash_completionsV2.go","line":31,"symbol":"genBashComp","kind":"function","lang":"go","code":"func genBashComp(buf io.StringWriter, name string, includeDesc bool) {\n\tcompCmd := ShellCompRequestCmd\n\tif !includeDesc {\n\t\tcompCmd = ShellCompNoDescRequestCmd\n\t}\n\n\tWriteStringAndCheck(buf, fmt.Sprintf(`# bash completion V2 for %-36[1]s -*- shell-script -*-\n\n__%[1]s_debug()\n{\n if [[ -n ${BASH_COMP_DEBUG_FILE-} ]]; then\n echo \"$*\" >> \"${BASH_COMP_DEBUG_FILE}\"\n fi\n}\n\n# Macs have bash3 for which the bash-completion package doesn't include\n# _init_completion. This is a minimal version of that function.\n__%[1]s_init_completion()\n{\n COMPREPLY=()\n _get_comp_words_by_ref \"$@\" cur prev words cword\n}\n\n# This function calls the %[1]s program to obtain the completion\n# results and the directive. It fills the 'out' and 'directive' vars.\n__%[1]s_get_completion_results() {\n local requestComp lastParam lastChar args\n\n # Prepare the command to request completions for the program.\n # Calling ${words[0]} instead of directly %[1]s allows handling aliases\n args=(\"${words[@]:1}\")\n requestComp=\"${words[0]} %[2]s ${args[*]}\"\n\n lastParam=${words[$((${#words[@]}-1))]}\n lastChar=${lastParam:$((${#lastParam}-1)):1}\n __%[1]s_debug \"lastParam ${lastParam}, lastChar ${"} | |
| {"repo":"cobra","file":"bash_completionsV2.go","line":470,"symbol":"GenBashCompletionFileV2","kind":"method","lang":"go","doc":"GenBashCompletionFileV2 generates Bash completion version 2.","code":"func (c *Command) GenBashCompletionFileV2(filename string, includeDesc bool) error {\n\toutFile, err := os.Create(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer outFile.Close()\n\n\treturn c.GenBashCompletionV2(outFile, includeDesc)\n}"} | |
| {"repo":"cobra","file":"bash_completionsV2.go","line":482,"symbol":"GenBashCompletionV2","kind":"method","lang":"go","doc":"GenBashCompletionV2 generates Bash completion file version 2 and writes it to the passed writer.","code":"func (c *Command) GenBashCompletionV2(w io.Writer, includeDesc bool) error {\n\treturn c.genBashCompletion(w, includeDesc)\n}"} | |
| {"repo":"cobra","file":"bash_completionsV2_test.go","line":23,"symbol":"TestBashCompletionV2WithActiveHelp","kind":"function","lang":"go","code":"func TestBashCompletionV2WithActiveHelp(t *testing.T) {\n\tc := &Command{Use: \"c\", Run: emptyRun}\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, c.GenBashCompletionV2(buf, true))\n\toutput := buf.String()\n\n\t// check that active help is not being disabled\n\tactiveHelpVar := activeHelpEnvVar(c.Name())\n\tcheckOmit(t, output, fmt.Sprintf(\"%s=0\", activeHelpVar))\n}"} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":27,"symbol":"checkOmit","kind":"function","lang":"go","code":"func checkOmit(t *testing.T, found, unexpected string) {\n\tif strings.Contains(found, unexpected) {\n\t\tt.Errorf(\"Got: %q\\nBut should not have!\\n\", unexpected)\n\t}\n}"} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":33,"symbol":"check","kind":"function","lang":"go","code":"func check(t *testing.T, found, expected string) {\n\tif !strings.Contains(found, expected) {\n\t\tt.Errorf(\"Expecting to contain: \\n %q\\nGot:\\n %q\\n\", expected, found)\n\t}\n}"} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":39,"symbol":"checkNumOccurrences","kind":"function","lang":"go","code":"func checkNumOccurrences(t *testing.T, found, expected string, expectedOccurrences int) {\n\tnumOccurrences := strings.Count(found, expected)\n\tif numOccurrences != expectedOccurrences {\n\t\tt.Errorf(\"Expecting to contain %d occurrences of: \\n %q\\nGot %d:\\n %q\\n\", expectedOccurrences, expected, numOccurrences, found)\n\t}\n}"} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":46,"symbol":"checkRegex","kind":"function","lang":"go","code":"func checkRegex(t *testing.T, found, pattern string) {\n\tmatched, err := regexp.MatchString(pattern, found)\n\tif err != nil {\n\t\tt.Errorf(\"Error thrown performing MatchString: \\n %s\\n\", err)\n\t}\n\tif !matched {\n\t\tt.Errorf(\"Expecting to match: \\n %q\\nGot:\\n %q\\n\", pattern, found)\n\t}\n}"} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":56,"symbol":"runShellCheck","kind":"function","lang":"go","code":"func runShellCheck(s string) error {\n\tcmd := exec.Command(\"shellcheck\", \"-s\", \"bash\", \"-\", \"-e\",\n\t\t\"SC2034\", // PREFIX appears unused. Verify it or export it.\n\t)\n\tcmd.Stderr = os.Stderr\n\tcmd.Stdout = os.Stdout\n\n\tstdin, err := cmd.StdinPipe()\n\tif err != nil {\n\t\treturn err\n\t}\n\tgo func() {\n\t\t_, err := stdin.Write([]byte(s))\n\t\tCheckErr(err)\n\n\t\tstdin.Close()\n\t}()\n\n\treturn cmd.Run()\n}"} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":78,"symbol":"bashCompletionFunc","kind":"constant","lang":"go","doc":"World worst custom function, just keep telling you to enter hello!","code":"bashCompletionFunc = `__root_custom_func() {\n\tCOMPREPLY=( \"hello\" )\n}\n`"} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":83,"symbol":"TestBashCompletions","kind":"function","lang":"go","code":"func TestBashCompletions(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tArgAliases: []string{\"pods\", \"nodes\", \"services\", \"replicationcontrollers\", \"po\", \"no\", \"svc\", \"rc\"},\n\t\tValidArgs: []string{\"pod\", \"node\", \"service\", \"replicationcontroller\"},\n\t\tBashCompletionFunction: bashCompletionFunc,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.Flags().IntP(\"introot\", \"i\", -1, \"help message for flag introot\")\n\tassertNoErr(t, rootCmd.MarkFlagRequired(\"introot\"))\n\n\t// Filename.\n\trootCmd.Flags().String(\"filename\", \"\", \"Enter a filename\")\n\tassertNoErr(t, rootCmd.MarkFlagFilename(\"filename\", \"json\", \"yaml\", \"yml\"))\n\n\t// Persistent filename.\n\trootCmd.PersistentFlags().String(\"persistent-filename\", \"\", \"Enter a filename\")\n\tassertNoErr(t, rootCmd.MarkPersistentFlagFilename(\"persistent-filename\"))\n\tassertNoErr(t, rootCmd.MarkPersistentFlagRequired(\"persistent-filename\"))\n\n\t// Filename extensions.\n\trootCmd.Flags().String(\"filename-ext\", \"\", \"Enter a filename (extension limited)\")\n\tassertNoErr(t, rootCmd.MarkFlagFilename(\"filename-ext\"))\n\trootCmd.Flags().String(\"custom\", \"\", \"Enter a filename (extension limited)\")\n\tassertNoErr(t, rootCmd.MarkFlag"} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":229,"symbol":"TestBashCompletionHiddenFlag","kind":"function","lang":"go","code":"func TestBashCompletionHiddenFlag(t *testing.T) {\n\tc := &Command{Use: \"c\", Run: emptyRun}\n\n\tconst flagName = \"hiddenFlag\"\n\tc.Flags().Bool(flagName, false, \"\")\n\tassertNoErr(t, c.Flags().MarkHidden(flagName))\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, c.GenBashCompletion(buf))\n\toutput := buf.String()\n\n\tif strings.Contains(output, flagName) {\n\t\tt.Errorf(\"Expected completion to not include %q flag: Got %v\", flagName, output)\n\t}\n}"} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":232,"symbol":"flagName","kind":"constant","lang":"go","code":"flagName = \"hiddenFlag\""} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":245,"symbol":"TestBashCompletionDeprecatedFlag","kind":"function","lang":"go","code":"func TestBashCompletionDeprecatedFlag(t *testing.T) {\n\tc := &Command{Use: \"c\", Run: emptyRun}\n\n\tconst flagName = \"deprecated-flag\"\n\tc.Flags().Bool(flagName, false, \"\")\n\tassertNoErr(t, c.Flags().MarkDeprecated(flagName, \"use --not-deprecated instead\"))\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, c.GenBashCompletion(buf))\n\toutput := buf.String()\n\n\tif strings.Contains(output, flagName) {\n\t\tt.Errorf(\"expected completion to not include %q flag: Got %v\", flagName, output)\n\t}\n}"} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":248,"symbol":"flagName","kind":"constant","lang":"go","code":"flagName = \"deprecated-flag\""} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":261,"symbol":"TestBashCompletionTraverseChildren","kind":"function","lang":"go","code":"func TestBashCompletionTraverseChildren(t *testing.T) {\n\tc := &Command{Use: \"c\", Run: emptyRun, TraverseChildren: true}\n\n\tc.Flags().StringP(\"string-flag\", \"s\", \"\", \"string flag\")\n\tc.Flags().BoolP(\"bool-flag\", \"b\", false, \"bool flag\")\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, c.GenBashCompletion(buf))\n\toutput := buf.String()\n\n\t// check that local nonpersistent flag are not set since we have TraverseChildren set to true\n\tcheckOmit(t, output, `local_nonpersistent_flags+=(\"--string-flag\")`)\n\tcheckOmit(t, output, `local_nonpersistent_flags+=(\"--string-flag=\")`)\n\tcheckOmit(t, output, `local_nonpersistent_flags+=(\"-s\")`)\n\tcheckOmit(t, output, `local_nonpersistent_flags+=(\"--bool-flag\")`)\n\tcheckOmit(t, output, `local_nonpersistent_flags+=(\"-b\")`)\n}"} | |
| {"repo":"cobra","file":"bash_completions_test.go","line":279,"symbol":"TestBashCompletionNoActiveHelp","kind":"function","lang":"go","code":"func TestBashCompletionNoActiveHelp(t *testing.T) {\n\tc := &Command{Use: \"c\", Run: emptyRun}\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, c.GenBashCompletion(buf))\n\toutput := buf.String()\n\n\t// check that active help is being disabled\n\tactiveHelpVar := activeHelpEnvVar(c.Name())\n\tcheck(t, output, fmt.Sprintf(\"%s=0\", activeHelpVar))\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":32,"symbol":"templateFuncs","kind":"variable","lang":"go","code":"templateFuncs = template.FuncMap{\n\t\"trim\": strings.TrimSpace,\n\t\"trimRightSpace\": trimRightSpace,\n\t\"trimTrailingWhitespaces\": trimRightSpace,\n\t\"appendIfNotPresent\": appendIfNotPresent,\n\t\"rpad\": rpad,\n\t\"gt\": Gt,\n\t\"eq\": Eq,\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":42,"symbol":"initializers","kind":"variable","lang":"go","code":"initializers []func()"} | |
| {"repo":"cobra","file":"cobra.go","line":43,"symbol":"finalizers","kind":"variable","lang":"go","code":"finalizers []func()"} | |
| {"repo":"cobra","file":"cobra.go","line":46,"symbol":"defaultPrefixMatching","kind":"constant","lang":"go","code":"defaultPrefixMatching = false"} | |
| {"repo":"cobra","file":"cobra.go","line":47,"symbol":"defaultCommandSorting","kind":"constant","lang":"go","code":"defaultCommandSorting = true"} | |
| {"repo":"cobra","file":"cobra.go","line":48,"symbol":"defaultCaseInsensitive","kind":"constant","lang":"go","code":"defaultCaseInsensitive = false"} | |
| {"repo":"cobra","file":"cobra.go","line":49,"symbol":"defaultTraverseRunHooks","kind":"constant","lang":"go","code":"defaultTraverseRunHooks = false"} | |
| {"repo":"cobra","file":"cobra.go","line":55,"symbol":"EnablePrefixMatching","kind":"variable","lang":"go","doc":"EnablePrefixMatching allows setting automatic prefix matching. Automatic prefix matching can be a dangerous thing to automatically enable in CLI tools. Set this to true to enable it.","code":"EnablePrefixMatching = defaultPrefixMatching"} | |
| {"repo":"cobra","file":"cobra.go","line":59,"symbol":"EnableCommandSorting","kind":"variable","lang":"go","doc":"EnableCommandSorting controls sorting of the slice of commands, which is turned on by default. To disable sorting, set it to false.","code":"EnableCommandSorting = defaultCommandSorting"} | |
| {"repo":"cobra","file":"cobra.go","line":62,"symbol":"EnableCaseInsensitive","kind":"variable","lang":"go","doc":"EnableCaseInsensitive allows case-insensitive commands names. (case sensitive by default)","code":"EnableCaseInsensitive = defaultCaseInsensitive"} | |
| {"repo":"cobra","file":"cobra.go","line":66,"symbol":"EnableTraverseRunHooks","kind":"variable","lang":"go","doc":"EnableTraverseRunHooks executes persistent pre-run and post-run hooks from all parents. By default this is disabled, which means only the first run hook to be found is executed.","code":"EnableTraverseRunHooks = defaultTraverseRunHooks"} | |
| {"repo":"cobra","file":"cobra.go","line":72,"symbol":"MousetrapHelpText","kind":"variable","lang":"go","doc":"MousetrapHelpText enables an information splash screen on Windows if the CLI is started from explorer.exe. To disable the mousetrap, just set this variable to blank string (\"\"). Works only on Microsoft Windows.","code":"MousetrapHelpText = `This is a command line tool.\n\nYou need to open cmd.exe and run it from there.\n`"} | |
| {"repo":"cobra","file":"cobra.go","line":81,"symbol":"MousetrapDisplayDuration","kind":"variable","lang":"go","doc":"MousetrapDisplayDuration controls how long the MousetrapHelpText message is displayed on Windows if the CLI is started from explorer.exe. Set to 0 to wait for the return key to be pressed. To disable the mousetrap, just set MousetrapHelpText to blank string (\"\"). Works only on Microsoft Windows.","code":"MousetrapDisplayDuration = 5 * time.Second"} | |
| {"repo":"cobra","file":"cobra.go","line":85,"symbol":"AddTemplateFunc","kind":"function","lang":"go","doc":"AddTemplateFunc adds a template function that's available to Usage and Help template generation.","code":"func AddTemplateFunc(name string, tmplFunc interface{}) {\n\ttemplateFuncs[name] = tmplFunc\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":91,"symbol":"AddTemplateFuncs","kind":"function","lang":"go","doc":"AddTemplateFuncs adds multiple template functions that are available to Usage and Help template generation.","code":"func AddTemplateFuncs(tmplFuncs template.FuncMap) {\n\tfor k, v := range tmplFuncs {\n\t\ttemplateFuncs[k] = v\n\t}\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":99,"symbol":"OnInitialize","kind":"function","lang":"go","doc":"OnInitialize sets the passed functions to be run when each command's Execute method is called.","code":"func OnInitialize(y ...func()) {\n\tinitializers = append(initializers, y...)\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":105,"symbol":"OnFinalize","kind":"function","lang":"go","doc":"OnFinalize sets the passed functions to be run when each command's Execute method is terminated.","code":"func OnFinalize(y ...func()) {\n\tfinalizers = append(finalizers, y...)\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":114,"symbol":"Gt","kind":"function","lang":"go","doc":"Gt takes two types and checks whether the first type is greater than the second. In case of types Arrays, Chans, Maps and Slices, Gt will compare their lengths. Ints are compared directly while strings are first parsed as ints and then compared.","code":"func Gt(a interface{}, b interface{}) bool {\n\tvar left, right int64\n\tav := reflect.ValueOf(a)\n\n\tswitch av.Kind() {\n\tcase reflect.Array, reflect.Chan, reflect.Map, reflect.Slice:\n\t\tleft = int64(av.Len())\n\tcase reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:\n\t\tleft = av.Int()\n\tcase reflect.String:\n\t\tleft, _ = strconv.ParseInt(av.String(), 10, 64)\n\t}\n\n\tbv := reflect.ValueOf(b)\n\n\tswitch bv.Kind() {\n\tcase reflect.Array, reflect.Chan, reflect.Map, reflect.Slice:\n\t\tright = int64(bv.Len())\n\tcase reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:\n\t\tright = bv.Int()\n\tcase reflect.String:\n\t\tright, _ = strconv.ParseInt(bv.String(), 10, 64)\n\t}\n\n\treturn left > right\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":115,"symbol":"left","kind":"variable","lang":"go","code":"left, right int64"} | |
| {"repo":"cobra","file":"cobra.go","line":115,"symbol":"right","kind":"variable","lang":"go","code":"left, right int64"} | |
| {"repo":"cobra","file":"cobra.go","line":144,"symbol":"Eq","kind":"function","lang":"go","doc":"Eq takes two types and checks whether they are equal. Supported types are int and string. Unsupported types will panic.","code":"func Eq(a interface{}, b interface{}) bool {\n\tav := reflect.ValueOf(a)\n\tbv := reflect.ValueOf(b)\n\n\tswitch av.Kind() {\n\tcase reflect.Array, reflect.Chan, reflect.Map, reflect.Slice:\n\t\tpanic(\"Eq called on unsupported type\")\n\tcase reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:\n\t\treturn av.Int() == bv.Int()\n\tcase reflect.String:\n\t\treturn av.String() == bv.String()\n\t}\n\treturn false\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":159,"symbol":"trimRightSpace","kind":"function","lang":"go","code":"func trimRightSpace(s string) string {\n\treturn strings.TrimRightFunc(s, unicode.IsSpace)\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":166,"symbol":"appendIfNotPresent","kind":"function","lang":"go","doc":"appendIfNotPresent will append stringToAppend to the end of s, but only if it's not yet present in s.","code":"func appendIfNotPresent(s, stringToAppend string) string {\n\tif strings.Contains(s, stringToAppend) {\n\t\treturn s\n\t}\n\treturn s + \" \" + stringToAppend\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":174,"symbol":"rpad","kind":"function","lang":"go","doc":"rpad adds padding to the right of a string.","code":"func rpad(s string, padding int) string {\n\tformattedString := fmt.Sprintf(\"%%-%ds\", padding)\n\treturn fmt.Sprintf(formattedString, s)\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":179,"symbol":"tmpl","kind":"function","lang":"go","code":"func tmpl(text string) *tmplFunc {\n\treturn &tmplFunc{\n\t\ttmpl: text,\n\t\tfn: func(w io.Writer, data interface{}) error {\n\t\t\tt := template.New(\"top\")\n\t\t\tt.Funcs(templateFuncs)\n\t\t\ttemplate.Must(t.Parse(text))\n\t\t\treturn t.Execute(w, data)\n\t\t},\n\t}\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":192,"symbol":"ld","kind":"function","lang":"go","doc":"ld compares two strings and returns the levenshtein distance between them.","code":"func ld(s, t string, ignoreCase bool) int {\n\tif ignoreCase {\n\t\ts = strings.ToLower(s)\n\t\tt = strings.ToLower(t)\n\t}\n\td := make([][]int, len(s)+1)\n\tfor i := range d {\n\t\td[i] = make([]int, len(t)+1)\n\t\td[i][0] = i\n\t}\n\tfor j := range d[0] {\n\t\td[0][j] = j\n\t}\n\tfor j := 1; j <= len(t); j++ {\n\t\tfor i := 1; i <= len(s); i++ {\n\t\t\tif s[i-1] == t[j-1] {\n\t\t\t\td[i][j] = d[i-1][j-1]\n\t\t\t} else {\n\t\t\t\tmin := d[i-1][j]\n\t\t\t\tif d[i][j-1] < min {\n\t\t\t\t\tmin = d[i][j-1]\n\t\t\t\t}\n\t\t\t\tif d[i-1][j-1] < min {\n\t\t\t\t\tmin = d[i-1][j-1]\n\t\t\t\t}\n\t\t\t\td[i][j] = min + 1\n\t\t\t}\n\t\t}\n\n\t}\n\treturn d[len(s)][len(t)]\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":225,"symbol":"stringInSlice","kind":"function","lang":"go","code":"func stringInSlice(a string, list []string) bool {\n\tfor _, b := range list {\n\t\tif b == a {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":235,"symbol":"CheckErr","kind":"function","lang":"go","doc":"CheckErr prints the msg with the prefix 'Error:' and exits with error code 1. If the msg is nil, it does nothing.","code":"func CheckErr(msg interface{}) {\n\tif msg != nil {\n\t\tfmt.Fprintln(os.Stderr, \"Error:\", msg)\n\t\tos.Exit(1)\n\t}\n}"} | |
| {"repo":"cobra","file":"cobra.go","line":243,"symbol":"WriteStringAndCheck","kind":"function","lang":"go","doc":"WriteStringAndCheck writes a string into a buffer, and checks if the error is not nil.","code":"func WriteStringAndCheck(b io.StringWriter, s string) {\n\t_, err := b.WriteString(s)\n\tCheckErr(err)\n}"} | |
| {"repo":"cobra","file":"cobra_test.go","line":27,"symbol":"assertNoErr","kind":"function","lang":"go","code":"func assertNoErr(t *testing.T, e error) {\n\tif e != nil {\n\t\tt.Error(e)\n\t}\n}"} | |
| {"repo":"cobra","file":"cobra_test.go","line":33,"symbol":"TestAddTemplateFunctions","kind":"function","lang":"go","code":"func TestAddTemplateFunctions(t *testing.T) {\n\tAddTemplateFunc(\"t\", func() bool { return true })\n\tAddTemplateFuncs(template.FuncMap{\n\t\t\"f\": func() bool { return false },\n\t\t\"h\": func() string { return \"Hello,\" },\n\t\t\"w\": func() string { return \"world.\" }})\n\n\tc := &Command{}\n\tc.SetUsageTemplate(`{{if t}}{{h}}{{end}}{{if f}}{{h}}{{end}} {{w}}`)\n\n\tconst expected = \"Hello, world.\"\n\tif got := c.UsageString(); got != expected {\n\t\tt.Errorf(\"Expected UsageString: %v\\nGot: %v\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"cobra_test.go","line":43,"symbol":"expected","kind":"constant","lang":"go","code":"expected = \"Hello, world.\""} | |
| {"repo":"cobra","file":"cobra_test.go","line":49,"symbol":"TestLevenshteinDistance","kind":"function","lang":"go","code":"func TestLevenshteinDistance(t *testing.T) {\n\ttests := []struct {\n\t\tname string\n\t\ts string\n\t\tt string\n\t\tignoreCase bool\n\t\texpected int\n\t}{\n\t\t{\n\t\t\tname: \"Equal strings (case-sensitive)\",\n\t\t\ts: \"hello\",\n\t\t\tt: \"hello\",\n\t\t\tignoreCase: false,\n\t\t\texpected: 0,\n\t\t},\n\t\t{\n\t\t\tname: \"Equal strings (case-insensitive)\",\n\t\t\ts: \"Hello\",\n\t\t\tt: \"hello\",\n\t\t\tignoreCase: true,\n\t\t\texpected: 0,\n\t\t},\n\t\t{\n\t\t\tname: \"Different strings (case-sensitive)\",\n\t\t\ts: \"kitten\",\n\t\t\tt: \"sitting\",\n\t\t\tignoreCase: false,\n\t\t\texpected: 3,\n\t\t},\n\t\t{\n\t\t\tname: \"Different strings (case-insensitive)\",\n\t\t\ts: \"Kitten\",\n\t\t\tt: \"Sitting\",\n\t\t\tignoreCase: true,\n\t\t\texpected: 3,\n\t\t},\n\t\t{\n\t\t\tname: \"Empty strings\",\n\t\t\ts: \"\",\n\t\t\tt: \"\",\n\t\t\tignoreCase: false,\n\t\t\texpected: 0,\n\t\t},\n\t\t{\n\t\t\tname: \"One empty string\",\n\t\t\ts: \"abc\",\n\t\t\tt: \"\",\n\t\t\tignoreCase: false,\n\t\t\texpected: 3,\n\t\t},\n\t\t{\n\t\t\tname: \"Both empty strings\",\n\t\t\ts: \"\",\n\t\t\tt: \"\",\n\t\t\tignoreCase: true,\n\t\t\texpected: 0,\n\t\t},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) "} | |
| {"repo":"cobra","file":"cobra_test.go","line":121,"symbol":"TestStringInSlice","kind":"function","lang":"go","code":"func TestStringInSlice(t *testing.T) {\n\ttests := []struct {\n\t\tname string\n\t\ta string\n\t\tlist []string\n\t\texpected bool\n\t}{\n\t\t{\n\t\t\tname: \"String in slice (case-sensitive)\",\n\t\t\ta: \"apple\",\n\t\t\tlist: []string{\"orange\", \"banana\", \"apple\", \"grape\"},\n\t\t\texpected: true,\n\t\t},\n\t\t{\n\t\t\tname: \"String not in slice (case-sensitive)\",\n\t\t\ta: \"pear\",\n\t\t\tlist: []string{\"orange\", \"banana\", \"apple\", \"grape\"},\n\t\t\texpected: false,\n\t\t},\n\t\t{\n\t\t\tname: \"String in slice (case-insensitive)\",\n\t\t\ta: \"APPLE\",\n\t\t\tlist: []string{\"orange\", \"banana\", \"apple\", \"grape\"},\n\t\t\texpected: false,\n\t\t},\n\t\t{\n\t\t\tname: \"Empty slice\",\n\t\t\ta: \"apple\",\n\t\t\tlist: []string{},\n\t\t\texpected: false,\n\t\t},\n\t\t{\n\t\t\tname: \"Empty string\",\n\t\t\ta: \"\",\n\t\t\tlist: []string{\"orange\", \"banana\", \"apple\", \"grape\"},\n\t\t\texpected: false,\n\t\t},\n\t\t{\n\t\t\tname: \"Empty strings match\",\n\t\t\ta: \"\",\n\t\t\tlist: []string{\"orange\", \"\"},\n\t\t\texpected: true,\n\t\t},\n\t\t{\n\t\t\tname: \"Empty string in empty slice\",\n\t\t\ta: \"\",\n\t\t\tlist: []string{},\n\t\t\texpected: false,\n\t\t},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\t// Act\n\t\t\tgot := stringInSlice("} | |
| {"repo":"cobra","file":"cobra_test.go","line":185,"symbol":"TestRpad","kind":"function","lang":"go","code":"func TestRpad(t *testing.T) {\n\ttests := []struct {\n\t\tname string\n\t\tinputString string\n\t\tpadding int\n\t\texpected string\n\t}{\n\t\t{\n\t\t\tname: \"Padding required\",\n\t\t\tinputString: \"Hello\",\n\t\t\tpadding: 10,\n\t\t\texpected: \"Hello \",\n\t\t},\n\t\t{\n\t\t\tname: \"No padding required\",\n\t\t\tinputString: \"World\",\n\t\t\tpadding: 5,\n\t\t\texpected: \"World\",\n\t\t},\n\t\t{\n\t\t\tname: \"Empty string\",\n\t\t\tinputString: \"\",\n\t\t\tpadding: 8,\n\t\t\texpected: \" \",\n\t\t},\n\t\t{\n\t\t\tname: \"Zero padding\",\n\t\t\tinputString: \"cobra\",\n\t\t\tpadding: 0,\n\t\t\texpected: \"cobra\",\n\t\t},\n\t}\n\n\tfor _, tt := range tests {\n\t\tt.Run(tt.name, func(t *testing.T) {\n\t\t\t// Act\n\t\t\tgot := rpad(tt.inputString, tt.padding)\n\n\t\t\t// Assert\n\t\t\tif got != tt.expected {\n\t\t\t\tt.Errorf(\"Expected rpad: %v\\nGot: %v\", tt.expected, got)\n\t\t\t}\n\t\t})\n\t}\n}"} | |
| {"repo":"cobra","file":"cobra_test.go","line":245,"symbol":"TestDeadcodeElimination","kind":"function","lang":"go","doc":"reachable. Since cobra can use text/template templates this test checks that in its default configuration that code path can be proven to be unreachable by the linker. See also: https://github.com/spf13/cobra/pull/1956","code":"func TestDeadcodeElimination(t *testing.T) {\n\tif runtime.GOOS == \"windows\" {\n\t\tt.Skip(\"go tool nm fails on windows\")\n\t}\n\n\t// check that a simple program using cobra in its default configuration is\n\t// linked with deadcode elimination enabled.\n\tconst (\n\t\tdirname = \"test_deadcode\"\n\t\tprogname = \"test_deadcode_elimination\"\n\t)\n\t_ = os.Mkdir(dirname, 0770)\n\tdefer os.RemoveAll(dirname)\n\tfilename := filepath.Join(dirname, progname+\".go\")\n\terr := os.WriteFile(filename, []byte(`package main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/spf13/cobra\"\n)\n\nvar rootCmd = &cobra.Command{\n\tVersion: \"1.0\",\n\tUse: \"example_program\",\n\tShort: \"example_program - test fixture to check that deadcode elimination is allowed\",\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tfmt.Println(\"hello world\")\n\t},\n\tAliases: []string{\"alias1\", \"alias2\"},\n\tExample: \"stringer --help\",\n}\n\nfunc main() {\n\tif err := rootCmd.Execute(); err != nil {\n\t\tfmt.Fprintf(os.Stderr, \"Whoops. There was an error while executing your CLI '%s'\", err)\n\t\tos.Exit(1)\n\t}\n}\n`), 0600)\n\tif err != nil {\n\t\tt.Fatalf(\"could not write test program: %v\", err)\n\t}\n\tbuf, err := exec.Command(\"go\", \"build\", filename).CombinedOutput()\n\tif err != nil {\n\t\tt.Fatal"} | |
| {"repo":"cobra","file":"cobra_test.go","line":253,"symbol":"dirname","kind":"constant","lang":"go","code":"dirname = \"test_deadcode\""} | |
| {"repo":"cobra","file":"cobra_test.go","line":254,"symbol":"progname","kind":"constant","lang":"go","code":"progname = \"test_deadcode_elimination\""} | |
| {"repo":"cobra","file":"command.go","line":34,"symbol":"FlagSetByCobraAnnotation","kind":"constant","lang":"go","code":"FlagSetByCobraAnnotation = \"cobra_annotation_flag_set_by_cobra\""} | |
| {"repo":"cobra","file":"command.go","line":35,"symbol":"CommandDisplayNameAnnotation","kind":"constant","lang":"go","code":"CommandDisplayNameAnnotation = \"cobra_annotation_command_display_name\""} | |
| {"repo":"cobra","file":"command.go","line":37,"symbol":"helpFlagName","kind":"constant","lang":"go","code":"helpFlagName = \"help\""} | |
| {"repo":"cobra","file":"command.go","line":38,"symbol":"helpCommandName","kind":"constant","lang":"go","code":"helpCommandName = \"help\""} | |
| {"repo":"cobra","file":"command.go","line":42,"symbol":"FParseErrWhitelist","kind":"type","lang":"go","doc":"FParseErrWhitelist configures Flag parse errors to be ignored","code":"type FParseErrWhitelist flag.ParseErrorsAllowlist"} | |
| {"repo":"cobra","file":"command.go","line":45,"symbol":"Group","kind":"type","lang":"go","doc":"Group Structure to manage groups for commands","code":"type Group struct {\n\tID string\n\tTitle string\n}"} | |
| {"repo":"cobra","file":"command.go","line":54,"symbol":"Command","kind":"type","lang":"go","doc":"Command is just that, a command for your application. E.g. 'go run ...' - 'run' is the command. Cobra requires you to define the usage and description as part of your command definition to ensure usability.","code":"type Command struct {\n\t// Use is the one-line usage message.\n\t// Recommended syntax is as follows:\n\t// [ ] identifies an optional argument. Arguments that are not enclosed in brackets are required.\n\t// ... indicates that you can specify multiple values for the previous argument.\n\t// | indicates mutually exclusive information. You can use the argument to the left of the separator or the\n\t// argument to the right of the separator. You cannot use both arguments in a single use of the command.\n\t// { } delimits a set of mutually exclusive arguments when one of the arguments is required. If the arguments are\n\t// optional, they are enclosed in brackets ([ ]).\n\t// Example: add [-F file | -D dir]... [-f format] profile\n\tUse string\n\n\t// Aliases is an array of aliases that can be used instead of the first word in Use.\n\tAliases []string\n\n\t// SuggestFor is an array of command names for which this command will be suggested -\n\t// similar to aliases but only suggests.\n\tSuggestFor []string\n\n\t// Short is the short description shown in the 'help' output.\n\tShort string\n\n\t// The group id under which this subcommand is grouped in the 'help' output of its parent.\n\tGroupID string\n\n\t/"} | |
| {"repo":"cobra","file":"command.go","line":269,"symbol":"Context","kind":"method","lang":"go","doc":"with ExecuteContext or the context was set with SetContext, the previously set context will be returned. Otherwise, nil is returned. Notice that a call to Execute and ExecuteC will replace a nil context of a command with a context.Background, so a background context will be returned by Context after one of these functions has been called.","code":"func (c *Command) Context() context.Context {\n\treturn c.ctx\n}"} | |
| {"repo":"cobra","file":"command.go","line":275,"symbol":"SetContext","kind":"method","lang":"go","doc":"SetContext sets context for the command. This context will be overwritten by Command.ExecuteContext or Command.ExecuteContextC.","code":"func (c *Command) SetContext(ctx context.Context) {\n\tc.ctx = ctx\n}"} | |
| {"repo":"cobra","file":"command.go","line":281,"symbol":"SetArgs","kind":"method","lang":"go","doc":"SetArgs sets arguments for the command. It is set to os.Args[1:] by default, if desired, can be overridden particularly useful when testing.","code":"func (c *Command) SetArgs(a []string) {\n\tc.args = a\n}"} | |
| {"repo":"cobra","file":"command.go","line":289,"symbol":"SetOutput","kind":"method","lang":"go","doc":"SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used. Deprecated: Use SetOut and/or SetErr instead","code":"func (c *Command) SetOutput(output io.Writer) {\n\tc.outWriter = output\n\tc.errWriter = output\n}"} | |
| {"repo":"cobra","file":"command.go","line":296,"symbol":"SetOut","kind":"method","lang":"go","doc":"SetOut sets the destination for usage messages. If newOut is nil, os.Stdout is used.","code":"func (c *Command) SetOut(newOut io.Writer) {\n\tc.outWriter = newOut\n}"} | |
| {"repo":"cobra","file":"command.go","line":302,"symbol":"SetErr","kind":"method","lang":"go","doc":"SetErr sets the destination for error messages. If newErr is nil, os.Stderr is used.","code":"func (c *Command) SetErr(newErr io.Writer) {\n\tc.errWriter = newErr\n}"} | |
| {"repo":"cobra","file":"command.go","line":308,"symbol":"SetIn","kind":"method","lang":"go","doc":"SetIn sets the source for input data If newIn is nil, os.Stdin is used.","code":"func (c *Command) SetIn(newIn io.Reader) {\n\tc.inReader = newIn\n}"} | |
| {"repo":"cobra","file":"command.go","line":313,"symbol":"SetUsageFunc","kind":"method","lang":"go","doc":"SetUsageFunc sets usage function. Usage can be defined by application.","code":"func (c *Command) SetUsageFunc(f func(*Command) error) {\n\tc.usageFunc = f\n}"} | |
| {"repo":"cobra","file":"command.go","line":318,"symbol":"SetUsageTemplate","kind":"method","lang":"go","doc":"SetUsageTemplate sets usage template. Can be defined by Application.","code":"func (c *Command) SetUsageTemplate(s string) {\n\tif s == \"\" {\n\t\tc.usageTemplate = nil\n\t\treturn\n\t}\n\tc.usageTemplate = tmpl(s)\n}"} | |
| {"repo":"cobra","file":"command.go","line":328,"symbol":"SetFlagErrorFunc","kind":"method","lang":"go","doc":"SetFlagErrorFunc sets a function to generate an error when flag parsing fails.","code":"func (c *Command) SetFlagErrorFunc(f func(*Command, error) error) {\n\tc.flagErrorFunc = f\n}"} | |
| {"repo":"cobra","file":"command.go","line":333,"symbol":"SetHelpFunc","kind":"method","lang":"go","doc":"SetHelpFunc sets help function. Can be defined by Application.","code":"func (c *Command) SetHelpFunc(f func(*Command, []string)) {\n\tc.helpFunc = f\n}"} | |
| {"repo":"cobra","file":"command.go","line":338,"symbol":"SetHelpCommand","kind":"method","lang":"go","doc":"SetHelpCommand sets help command.","code":"func (c *Command) SetHelpCommand(cmd *Command) {\n\tc.helpCommand = cmd\n}"} | |
| {"repo":"cobra","file":"command.go","line":343,"symbol":"SetHelpCommandGroupID","kind":"method","lang":"go","doc":"SetHelpCommandGroupID sets the group id of the help command.","code":"func (c *Command) SetHelpCommandGroupID(groupID string) {\n\tif c.helpCommand != nil {\n\t\tc.helpCommand.GroupID = groupID\n\t}\n\t// helpCommandGroupID is used if no helpCommand is defined by the user\n\tc.helpCommandGroupID = groupID\n}"} | |
| {"repo":"cobra","file":"command.go","line":352,"symbol":"SetCompletionCommandGroupID","kind":"method","lang":"go","doc":"SetCompletionCommandGroupID sets the group id of the completion command.","code":"func (c *Command) SetCompletionCommandGroupID(groupID string) {\n\t// completionCommandGroupID is used if no completion command is defined by the user\n\tc.Root().completionCommandGroupID = groupID\n}"} | |
| {"repo":"cobra","file":"command.go","line":358,"symbol":"SetHelpTemplate","kind":"method","lang":"go","doc":"SetHelpTemplate sets help template to be used. Application can use it to set custom template.","code":"func (c *Command) SetHelpTemplate(s string) {\n\tif s == \"\" {\n\t\tc.helpTemplate = nil\n\t\treturn\n\t}\n\tc.helpTemplate = tmpl(s)\n}"} | |
| {"repo":"cobra","file":"command.go","line":367,"symbol":"SetVersionTemplate","kind":"method","lang":"go","doc":"SetVersionTemplate sets version template to be used. Application can use it to set custom template.","code":"func (c *Command) SetVersionTemplate(s string) {\n\tif s == \"\" {\n\t\tc.versionTemplate = nil\n\t\treturn\n\t}\n\tc.versionTemplate = tmpl(s)\n}"} | |
| {"repo":"cobra","file":"command.go","line":376,"symbol":"SetErrPrefix","kind":"method","lang":"go","doc":"SetErrPrefix sets error message prefix to be used. Application can use it to set custom prefix.","code":"func (c *Command) SetErrPrefix(s string) {\n\tc.errPrefix = s\n}"} | |
| {"repo":"cobra","file":"command.go","line":382,"symbol":"SetGlobalNormalizationFunc","kind":"method","lang":"go","doc":"SetGlobalNormalizationFunc sets a normalization function to all flag sets and also to child commands. The user should not have a cyclic dependency on commands.","code":"func (c *Command) SetGlobalNormalizationFunc(n func(f *flag.FlagSet, name string) flag.NormalizedName) {\n\tc.Flags().SetNormalizeFunc(n)\n\tc.PersistentFlags().SetNormalizeFunc(n)\n\tc.globNormFunc = n\n\n\tfor _, command := range c.commands {\n\t\tcommand.SetGlobalNormalizationFunc(n)\n\t}\n}"} | |
| {"repo":"cobra","file":"command.go","line":393,"symbol":"OutOrStdout","kind":"method","lang":"go","doc":"OutOrStdout returns output to stdout.","code":"func (c *Command) OutOrStdout() io.Writer {\n\treturn c.getOut(os.Stdout)\n}"} | |
| {"repo":"cobra","file":"command.go","line":398,"symbol":"OutOrStderr","kind":"method","lang":"go","doc":"OutOrStderr returns output to stderr","code":"func (c *Command) OutOrStderr() io.Writer {\n\treturn c.getOut(os.Stderr)\n}"} | |
| {"repo":"cobra","file":"command.go","line":403,"symbol":"ErrOrStderr","kind":"method","lang":"go","doc":"ErrOrStderr returns output to stderr","code":"func (c *Command) ErrOrStderr() io.Writer {\n\treturn c.getErr(os.Stderr)\n}"} | |
| {"repo":"cobra","file":"command.go","line":408,"symbol":"InOrStdin","kind":"method","lang":"go","doc":"InOrStdin returns input to stdin","code":"func (c *Command) InOrStdin() io.Reader {\n\treturn c.getIn(os.Stdin)\n}"} | |
| {"repo":"cobra","file":"command.go","line":412,"symbol":"getOut","kind":"method","lang":"go","code":"func (c *Command) getOut(def io.Writer) io.Writer {\n\tif c.outWriter != nil {\n\t\treturn c.outWriter\n\t}\n\tif c.HasParent() {\n\t\treturn c.parent.getOut(def)\n\t}\n\treturn def\n}"} | |
| {"repo":"cobra","file":"command.go","line":422,"symbol":"getErr","kind":"method","lang":"go","code":"func (c *Command) getErr(def io.Writer) io.Writer {\n\tif c.errWriter != nil {\n\t\treturn c.errWriter\n\t}\n\tif c.HasParent() {\n\t\treturn c.parent.getErr(def)\n\t}\n\treturn def\n}"} | |
| {"repo":"cobra","file":"command.go","line":432,"symbol":"getIn","kind":"method","lang":"go","code":"func (c *Command) getIn(def io.Reader) io.Reader {\n\tif c.inReader != nil {\n\t\treturn c.inReader\n\t}\n\tif c.HasParent() {\n\t\treturn c.parent.getIn(def)\n\t}\n\treturn def\n}"} | |
| {"repo":"cobra","file":"command.go","line":444,"symbol":"UsageFunc","kind":"method","lang":"go","doc":"UsageFunc returns either the function set by SetUsageFunc for this command or a parent, or it returns a default usage function.","code":"func (c *Command) UsageFunc() (f func(*Command) error) {\n\tif c.usageFunc != nil {\n\t\treturn c.usageFunc\n\t}\n\tif c.HasParent() {\n\t\treturn c.Parent().UsageFunc()\n\t}\n\treturn func(c *Command) error {\n\t\tc.mergePersistentFlags()\n\t\tfn := c.getUsageTemplateFunc()\n\t\terr := fn(c.OutOrStderr(), c)\n\t\tif err != nil {\n\t\t\tc.PrintErrln(err)\n\t\t}\n\t\treturn err\n\t}\n}"} | |
| {"repo":"cobra","file":"command.go","line":464,"symbol":"getUsageTemplateFunc","kind":"method","lang":"go","doc":"getUsageTemplateFunc returns the usage template function for the command going up the command tree if necessary.","code":"func (c *Command) getUsageTemplateFunc() func(w io.Writer, data interface{}) error {\n\tif c.usageTemplate != nil {\n\t\treturn c.usageTemplate.fn\n\t}\n\n\tif c.HasParent() {\n\t\treturn c.parent.getUsageTemplateFunc()\n\t}\n\treturn defaultUsageFunc\n}"} | |
| {"repo":"cobra","file":"command.go","line":478,"symbol":"Usage","kind":"method","lang":"go","doc":"Usage puts out the usage for the command. Used when a user provides invalid input. Can be defined by user by overriding UsageFunc.","code":"func (c *Command) Usage() error {\n\treturn c.UsageFunc()(c)\n}"} | |
| {"repo":"cobra","file":"command.go","line":484,"symbol":"HelpFunc","kind":"method","lang":"go","doc":"HelpFunc returns either the function set by SetHelpFunc for this command or a parent, or it returns a function with default help behavior.","code":"func (c *Command) HelpFunc() func(*Command, []string) {\n\tif c.helpFunc != nil {\n\t\treturn c.helpFunc\n\t}\n\tif c.HasParent() {\n\t\treturn c.Parent().HelpFunc()\n\t}\n\treturn func(c *Command, a []string) {\n\t\tc.mergePersistentFlags()\n\t\tfn := c.getHelpTemplateFunc()\n\t\t// The help should be sent to stdout\n\t\t// See https://github.com/spf13/cobra/issues/1002\n\t\terr := fn(c.OutOrStdout(), c)\n\t\tif err != nil {\n\t\t\tc.PrintErrln(err)\n\t\t}\n\t}\n}"} | |
| {"repo":"cobra","file":"command.go","line":505,"symbol":"getHelpTemplateFunc","kind":"method","lang":"go","doc":"getHelpTemplateFunc returns the help template function for the command going up the command tree if necessary.","code":"func (c *Command) getHelpTemplateFunc() func(w io.Writer, data interface{}) error {\n\tif c.helpTemplate != nil {\n\t\treturn c.helpTemplate.fn\n\t}\n\n\tif c.HasParent() {\n\t\treturn c.parent.getHelpTemplateFunc()\n\t}\n\n\treturn defaultHelpFunc\n}"} | |
| {"repo":"cobra","file":"command.go","line":520,"symbol":"Help","kind":"method","lang":"go","doc":"Help puts out the help for the command. Used when a user calls help [command]. Can be defined by user by overriding HelpFunc.","code":"func (c *Command) Help() error {\n\tc.HelpFunc()(c, []string{})\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"command.go","line":526,"symbol":"UsageString","kind":"method","lang":"go","doc":"UsageString returns usage string.","code":"func (c *Command) UsageString() string {\n\t// Storing normal writers\n\ttmpOutput := c.outWriter\n\ttmpErr := c.errWriter\n\n\tbb := new(bytes.Buffer)\n\tc.outWriter = bb\n\tc.errWriter = bb\n\n\tCheckErr(c.Usage())\n\n\t// Setting things back to normal\n\tc.outWriter = tmpOutput\n\tc.errWriter = tmpErr\n\n\treturn bb.String()\n}"} | |
| {"repo":"cobra","file":"command.go","line":547,"symbol":"FlagErrorFunc","kind":"method","lang":"go","doc":"FlagErrorFunc returns either the function set by SetFlagErrorFunc for this command or a parent, or it returns a function which returns the original error.","code":"func (c *Command) FlagErrorFunc() (f func(*Command, error) error) {\n\tif c.flagErrorFunc != nil {\n\t\treturn c.flagErrorFunc\n\t}\n\n\tif c.HasParent() {\n\t\treturn c.parent.FlagErrorFunc()\n\t}\n\treturn func(c *Command, err error) error {\n\t\treturn err\n\t}\n}"} | |
| {"repo":"cobra","file":"command.go","line":560,"symbol":"minUsagePadding","kind":"constant","lang":"go","code":"minUsagePadding = 25"} | |
| {"repo":"cobra","file":"command.go","line":563,"symbol":"UsagePadding","kind":"method","lang":"go","doc":"UsagePadding return padding for the usage.","code":"func (c *Command) UsagePadding() int {\n\tif c.parent == nil || minUsagePadding > c.parent.commandsMaxUseLen {\n\t\treturn minUsagePadding\n\t}\n\treturn c.parent.commandsMaxUseLen\n}"} | |
| {"repo":"cobra","file":"command.go","line":570,"symbol":"minCommandPathPadding","kind":"constant","lang":"go","code":"minCommandPathPadding = 11"} | |
| {"repo":"cobra","file":"command.go","line":573,"symbol":"CommandPathPadding","kind":"method","lang":"go","doc":"CommandPathPadding return padding for the command path.","code":"func (c *Command) CommandPathPadding() int {\n\tif c.parent == nil || minCommandPathPadding > c.parent.commandsMaxCommandPathLen {\n\t\treturn minCommandPathPadding\n\t}\n\treturn c.parent.commandsMaxCommandPathLen\n}"} | |
| {"repo":"cobra","file":"command.go","line":580,"symbol":"minNamePadding","kind":"constant","lang":"go","code":"minNamePadding = 11"} | |
| {"repo":"cobra","file":"command.go","line":583,"symbol":"NamePadding","kind":"method","lang":"go","doc":"NamePadding returns padding for the name.","code":"func (c *Command) NamePadding() int {\n\tif c.parent == nil || minNamePadding > c.parent.commandsMaxNameLen {\n\t\treturn minNamePadding\n\t}\n\treturn c.parent.commandsMaxNameLen\n}"} | |
| {"repo":"cobra","file":"command.go","line":592,"symbol":"UsageTemplate","kind":"method","lang":"go","doc":"UsageTemplate returns usage template for the command. This function is kept for backwards-compatibility reasons.","code":"func (c *Command) UsageTemplate() string {\n\tif c.usageTemplate != nil {\n\t\treturn c.usageTemplate.tmpl\n\t}\n\n\tif c.HasParent() {\n\t\treturn c.parent.UsageTemplate()\n\t}\n\treturn defaultUsageTemplate\n}"} | |
| {"repo":"cobra","file":"command.go","line":605,"symbol":"HelpTemplate","kind":"method","lang":"go","doc":"HelpTemplate return help template for the command. This function is kept for backwards-compatibility reasons.","code":"func (c *Command) HelpTemplate() string {\n\tif c.helpTemplate != nil {\n\t\treturn c.helpTemplate.tmpl\n\t}\n\n\tif c.HasParent() {\n\t\treturn c.parent.HelpTemplate()\n\t}\n\treturn defaultHelpTemplate\n}"} | |
| {"repo":"cobra","file":"command.go","line":618,"symbol":"VersionTemplate","kind":"method","lang":"go","doc":"VersionTemplate return version template for the command. This function is kept for backwards-compatibility reasons.","code":"func (c *Command) VersionTemplate() string {\n\tif c.versionTemplate != nil {\n\t\treturn c.versionTemplate.tmpl\n\t}\n\n\tif c.HasParent() {\n\t\treturn c.parent.VersionTemplate()\n\t}\n\treturn defaultVersionTemplate\n}"} | |
| {"repo":"cobra","file":"command.go","line":631,"symbol":"getVersionTemplateFunc","kind":"method","lang":"go","doc":"getVersionTemplateFunc returns the version template function for the command going up the command tree if necessary.","code":"func (c *Command) getVersionTemplateFunc() func(w io.Writer, data interface{}) error {\n\tif c.versionTemplate != nil {\n\t\treturn c.versionTemplate.fn\n\t}\n\n\tif c.HasParent() {\n\t\treturn c.parent.getVersionTemplateFunc()\n\t}\n\treturn defaultVersionFunc\n}"} | |
| {"repo":"cobra","file":"command.go","line":643,"symbol":"ErrPrefix","kind":"method","lang":"go","doc":"ErrPrefix return error message prefix for the command","code":"func (c *Command) ErrPrefix() string {\n\tif c.errPrefix != \"\" {\n\t\treturn c.errPrefix\n\t}\n\n\tif c.HasParent() {\n\t\treturn c.parent.ErrPrefix()\n\t}\n\treturn \"Error:\"\n}"} | |
| {"repo":"cobra","file":"command.go","line":654,"symbol":"hasNoOptDefVal","kind":"function","lang":"go","code":"func hasNoOptDefVal(name string, fs *flag.FlagSet) bool {\n\tflag := fs.Lookup(name)\n\tif flag == nil {\n\t\treturn false\n\t}\n\treturn flag.NoOptDefVal != \"\"\n}"} | |
| {"repo":"cobra","file":"command.go","line":662,"symbol":"shortHasNoOptDefVal","kind":"function","lang":"go","code":"func shortHasNoOptDefVal(name string, fs *flag.FlagSet) bool {\n\tif len(name) == 0 {\n\t\treturn false\n\t}\n\n\tflag := fs.ShorthandLookup(name[:1])\n\tif flag == nil {\n\t\treturn false\n\t}\n\treturn flag.NoOptDefVal != \"\"\n}"} | |
| {"repo":"cobra","file":"command.go","line":674,"symbol":"stripFlags","kind":"function","lang":"go","code":"func stripFlags(args []string, c *Command) []string {\n\tif len(args) == 0 {\n\t\treturn args\n\t}\n\tc.mergePersistentFlags()\n\n\tcommands := []string{}\n\tflags := c.Flags()\n\nLoop:\n\tfor len(args) > 0 {\n\t\ts := args[0]\n\t\targs = args[1:]\n\t\tswitch {\n\t\tcase s == \"--\":\n\t\t\t// \"--\" terminates the flags\n\t\t\tbreak Loop\n\t\tcase strings.HasPrefix(s, \"--\") && !strings.Contains(s, \"=\") && !hasNoOptDefVal(s[2:], flags):\n\t\t\t// If '--flag arg' then\n\t\t\t// delete arg from args.\n\t\t\tfallthrough // (do the same as below)\n\t\tcase strings.HasPrefix(s, \"-\") && !strings.Contains(s, \"=\") && len(s) == 2 && !shortHasNoOptDefVal(s[1:], flags):\n\t\t\t// If '-f arg' then\n\t\t\t// delete 'arg' from args or break the loop if len(args) <= 1.\n\t\t\tif len(args) <= 1 {\n\t\t\t\tbreak Loop\n\t\t\t} else {\n\t\t\t\targs = args[1:]\n\t\t\t\tcontinue\n\t\t\t}\n\t\tcase s != \"\" && !strings.HasPrefix(s, \"-\"):\n\t\t\tcommands = append(commands, s)\n\t\t}\n\t}\n\n\treturn commands\n}"} | |
| {"repo":"cobra","file":"command.go","line":715,"symbol":"argsMinusFirstX","kind":"method","lang":"go","doc":"argsMinusFirstX removes only the first x from args. Otherwise, commands that look like openshift admin policy add-role-to-user admin my-user, lose the admin argument (arg[4]). Special care needs to be taken not to remove a flag value.","code":"func (c *Command) argsMinusFirstX(args []string, x string) []string {\n\tif len(args) == 0 {\n\t\treturn args\n\t}\n\tc.mergePersistentFlags()\n\tflags := c.Flags()\n\nLoop:\n\tfor pos := 0; pos < len(args); pos++ {\n\t\ts := args[pos]\n\t\tswitch {\n\t\tcase s == \"--\":\n\t\t\t// -- means we have reached the end of the parseable args. Break out of the loop now.\n\t\t\tbreak Loop\n\t\tcase strings.HasPrefix(s, \"--\") && !strings.Contains(s, \"=\") && !hasNoOptDefVal(s[2:], flags):\n\t\t\tfallthrough\n\t\tcase strings.HasPrefix(s, \"-\") && !strings.Contains(s, \"=\") && len(s) == 2 && !shortHasNoOptDefVal(s[1:], flags):\n\t\t\t// This is a flag without a default value, and an equal sign is not used. Increment pos in order to skip\n\t\t\t// over the next arg, because that is the value of this flag.\n\t\t\tpos++\n\t\t\tcontinue\n\t\tcase !strings.HasPrefix(s, \"-\"):\n\t\t\t// This is not a flag or a flag value. Check to see if it matches what we're looking for, and if so,\n\t\t\t// return the args, excluding the one at this position.\n\t\t\tif s == x {\n\t\t\t\tret := make([]string, 0, len(args)-1)\n\t\t\t\tret = append(ret, args[:pos]...)\n\t\t\t\tret = append(ret, args[pos+1:]...)\n\t\t\t\treturn ret\n\t\t\t}\n\t\t}\n\t}\n\treturn args\n}"} | |
| {"repo":"cobra","file":"command.go","line":750,"symbol":"isFlagArg","kind":"function","lang":"go","code":"func isFlagArg(arg string) bool {\n\treturn ((len(arg) >= 3 && arg[0:2] == \"--\") ||\n\t\t(len(arg) >= 2 && arg[0] == '-' && arg[1] != '-'))\n}"} | |
| {"repo":"cobra","file":"command.go","line":757,"symbol":"Find","kind":"method","lang":"go","doc":"Find the target command given the args and command tree Meant to be run on the highest node. Only searches down.","code":"func (c *Command) Find(args []string) (*Command, []string, error) {\n\tvar innerfind func(*Command, []string) (*Command, []string)\n\n\tinnerfind = func(c *Command, innerArgs []string) (*Command, []string) {\n\t\targsWOflags := stripFlags(innerArgs, c)\n\t\tif len(argsWOflags) == 0 {\n\t\t\treturn c, innerArgs\n\t\t}\n\t\tnextSubCmd := argsWOflags[0]\n\n\t\tcmd := c.findNext(nextSubCmd)\n\t\tif cmd != nil {\n\t\t\treturn innerfind(cmd, c.argsMinusFirstX(innerArgs, nextSubCmd))\n\t\t}\n\t\treturn c, innerArgs\n\t}\n\n\tcommandFound, a := innerfind(c, args)\n\tif commandFound.Args == nil {\n\t\treturn commandFound, a, legacyArgs(commandFound, stripFlags(a, commandFound))\n\t}\n\treturn commandFound, a, nil\n}"} | |
| {"repo":"cobra","file":"command.go","line":758,"symbol":"innerfind","kind":"variable","lang":"go","code":"innerfind func(*Command, []string) (*Command, []string)"} | |
| {"repo":"cobra","file":"command.go","line":781,"symbol":"findSuggestions","kind":"method","lang":"go","code":"func (c *Command) findSuggestions(arg string) string {\n\tif c.DisableSuggestions {\n\t\treturn \"\"\n\t}\n\tif c.SuggestionsMinimumDistance <= 0 {\n\t\tc.SuggestionsMinimumDistance = 2\n\t}\n\tvar sb strings.Builder\n\tif suggestions := c.SuggestionsFor(arg); len(suggestions) > 0 {\n\t\tsb.WriteString(\"\\n\\nDid you mean this?\\n\")\n\t\tfor _, s := range suggestions {\n\t\t\t_, _ = fmt.Fprintf(&sb, \"\\t%v\\n\", s)\n\t\t}\n\t}\n\treturn sb.String()\n}"} | |
| {"repo":"cobra","file":"command.go","line":788,"symbol":"sb","kind":"variable","lang":"go","code":"sb strings.Builder"} | |
| {"repo":"cobra","file":"command_notwin.go","line":20,"symbol":"preExecHookFn","kind":"variable","lang":"go","code":"preExecHookFn func(*Command)"} | |
| {"repo":"cobra","file":"command_test.go","line":30,"symbol":"emptyRun","kind":"function","lang":"go","code":"func emptyRun(*Command, []string) {}"} | |
| {"repo":"cobra","file":"command_test.go","line":32,"symbol":"executeCommand","kind":"function","lang":"go","code":"func executeCommand(root *Command, args ...string) (output string, err error) {\n\t_, output, err = executeCommandC(root, args...)\n\treturn output, err\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":37,"symbol":"executeCommandWithContext","kind":"function","lang":"go","code":"func executeCommandWithContext(ctx context.Context, root *Command, args ...string) (output string, err error) {\n\tbuf := new(bytes.Buffer)\n\troot.SetOut(buf)\n\troot.SetErr(buf)\n\troot.SetArgs(args)\n\n\terr = root.ExecuteContext(ctx)\n\n\treturn buf.String(), err\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":48,"symbol":"executeCommandC","kind":"function","lang":"go","code":"func executeCommandC(root *Command, args ...string) (c *Command, output string, err error) {\n\tbuf := new(bytes.Buffer)\n\troot.SetOut(buf)\n\troot.SetErr(buf)\n\troot.SetArgs(args)\n\n\tc, err = root.ExecuteC()\n\n\treturn c, buf.String(), err\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":59,"symbol":"executeCommandWithContextC","kind":"function","lang":"go","code":"func executeCommandWithContextC(ctx context.Context, root *Command, args ...string) (c *Command, output string, err error) {\n\tbuf := new(bytes.Buffer)\n\troot.SetOut(buf)\n\troot.SetErr(buf)\n\troot.SetArgs(args)\n\n\tc, err = root.ExecuteContextC(ctx)\n\n\treturn c, buf.String(), err\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":70,"symbol":"resetCommandLineFlagSet","kind":"function","lang":"go","code":"func resetCommandLineFlagSet() {\n\tpflag.CommandLine = pflag.NewFlagSet(os.Args[0], pflag.ExitOnError)\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":74,"symbol":"checkStringContains","kind":"function","lang":"go","code":"func checkStringContains(t *testing.T, got, expected string) {\n\tif !strings.Contains(got, expected) {\n\t\tt.Errorf(\"Expected to contain: \\n %v\\nGot:\\n %v\\n\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":80,"symbol":"checkStringOmits","kind":"function","lang":"go","code":"func checkStringOmits(t *testing.T, got, expected string) {\n\tif strings.Contains(got, expected) {\n\t\tt.Errorf(\"Expected to not contain: \\n %v\\nGot: %v\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":86,"symbol":"onetwo","kind":"constant","lang":"go","code":"onetwo = \"one two\""} | |
| {"repo":"cobra","file":"command_test.go","line":88,"symbol":"TestSingleCommand","kind":"function","lang":"go","code":"func TestSingleCommand(t *testing.T) {\n\tvar rootCmdArgs []string\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tArgs: ExactArgs(2),\n\t\tRun: func(_ *Command, args []string) { rootCmdArgs = args },\n\t}\n\taCmd := &Command{Use: \"a\", Args: NoArgs, Run: emptyRun}\n\tbCmd := &Command{Use: \"b\", Args: NoArgs, Run: emptyRun}\n\trootCmd.AddCommand(aCmd, bCmd)\n\n\toutput, err := executeCommand(rootCmd, \"one\", \"two\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tgot := strings.Join(rootCmdArgs, \" \")\n\tif got != onetwo {\n\t\tt.Errorf(\"rootCmdArgs expected: %q, got: %q\", onetwo, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":89,"symbol":"rootCmdArgs","kind":"variable","lang":"go","code":"rootCmdArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":113,"symbol":"TestChildCommand","kind":"function","lang":"go","code":"func TestChildCommand(t *testing.T) {\n\tvar child1CmdArgs []string\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild1Cmd := &Command{\n\t\tUse: \"child1\",\n\t\tArgs: ExactArgs(2),\n\t\tRun: func(_ *Command, args []string) { child1CmdArgs = args },\n\t}\n\tchild2Cmd := &Command{Use: \"child2\", Args: NoArgs, Run: emptyRun}\n\trootCmd.AddCommand(child1Cmd, child2Cmd)\n\n\toutput, err := executeCommand(rootCmd, \"child1\", \"one\", \"two\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tgot := strings.Join(child1CmdArgs, \" \")\n\tif got != onetwo {\n\t\tt.Errorf(\"child1CmdArgs expected: %q, got: %q\", onetwo, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":114,"symbol":"child1CmdArgs","kind":"variable","lang":"go","code":"child1CmdArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":138,"symbol":"TestCallCommandWithoutSubcommands","kind":"function","lang":"go","code":"func TestCallCommandWithoutSubcommands(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\t_, err := executeCommand(rootCmd)\n\tif err != nil {\n\t\tt.Errorf(\"Calling command without subcommands should not have error: %v\", err)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":146,"symbol":"TestRootExecuteUnknownCommand","kind":"function","lang":"go","code":"func TestRootExecuteUnknownCommand(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\trootCmd.AddCommand(&Command{Use: \"child\", Run: emptyRun})\n\n\toutput, _ := executeCommand(rootCmd, \"unknown\")\n\n\texpected := \"Error: unknown command \\\"unknown\\\" for \\\"root\\\"\\nRun 'root --help' for usage.\\n\"\n\n\tif output != expected {\n\t\tt.Errorf(\"Expected:\\n %q\\nGot:\\n %q\\n\", expected, output)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":159,"symbol":"TestSubcommandExecuteC","kind":"function","lang":"go","code":"func TestSubcommandExecuteC(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\tchildCmd := &Command{Use: \"child\", Run: emptyRun}\n\trootCmd.AddCommand(childCmd)\n\n\tc, output, err := executeCommandC(rootCmd, \"child\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tif c.Name() != \"child\" {\n\t\tt.Errorf(`invalid command returned from ExecuteC: expected \"child\"', got: %q`, c.Name())\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":177,"symbol":"TestExecuteContext","kind":"function","lang":"go","code":"func TestExecuteContext(t *testing.T) {\n\tctx := context.TODO()\n\n\tctxRun := func(cmd *Command, args []string) {\n\t\tif cmd.Context() != ctx {\n\t\t\tt.Errorf(\"Command %q must have context when called with ExecuteContext\", cmd.Use)\n\t\t}\n\t}\n\n\trootCmd := &Command{Use: \"root\", Run: ctxRun, PreRun: ctxRun}\n\tchildCmd := &Command{Use: \"child\", Run: ctxRun, PreRun: ctxRun}\n\tgranchildCmd := &Command{Use: \"grandchild\", Run: ctxRun, PreRun: ctxRun}\n\n\tchildCmd.AddCommand(granchildCmd)\n\trootCmd.AddCommand(childCmd)\n\n\tif _, err := executeCommandWithContext(ctx, rootCmd, \"\"); err != nil {\n\t\tt.Errorf(\"Root command must not fail: %+v\", err)\n\t}\n\n\tif _, err := executeCommandWithContext(ctx, rootCmd, \"child\"); err != nil {\n\t\tt.Errorf(\"Subcommand must not fail: %+v\", err)\n\t}\n\n\tif _, err := executeCommandWithContext(ctx, rootCmd, \"child\", \"grandchild\"); err != nil {\n\t\tt.Errorf(\"Command child must not fail: %+v\", err)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":206,"symbol":"TestExecuteContextC","kind":"function","lang":"go","code":"func TestExecuteContextC(t *testing.T) {\n\tctx := context.TODO()\n\n\tctxRun := func(cmd *Command, args []string) {\n\t\tif cmd.Context() != ctx {\n\t\t\tt.Errorf(\"Command %q must have context when called with ExecuteContext\", cmd.Use)\n\t\t}\n\t}\n\n\trootCmd := &Command{Use: \"root\", Run: ctxRun, PreRun: ctxRun}\n\tchildCmd := &Command{Use: \"child\", Run: ctxRun, PreRun: ctxRun}\n\tgranchildCmd := &Command{Use: \"grandchild\", Run: ctxRun, PreRun: ctxRun}\n\n\tchildCmd.AddCommand(granchildCmd)\n\trootCmd.AddCommand(childCmd)\n\n\tif _, _, err := executeCommandWithContextC(ctx, rootCmd, \"\"); err != nil {\n\t\tt.Errorf(\"Root command must not fail: %+v\", err)\n\t}\n\n\tif _, _, err := executeCommandWithContextC(ctx, rootCmd, \"child\"); err != nil {\n\t\tt.Errorf(\"Subcommand must not fail: %+v\", err)\n\t}\n\n\tif _, _, err := executeCommandWithContextC(ctx, rootCmd, \"child\", \"grandchild\"); err != nil {\n\t\tt.Errorf(\"Command child must not fail: %+v\", err)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":235,"symbol":"TestExecute_NoContext","kind":"function","lang":"go","code":"func TestExecute_NoContext(t *testing.T) {\n\trun := func(cmd *Command, args []string) {\n\t\tif cmd.Context() != context.Background() {\n\t\t\tt.Errorf(\"Command %s must have background context\", cmd.Use)\n\t\t}\n\t}\n\n\trootCmd := &Command{Use: \"root\", Run: run, PreRun: run}\n\tchildCmd := &Command{Use: \"child\", Run: run, PreRun: run}\n\tgranchildCmd := &Command{Use: \"grandchild\", Run: run, PreRun: run}\n\n\tchildCmd.AddCommand(granchildCmd)\n\trootCmd.AddCommand(childCmd)\n\n\tif _, err := executeCommand(rootCmd, \"\"); err != nil {\n\t\tt.Errorf(\"Root command must not fail: %+v\", err)\n\t}\n\n\tif _, err := executeCommand(rootCmd, \"child\"); err != nil {\n\t\tt.Errorf(\"Subcommand must not fail: %+v\", err)\n\t}\n\n\tif _, err := executeCommand(rootCmd, \"child\", \"grandchild\"); err != nil {\n\t\tt.Errorf(\"Command child must not fail: %+v\", err)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":262,"symbol":"TestRootUnknownCommandSilenced","kind":"function","lang":"go","code":"func TestRootUnknownCommandSilenced(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\trootCmd.SilenceErrors = true\n\trootCmd.SilenceUsage = true\n\trootCmd.AddCommand(&Command{Use: \"child\", Run: emptyRun})\n\n\toutput, _ := executeCommand(rootCmd, \"unknown\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Expected blank output, because of silenced usage.\\nGot:\\n %q\\n\", output)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":274,"symbol":"TestCommandAlias","kind":"function","lang":"go","code":"func TestCommandAlias(t *testing.T) {\n\tvar timesCmdArgs []string\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\techoCmd := &Command{\n\t\tUse: \"echo\",\n\t\tAliases: []string{\"say\", \"tell\"},\n\t\tArgs: NoArgs,\n\t\tRun: emptyRun,\n\t}\n\ttimesCmd := &Command{\n\t\tUse: \"times\",\n\t\tArgs: ExactArgs(2),\n\t\tRun: func(_ *Command, args []string) { timesCmdArgs = args },\n\t}\n\techoCmd.AddCommand(timesCmd)\n\trootCmd.AddCommand(echoCmd)\n\n\toutput, err := executeCommand(rootCmd, \"tell\", \"times\", \"one\", \"two\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tgot := strings.Join(timesCmdArgs, \" \")\n\tif got != onetwo {\n\t\tt.Errorf(\"timesCmdArgs expected: %v, got: %v\", onetwo, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":275,"symbol":"timesCmdArgs","kind":"variable","lang":"go","code":"timesCmdArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":305,"symbol":"TestEnablePrefixMatching","kind":"function","lang":"go","code":"func TestEnablePrefixMatching(t *testing.T) {\n\tEnablePrefixMatching = true\n\n\tvar aCmdArgs []string\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\taCmd := &Command{\n\t\tUse: \"aCmd\",\n\t\tArgs: ExactArgs(2),\n\t\tRun: func(_ *Command, args []string) { aCmdArgs = args },\n\t}\n\tbCmd := &Command{Use: \"bCmd\", Args: NoArgs, Run: emptyRun}\n\trootCmd.AddCommand(aCmd, bCmd)\n\n\toutput, err := executeCommand(rootCmd, \"a\", \"one\", \"two\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tgot := strings.Join(aCmdArgs, \" \")\n\tif got != onetwo {\n\t\tt.Errorf(\"aCmdArgs expected: %q, got: %q\", onetwo, got)\n\t}\n\n\tEnablePrefixMatching = defaultPrefixMatching\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":308,"symbol":"aCmdArgs","kind":"variable","lang":"go","code":"aCmdArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":334,"symbol":"TestAliasPrefixMatching","kind":"function","lang":"go","code":"func TestAliasPrefixMatching(t *testing.T) {\n\tEnablePrefixMatching = true\n\n\tvar timesCmdArgs []string\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\techoCmd := &Command{\n\t\tUse: \"echo\",\n\t\tAliases: []string{\"say\", \"tell\"},\n\t\tArgs: NoArgs,\n\t\tRun: emptyRun,\n\t}\n\ttimesCmd := &Command{\n\t\tUse: \"times\",\n\t\tArgs: ExactArgs(2),\n\t\tRun: func(_ *Command, args []string) { timesCmdArgs = args },\n\t}\n\techoCmd.AddCommand(timesCmd)\n\trootCmd.AddCommand(echoCmd)\n\n\toutput, err := executeCommand(rootCmd, \"sa\", \"times\", \"one\", \"two\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tgot := strings.Join(timesCmdArgs, \" \")\n\tif got != onetwo {\n\t\tt.Errorf(\"timesCmdArgs expected: %v, got: %v\", onetwo, got)\n\t}\n\n\tEnablePrefixMatching = defaultPrefixMatching\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":337,"symbol":"timesCmdArgs","kind":"variable","lang":"go","code":"timesCmdArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":372,"symbol":"TestPlugin","kind":"function","lang":"go","doc":"TestPlugin checks usage as plugin for another command such as kubectl. The executable is `kubectl-plugin`, but we run it as `kubectl plugin`. The help text should reflect the way we run the command.","code":"func TestPlugin(t *testing.T) {\n\tcmd := &Command{\n\t\tUse: \"kubectl-plugin\",\n\t\tVersion: \"1.0.0\",\n\t\tArgs: NoArgs,\n\t\tAnnotations: map[string]string{\n\t\t\tCommandDisplayNameAnnotation: \"kubectl plugin\",\n\t\t},\n\t\tRun: emptyRun,\n\t}\n\n\tcmdHelp, err := executeCommand(cmd, \"-h\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tcheckStringContains(t, cmdHelp, \"kubectl plugin [flags]\")\n\tcheckStringContains(t, cmdHelp, \"help for kubectl plugin\")\n\tcheckStringContains(t, cmdHelp, \"version for kubectl plugin\")\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":394,"symbol":"TestPluginWithSubCommands","kind":"function","lang":"go","doc":"TestPluginWithSubCommands checks usage as plugin with sub commands.","code":"func TestPluginWithSubCommands(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"kubectl-plugin\",\n\t\tVersion: \"1.0.0\",\n\t\tArgs: NoArgs,\n\t\tAnnotations: map[string]string{\n\t\t\tCommandDisplayNameAnnotation: \"kubectl plugin\",\n\t\t},\n\t}\n\n\tsubCmd := &Command{Use: \"sub [flags]\", Args: NoArgs, Run: emptyRun}\n\trootCmd.AddCommand(subCmd)\n\n\trootHelp, err := executeCommand(rootCmd, \"-h\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tcheckStringContains(t, rootHelp, \"kubectl plugin [command]\")\n\tcheckStringContains(t, rootHelp, \"help for kubectl plugin\")\n\tcheckStringContains(t, rootHelp, \"version for kubectl plugin\")\n\tcheckStringContains(t, rootHelp, \"kubectl plugin [command] --help\")\n\n\tchildHelp, err := executeCommand(rootCmd, \"sub\", \"-h\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tcheckStringContains(t, childHelp, \"kubectl plugin sub [flags]\")\n\tcheckStringContains(t, childHelp, \"help for sub\")\n\n\thelpHelp, err := executeCommand(rootCmd, \"help\", \"-h\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tcheckStringContains(t, helpHelp, \"kubectl plugin help [path to command]\")\n\tcheckStringContains(t, helpHelp, \"kubectl plugin help [command]\")\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":437,"symbol":"TestChildSameName","kind":"function","lang":"go","doc":"TestChildSameName checks the correct behaviour of cobra in cases, when an application with name \"foo\" and with subcommand \"foo\" is executed with args \"foo foo\".","code":"func TestChildSameName(t *testing.T) {\n\tvar fooCmdArgs []string\n\trootCmd := &Command{Use: \"foo\", Args: NoArgs, Run: emptyRun}\n\tfooCmd := &Command{\n\t\tUse: \"foo\",\n\t\tArgs: ExactArgs(2),\n\t\tRun: func(_ *Command, args []string) { fooCmdArgs = args },\n\t}\n\tbarCmd := &Command{Use: \"bar\", Args: NoArgs, Run: emptyRun}\n\trootCmd.AddCommand(fooCmd, barCmd)\n\n\toutput, err := executeCommand(rootCmd, \"foo\", \"one\", \"two\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tgot := strings.Join(fooCmdArgs, \" \")\n\tif got != onetwo {\n\t\tt.Errorf(\"fooCmdArgs expected: %v, got: %v\", onetwo, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":438,"symbol":"fooCmdArgs","kind":"variable","lang":"go","code":"fooCmdArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":465,"symbol":"TestGrandChildSameName","kind":"function","lang":"go","doc":"TestGrandChildSameName checks the correct behaviour of cobra in cases, when user has a root command and a grand child with the same name.","code":"func TestGrandChildSameName(t *testing.T) {\n\tvar fooCmdArgs []string\n\trootCmd := &Command{Use: \"foo\", Args: NoArgs, Run: emptyRun}\n\tbarCmd := &Command{Use: \"bar\", Args: NoArgs, Run: emptyRun}\n\tfooCmd := &Command{\n\t\tUse: \"foo\",\n\t\tArgs: ExactArgs(2),\n\t\tRun: func(_ *Command, args []string) { fooCmdArgs = args },\n\t}\n\tbarCmd.AddCommand(fooCmd)\n\trootCmd.AddCommand(barCmd)\n\n\toutput, err := executeCommand(rootCmd, \"bar\", \"foo\", \"one\", \"two\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tgot := strings.Join(fooCmdArgs, \" \")\n\tif got != onetwo {\n\t\tt.Errorf(\"fooCmdArgs expected: %v, got: %v\", onetwo, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":466,"symbol":"fooCmdArgs","kind":"variable","lang":"go","code":"fooCmdArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":491,"symbol":"TestFlagLong","kind":"function","lang":"go","code":"func TestFlagLong(t *testing.T) {\n\tvar cArgs []string\n\tc := &Command{\n\t\tUse: \"c\",\n\t\tArgs: ArbitraryArgs,\n\t\tRun: func(_ *Command, args []string) { cArgs = args },\n\t}\n\n\tvar intFlagValue int\n\tvar stringFlagValue string\n\tc.Flags().IntVar(&intFlagValue, \"intf\", -1, \"\")\n\tc.Flags().StringVar(&stringFlagValue, \"sf\", \"\", \"\")\n\n\toutput, err := executeCommand(c, \"--intf=7\", \"--sf=abc\", \"one\", \"--\", \"two\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tif c.ArgsLenAtDash() != 1 {\n\t\tt.Errorf(\"Expected ArgsLenAtDash: %v but got %v\", 1, c.ArgsLenAtDash())\n\t}\n\tif intFlagValue != 7 {\n\t\tt.Errorf(\"Expected intFlagValue: %v, got %v\", 7, intFlagValue)\n\t}\n\tif stringFlagValue != \"abc\" {\n\t\tt.Errorf(\"Expected stringFlagValue: %q, got %q\", \"abc\", stringFlagValue)\n\t}\n\n\tgot := strings.Join(cArgs, \" \")\n\tif got != onetwo {\n\t\tt.Errorf(\"rootCmdArgs expected: %q, got: %q\", onetwo, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":492,"symbol":"cArgs","kind":"variable","lang":"go","code":"cArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":499,"symbol":"intFlagValue","kind":"variable","lang":"go","code":"intFlagValue int"} | |
| {"repo":"cobra","file":"command_test.go","line":500,"symbol":"stringFlagValue","kind":"variable","lang":"go","code":"stringFlagValue string"} | |
| {"repo":"cobra","file":"command_test.go","line":528,"symbol":"TestFlagShort","kind":"function","lang":"go","code":"func TestFlagShort(t *testing.T) {\n\tvar cArgs []string\n\tc := &Command{\n\t\tUse: \"c\",\n\t\tArgs: ArbitraryArgs,\n\t\tRun: func(_ *Command, args []string) { cArgs = args },\n\t}\n\n\tvar intFlagValue int\n\tvar stringFlagValue string\n\tc.Flags().IntVarP(&intFlagValue, \"intf\", \"i\", -1, \"\")\n\tc.Flags().StringVarP(&stringFlagValue, \"sf\", \"s\", \"\", \"\")\n\n\toutput, err := executeCommand(c, \"-i\", \"7\", \"-sabc\", \"one\", \"two\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tif intFlagValue != 7 {\n\t\tt.Errorf(\"Expected flag value: %v, got %v\", 7, intFlagValue)\n\t}\n\tif stringFlagValue != \"abc\" {\n\t\tt.Errorf(\"Expected stringFlagValue: %q, got %q\", \"abc\", stringFlagValue)\n\t}\n\n\tgot := strings.Join(cArgs, \" \")\n\tif got != onetwo {\n\t\tt.Errorf(\"rootCmdArgs expected: %q, got: %q\", onetwo, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":529,"symbol":"cArgs","kind":"variable","lang":"go","code":"cArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":536,"symbol":"intFlagValue","kind":"variable","lang":"go","code":"intFlagValue int"} | |
| {"repo":"cobra","file":"command_test.go","line":537,"symbol":"stringFlagValue","kind":"variable","lang":"go","code":"stringFlagValue string"} | |
| {"repo":"cobra","file":"command_test.go","line":562,"symbol":"TestChildFlag","kind":"function","lang":"go","code":"func TestChildFlag(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\tchildCmd := &Command{Use: \"child\", Run: emptyRun}\n\trootCmd.AddCommand(childCmd)\n\n\tvar intFlagValue int\n\tchildCmd.Flags().IntVarP(&intFlagValue, \"intf\", \"i\", -1, \"\")\n\n\toutput, err := executeCommand(rootCmd, \"child\", \"-i7\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tif intFlagValue != 7 {\n\t\tt.Errorf(\"Expected flag value: %v, got %v\", 7, intFlagValue)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":567,"symbol":"intFlagValue","kind":"variable","lang":"go","code":"intFlagValue int"} | |
| {"repo":"cobra","file":"command_test.go","line":583,"symbol":"TestChildFlagWithParentLocalFlag","kind":"function","lang":"go","code":"func TestChildFlagWithParentLocalFlag(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\tchildCmd := &Command{Use: \"child\", Run: emptyRun}\n\trootCmd.AddCommand(childCmd)\n\n\tvar intFlagValue int\n\trootCmd.Flags().StringP(\"sf\", \"s\", \"\", \"\")\n\tchildCmd.Flags().IntVarP(&intFlagValue, \"intf\", \"i\", -1, \"\")\n\n\t_, err := executeCommand(rootCmd, \"child\", \"-i7\", \"-sabc\")\n\tif err == nil {\n\t\tt.Errorf(\"Invalid flag should generate error\")\n\t}\n\n\tcheckStringContains(t, err.Error(), \"unknown shorthand\")\n\n\tif intFlagValue != 7 {\n\t\tt.Errorf(\"Expected flag value: %v, got %v\", 7, intFlagValue)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":588,"symbol":"intFlagValue","kind":"variable","lang":"go","code":"intFlagValue int"} | |
| {"repo":"cobra","file":"command_test.go","line":604,"symbol":"TestFlagInvalidInput","kind":"function","lang":"go","code":"func TestFlagInvalidInput(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\trootCmd.Flags().IntP(\"intf\", \"i\", -1, \"\")\n\n\t_, err := executeCommand(rootCmd, \"-iabc\")\n\tif err == nil {\n\t\tt.Errorf(\"Invalid flag value should generate error\")\n\t}\n\n\tcheckStringContains(t, err.Error(), \"invalid syntax\")\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":616,"symbol":"TestFlagBeforeCommand","kind":"function","lang":"go","code":"func TestFlagBeforeCommand(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\tchildCmd := &Command{Use: \"child\", Run: emptyRun}\n\trootCmd.AddCommand(childCmd)\n\n\tvar flagValue int\n\tchildCmd.Flags().IntVarP(&flagValue, \"intf\", \"i\", -1, \"\")\n\n\t// With short flag.\n\t_, err := executeCommand(rootCmd, \"-i7\", \"child\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\tif flagValue != 7 {\n\t\tt.Errorf(\"Expected flag value: %v, got %v\", 7, flagValue)\n\t}\n\n\t// With long flag.\n\t_, err = executeCommand(rootCmd, \"--intf=8\", \"child\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\tif flagValue != 8 {\n\t\tt.Errorf(\"Expected flag value: %v, got %v\", 9, flagValue)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":621,"symbol":"flagValue","kind":"variable","lang":"go","code":"flagValue int"} | |
| {"repo":"cobra","file":"command_test.go","line":643,"symbol":"TestStripFlags","kind":"function","lang":"go","code":"func TestStripFlags(t *testing.T) {\n\ttests := []struct {\n\t\tinput []string\n\t\toutput []string\n\t}{\n\t\t{\n\t\t\t[]string{\"foo\", \"bar\"},\n\t\t\t[]string{\"foo\", \"bar\"},\n\t\t},\n\t\t{\n\t\t\t[]string{\"foo\", \"--str\", \"-s\"},\n\t\t\t[]string{\"foo\"},\n\t\t},\n\t\t{\n\t\t\t[]string{\"-s\", \"foo\", \"--str\", \"bar\"},\n\t\t\t[]string{},\n\t\t},\n\t\t{\n\t\t\t[]string{\"-i10\", \"echo\"},\n\t\t\t[]string{\"echo\"},\n\t\t},\n\t\t{\n\t\t\t[]string{\"-i=10\", \"echo\"},\n\t\t\t[]string{\"echo\"},\n\t\t},\n\t\t{\n\t\t\t[]string{\"--int=100\", \"echo\"},\n\t\t\t[]string{\"echo\"},\n\t\t},\n\t\t{\n\t\t\t[]string{\"-ib\", \"echo\", \"-sfoo\", \"baz\"},\n\t\t\t[]string{\"echo\", \"baz\"},\n\t\t},\n\t\t{\n\t\t\t[]string{\"-i=baz\", \"bar\", \"-i\", \"foo\", \"blah\"},\n\t\t\t[]string{\"bar\", \"blah\"},\n\t\t},\n\t\t{\n\t\t\t[]string{\"--int=baz\", \"-sbar\", \"-i\", \"foo\", \"blah\"},\n\t\t\t[]string{\"blah\"},\n\t\t},\n\t\t{\n\t\t\t[]string{\"--bool\", \"bar\", \"-i\", \"foo\", \"blah\"},\n\t\t\t[]string{\"bar\", \"blah\"},\n\t\t},\n\t\t{\n\t\t\t[]string{\"-b\", \"bar\", \"-i\", \"foo\", \"blah\"},\n\t\t\t[]string{\"bar\", \"blah\"},\n\t\t},\n\t\t{\n\t\t\t[]string{\"--persist\", \"bar\"},\n\t\t\t[]string{\"bar\"},\n\t\t},\n\t\t{\n\t\t\t[]string{\"-p\", \"bar\"},\n\t\t\t[]string{\"bar\"},\n\t\t},\n\t}\n\n\tc := &Command{Use: \"c\", Run: emptyRun}\n\tc.PersistentFlags().BoolP(\"persist\", \"p\", false, \"\")\n\tc.Flags().IntP(\"int\", \"i\", -1, \"\")\n\tc.Flags().StringP(\"str\", \"s\", \"\", \"\")\n\tc.Flags()"} | |
| {"repo":"cobra","file":"command_test.go","line":716,"symbol":"TestDisableFlagParsing","kind":"function","lang":"go","code":"func TestDisableFlagParsing(t *testing.T) {\n\tvar cArgs []string\n\tc := &Command{\n\t\tUse: \"c\",\n\t\tDisableFlagParsing: true,\n\t\tRun: func(_ *Command, args []string) {\n\t\t\tcArgs = args\n\t\t},\n\t}\n\n\targs := []string{\"cmd\", \"-v\", \"-race\", \"-file\", \"foo.go\"}\n\toutput, err := executeCommand(c, args...)\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tif !reflect.DeepEqual(args, cArgs) {\n\t\tt.Errorf(\"Expected: %v, got: %v\", args, cArgs)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":717,"symbol":"cArgs","kind":"variable","lang":"go","code":"cArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":740,"symbol":"TestPersistentFlagsOnSameCommand","kind":"function","lang":"go","code":"func TestPersistentFlagsOnSameCommand(t *testing.T) {\n\tvar rootCmdArgs []string\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tArgs: ArbitraryArgs,\n\t\tRun: func(_ *Command, args []string) { rootCmdArgs = args },\n\t}\n\n\tvar flagValue int\n\trootCmd.PersistentFlags().IntVarP(&flagValue, \"intf\", \"i\", -1, \"\")\n\n\toutput, err := executeCommand(rootCmd, \"-i7\", \"one\", \"two\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tgot := strings.Join(rootCmdArgs, \" \")\n\tif got != onetwo {\n\t\tt.Errorf(\"rootCmdArgs expected: %q, got %q\", onetwo, got)\n\t}\n\tif flagValue != 7 {\n\t\tt.Errorf(\"flagValue expected: %v, got %v\", 7, flagValue)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":741,"symbol":"rootCmdArgs","kind":"variable","lang":"go","code":"rootCmdArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":748,"symbol":"flagValue","kind":"variable","lang":"go","code":"flagValue int"} | |
| {"repo":"cobra","file":"command_test.go","line":770,"symbol":"TestEmptyInputs","kind":"function","lang":"go","doc":"TestEmptyInputs checks, if flags correctly parsed with blank strings in args.","code":"func TestEmptyInputs(t *testing.T) {\n\tc := &Command{Use: \"c\", Run: emptyRun}\n\n\tvar flagValue int\n\tc.Flags().IntVarP(&flagValue, \"intf\", \"i\", -1, \"\")\n\n\toutput, err := executeCommand(c, \"\", \"-i7\", \"\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tif flagValue != 7 {\n\t\tt.Errorf(\"flagValue expected: %v, got %v\", 7, flagValue)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":773,"symbol":"flagValue","kind":"variable","lang":"go","code":"flagValue int"} | |
| {"repo":"cobra","file":"command_test.go","line":789,"symbol":"TestChildFlagShadowsParentPersistentFlag","kind":"function","lang":"go","code":"func TestChildFlagShadowsParentPersistentFlag(t *testing.T) {\n\tparent := &Command{Use: \"parent\", Run: emptyRun}\n\tchild := &Command{Use: \"child\", Run: emptyRun}\n\n\tparent.PersistentFlags().Bool(\"boolf\", false, \"\")\n\tparent.PersistentFlags().Int(\"intf\", -1, \"\")\n\tchild.Flags().String(\"strf\", \"\", \"\")\n\tchild.Flags().Int(\"intf\", -1, \"\")\n\n\tparent.AddCommand(child)\n\n\tchildInherited := child.InheritedFlags()\n\tchildLocal := child.LocalFlags()\n\n\tif childLocal.Lookup(\"strf\") == nil {\n\t\tt.Error(`LocalFlags expected to contain \"strf\", got \"nil\"`)\n\t}\n\tif childInherited.Lookup(\"boolf\") == nil {\n\t\tt.Error(`InheritedFlags expected to contain \"boolf\", got \"nil\"`)\n\t}\n\n\tif childInherited.Lookup(\"intf\") != nil {\n\t\tt.Errorf(`InheritedFlags should not contain shadowed flag \"intf\"`)\n\t}\n\tif childLocal.Lookup(\"intf\") == nil {\n\t\tt.Error(`LocalFlags expected to contain \"intf\", got \"nil\"`)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":818,"symbol":"TestPersistentFlagsOnChild","kind":"function","lang":"go","code":"func TestPersistentFlagsOnChild(t *testing.T) {\n\tvar childCmdArgs []string\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\tchildCmd := &Command{\n\t\tUse: \"child\",\n\t\tArgs: ArbitraryArgs,\n\t\tRun: func(_ *Command, args []string) { childCmdArgs = args },\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\tvar parentFlagValue int\n\tvar childFlagValue int\n\trootCmd.PersistentFlags().IntVarP(&parentFlagValue, \"parentf\", \"p\", -1, \"\")\n\tchildCmd.Flags().IntVarP(&childFlagValue, \"childf\", \"c\", -1, \"\")\n\n\toutput, err := executeCommand(rootCmd, \"child\", \"-c7\", \"-p8\", \"one\", \"two\")\n\tif output != \"\" {\n\t\tt.Errorf(\"Unexpected output: %v\", output)\n\t}\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\tgot := strings.Join(childCmdArgs, \" \")\n\tif got != onetwo {\n\t\tt.Errorf(\"rootCmdArgs expected: %q, got: %q\", onetwo, got)\n\t}\n\tif parentFlagValue != 8 {\n\t\tt.Errorf(\"parentFlagValue expected: %v, got %v\", 8, parentFlagValue)\n\t}\n\tif childFlagValue != 7 {\n\t\tt.Errorf(\"childFlagValue expected: %v, got %v\", 7, childFlagValue)\n\t}\n}"} | |
| {"repo":"cobra","file":"command_test.go","line":819,"symbol":"childCmdArgs","kind":"variable","lang":"go","code":"childCmdArgs []string"} | |
| {"repo":"cobra","file":"command_test.go","line":828,"symbol":"parentFlagValue","kind":"variable","lang":"go","code":"parentFlagValue int"} | |
| {"repo":"cobra","file":"command_test.go","line":829,"symbol":"childFlagValue","kind":"variable","lang":"go","code":"childFlagValue int"} | |
| {"repo":"cobra","file":"command_win.go","line":28,"symbol":"preExecHookFn","kind":"variable","lang":"go","code":"preExecHookFn = preExecHook"} | |
| {"repo":"cobra","file":"command_win.go","line":30,"symbol":"preExecHook","kind":"function","lang":"go","code":"func preExecHook(c *Command) {\n\tif MousetrapHelpText != \"\" && mousetrap.StartedByExplorer() {\n\t\tc.Print(MousetrapHelpText)\n\t\tif MousetrapDisplayDuration > 0 {\n\t\t\ttime.Sleep(MousetrapDisplayDuration)\n\t\t} else {\n\t\t\tc.Println(\"Press return to continue...\")\n\t\t\tfmt.Scanln()\n\t\t}\n\t\tos.Exit(1)\n\t}\n}"} | |
| {"repo":"cobra","file":"completions.go","line":31,"symbol":"ShellCompRequestCmd","kind":"constant","lang":"go","doc":"ShellCompRequestCmd is the name of the hidden command that is used to request completion results from the program. It is used by the shell completion scripts.","code":"ShellCompRequestCmd = \"__complete\""} | |
| {"repo":"cobra","file":"completions.go","line":34,"symbol":"ShellCompNoDescRequestCmd","kind":"constant","lang":"go","doc":"ShellCompNoDescRequestCmd is the name of the hidden command that is used to request completion results without their description. It is used by the shell completion scripts.","code":"ShellCompNoDescRequestCmd = \"__completeNoDesc\""} | |
| {"repo":"cobra","file":"completions.go","line":38,"symbol":"flagCompletionFunctions","kind":"variable","lang":"go","doc":"Global map of flag completion functions. Make sure to use flagCompletionMutex before you try to read and write from it.","code":"flagCompletionFunctions = map[*pflag.Flag]CompletionFunc{}"} | |
| {"repo":"cobra","file":"completions.go","line":41,"symbol":"flagCompletionMutex","kind":"variable","lang":"go","doc":"lock for reading and writing from flagCompletionFunctions","code":"flagCompletionMutex = &sync.RWMutex{}"} | |
| {"repo":"cobra","file":"completions.go","line":45,"symbol":"ShellCompDirective","kind":"type","lang":"go","doc":"ShellCompDirective is a bit map representing the different behaviors the shell can be instructed to have once completions have been provided.","code":"type ShellCompDirective int"} | |
| {"repo":"cobra","file":"completions.go","line":47,"symbol":"flagCompError","kind":"type","lang":"go","code":"type flagCompError struct {\n\tsubCommand string\n\tflagName string\n}"} | |
| {"repo":"cobra","file":"completions.go","line":52,"symbol":"Error","kind":"method","lang":"go","code":"func (e *flagCompError) Error() string {\n\treturn \"Subcommand '\" + e.subCommand + \"' does not support flag '\" + e.flagName + \"'\"\n}"} | |
| {"repo":"cobra","file":"completions.go","line":58,"symbol":"ShellCompDirectiveError","kind":"constant","lang":"go","doc":"ShellCompDirectiveError indicates an error occurred and completions should be ignored.","code":"ShellCompDirectiveError ShellCompDirective = 1 << iota"} | |
| {"repo":"cobra","file":"completions.go","line":62,"symbol":"ShellCompDirectiveNoSpace","kind":"constant","lang":"go","doc":"ShellCompDirectiveNoSpace indicates that the shell should not add a space after the completion even if there is a single completion provided.","code":"ShellCompDirectiveNoSpace"} | |
| {"repo":"cobra","file":"completions.go","line":66,"symbol":"ShellCompDirectiveNoFileComp","kind":"constant","lang":"go","doc":"ShellCompDirectiveNoFileComp indicates that the shell should not provide file completion even when no completion is provided.","code":"ShellCompDirectiveNoFileComp"} | |
| {"repo":"cobra","file":"completions.go","line":73,"symbol":"ShellCompDirectiveFilterFileExt","kind":"constant","lang":"go","doc":"ShellCompDirectiveFilterFileExt indicates that the provided completions should be used as file extension filters. For flags, using Command.MarkFlagFilename() and Command.MarkPersistentFlagFilename() is a shortcut to using this directive explicitly. The BashCompFilenameExt annotation can also be used to obtain the same behavior for flags.","code":"ShellCompDirectiveFilterFileExt"} | |
| {"repo":"cobra","file":"completions.go","line":80,"symbol":"ShellCompDirectiveFilterDirs","kind":"constant","lang":"go","doc":"ShellCompDirectiveFilterDirs indicates that only directory names should be provided in file completion. To request directory names within another directory, the returned completions should specify the directory within which to search. The BashCompSubdirsInDir annotation can be used to obtain the same behavior but only for flags.","code":"ShellCompDirectiveFilterDirs"} | |
| {"repo":"cobra","file":"completions.go","line":84,"symbol":"ShellCompDirectiveKeepOrder","kind":"constant","lang":"go","doc":"ShellCompDirectiveKeepOrder indicates that the shell should preserve the order in which the completions are provided","code":"ShellCompDirectiveKeepOrder"} | |
| {"repo":"cobra","file":"completions.go","line":90,"symbol":"shellCompDirectiveMaxValue","kind":"constant","lang":"go","doc":"All directives using iota should be above this one. For internal use.","code":"shellCompDirectiveMaxValue"} | |
| {"repo":"cobra","file":"completions.go","line":95,"symbol":"ShellCompDirectiveDefault","kind":"constant","lang":"go","doc":"ShellCompDirectiveDefault indicates to let the shell perform its default behavior after completions have been provided. This one must be last to avoid messing up the iota count.","code":"ShellCompDirectiveDefault ShellCompDirective = 0"} | |
| {"repo":"cobra","file":"completions.go","line":100,"symbol":"compCmdName","kind":"constant","lang":"go","doc":"Constants for the completion command","code":"compCmdName = \"completion\""} | |
| {"repo":"cobra","file":"completions.go","line":101,"symbol":"compCmdNoDescFlagName","kind":"constant","lang":"go","code":"compCmdNoDescFlagName = \"no-descriptions\""} | |
| {"repo":"cobra","file":"completions.go","line":102,"symbol":"compCmdNoDescFlagDesc","kind":"constant","lang":"go","code":"compCmdNoDescFlagDesc = \"disable completion descriptions\""} | |
| {"repo":"cobra","file":"completions.go","line":103,"symbol":"compCmdNoDescFlagDefault","kind":"constant","lang":"go","code":"compCmdNoDescFlagDefault = false"} | |
| {"repo":"cobra","file":"completions.go","line":107,"symbol":"CompletionOptions","kind":"type","lang":"go","doc":"CompletionOptions are the options to control shell completion","code":"type CompletionOptions struct {\n\t// DisableDefaultCmd prevents Cobra from creating a default 'completion' command\n\tDisableDefaultCmd bool\n\t// DisableNoDescFlag prevents Cobra from creating the '--no-descriptions' flag\n\t// for shells that support completion descriptions\n\tDisableNoDescFlag bool\n\t// DisableDescriptions turns off all completion descriptions for shells\n\t// that support them\n\tDisableDescriptions bool\n\t// HiddenDefaultCmd makes the default 'completion' command hidden\n\tHiddenDefaultCmd bool\n\t// DefaultShellCompDirective sets the ShellCompDirective that is returned\n\t// if no special directive can be determined\n\tDefaultShellCompDirective *ShellCompDirective\n}"} | |
| {"repo":"cobra","file":"completions.go","line":123,"symbol":"SetDefaultShellCompDirective","kind":"method","lang":"go","code":"func (receiver *CompletionOptions) SetDefaultShellCompDirective(directive ShellCompDirective) {\n\treceiver.DefaultShellCompDirective = &directive\n}"} | |
| {"repo":"cobra","file":"completions.go","line":142,"symbol":"CompletionWithDesc","kind":"function","lang":"go","doc":"CompletionWithDesc returns a [Completion] with a description by using the TAB delimited format.","code":"func CompletionWithDesc(choice string, description string) Completion {\n\treturn choice + \"\\t\" + description\n}"} | |
| {"repo":"cobra","file":"completions.go","line":151,"symbol":"NoFileCompletions","kind":"function","lang":"go","doc":"NoFileCompletions can be used to disable file completion for commands that should not trigger file completions. This method satisfies [CompletionFunc]. It can be used with [Command.RegisterFlagCompletionFunc] and for [Command.ValidArgsFunction].","code":"func NoFileCompletions(cmd *Command, args []string, toComplete string) ([]Completion, ShellCompDirective) {\n\treturn nil, ShellCompDirectiveNoFileComp\n}"} | |
| {"repo":"cobra","file":"completions.go","line":160,"symbol":"FixedCompletions","kind":"function","lang":"go","doc":"FixedCompletions can be used to create a completion function which always returns the same results. This method returns a function that satisfies [CompletionFunc] It can be used with [Command.RegisterFlagCompletionFunc] and for [Command.ValidArgsFunction].","code":"func FixedCompletions(choices []Completion, directive ShellCompDirective) CompletionFunc {\n\treturn func(cmd *Command, args []string, toComplete string) ([]Completion, ShellCompDirective) {\n\t\treturn choices, directive\n\t}\n}"} | |
| {"repo":"cobra","file":"completions.go","line":170,"symbol":"RegisterFlagCompletionFunc","kind":"method","lang":"go","doc":"RegisterFlagCompletionFunc should be called to register a function to provide completion for a flag. You can use pre-defined completion functions such as [FixedCompletions] or [NoFileCompletions], or you can define your own.","code":"func (c *Command) RegisterFlagCompletionFunc(flagName string, f CompletionFunc) error {\n\tflag := c.Flag(flagName)\n\tif flag == nil {\n\t\treturn fmt.Errorf(\"RegisterFlagCompletionFunc: flag '%s' does not exist\", flagName)\n\t}\n\tflagCompletionMutex.Lock()\n\tdefer flagCompletionMutex.Unlock()\n\n\tif _, exists := flagCompletionFunctions[flag]; exists {\n\t\treturn fmt.Errorf(\"RegisterFlagCompletionFunc: flag '%s' already registered\", flagName)\n\t}\n\tflagCompletionFunctions[flag] = f\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"completions.go","line":186,"symbol":"GetFlagCompletionFunc","kind":"method","lang":"go","doc":"GetFlagCompletionFunc returns the completion function for the given flag of the command, if available.","code":"func (c *Command) GetFlagCompletionFunc(flagName string) (CompletionFunc, bool) {\n\tflag := c.Flag(flagName)\n\tif flag == nil {\n\t\treturn nil, false\n\t}\n\n\tflagCompletionMutex.RLock()\n\tdefer flagCompletionMutex.RUnlock()\n\n\tcompletionFunc, exists := flagCompletionFunctions[flag]\n\treturn completionFunc, exists\n}"} | |
| {"repo":"cobra","file":"completions.go","line":200,"symbol":"string","kind":"method","lang":"go","doc":"Returns a string listing the different directive enabled in the specified parameter","code":"func (d ShellCompDirective) string() string {\n\tvar directives []string\n\tif d&ShellCompDirectiveError != 0 {\n\t\tdirectives = append(directives, \"ShellCompDirectiveError\")\n\t}\n\tif d&ShellCompDirectiveNoSpace != 0 {\n\t\tdirectives = append(directives, \"ShellCompDirectiveNoSpace\")\n\t}\n\tif d&ShellCompDirectiveNoFileComp != 0 {\n\t\tdirectives = append(directives, \"ShellCompDirectiveNoFileComp\")\n\t}\n\tif d&ShellCompDirectiveFilterFileExt != 0 {\n\t\tdirectives = append(directives, \"ShellCompDirectiveFilterFileExt\")\n\t}\n\tif d&ShellCompDirectiveFilterDirs != 0 {\n\t\tdirectives = append(directives, \"ShellCompDirectiveFilterDirs\")\n\t}\n\tif d&ShellCompDirectiveKeepOrder != 0 {\n\t\tdirectives = append(directives, \"ShellCompDirectiveKeepOrder\")\n\t}\n\tif len(directives) == 0 {\n\t\tdirectives = append(directives, \"ShellCompDirectiveDefault\")\n\t}\n\n\tif d >= shellCompDirectiveMaxValue {\n\t\treturn fmt.Sprintf(\"ERROR: unexpected ShellCompDirective value: %d\", d)\n\t}\n\treturn strings.Join(directives, \", \")\n}"} | |
| {"repo":"cobra","file":"completions.go","line":201,"symbol":"directives","kind":"variable","lang":"go","code":"directives []string"} | |
| {"repo":"cobra","file":"completions.go","line":231,"symbol":"initCompleteCmd","kind":"method","lang":"go","doc":"initCompleteCmd adds a special hidden command that can be used to request custom completions.","code":"func (c *Command) initCompleteCmd(args []string) {\n\tcompleteCmd := &Command{\n\t\tUse: fmt.Sprintf(\"%s [command-line]\", ShellCompRequestCmd),\n\t\tAliases: []string{ShellCompNoDescRequestCmd},\n\t\tDisableFlagsInUseLine: true,\n\t\tHidden: true,\n\t\tDisableFlagParsing: true,\n\t\tArgs: MinimumNArgs(1),\n\t\tShort: \"Request shell completion choices for the specified command-line\",\n\t\tLong: fmt.Sprintf(\"%[2]s is a special command that is used by the shell completion logic\\n%[1]s\",\n\t\t\t\"to request completion choices for the specified command-line.\", ShellCompRequestCmd),\n\t\tRun: func(cmd *Command, args []string) {\n\t\t\tfinalCmd, completions, directive, err := cmd.getCompletions(args)\n\t\t\tif err != nil {\n\t\t\t\tCompErrorln(err.Error())\n\t\t\t\t// Keep going for multiple reasons:\n\t\t\t\t// 1- There could be some valid completions even though there was an error\n\t\t\t\t// 2- Even without completions, we need to print the directive\n\t\t\t}\n\n\t\t\tnoDescriptions := cmd.CalledAs() == ShellCompNoDescRequestCmd\n\t\t\tif !noDescriptions {\n\t\t\t\tif doDescriptions, err := strconv.ParseBool(getEnvConfig(cmd, configEnvVarSuffixDescriptions)); err == nil {\n\t\t\t\t\tnoDes"} | |
| {"repo":"cobra","file":"completions.go","line":311,"symbol":"SliceValue","kind":"type","lang":"go","doc":"SliceValue is a reduced version of [pflag.SliceValue]. It is used to detect flags that accept multiple values and therefore can provide completion multiple times.","code":"type SliceValue interface {\n\t// GetSlice returns the flag value list as an array of strings.\n\tGetSlice() []string\n}"} | |
| {"repo":"cobra","file":"completions.go","line":316,"symbol":"getCompletions","kind":"method","lang":"go","code":"func (c *Command) getCompletions(args []string) (*Command, []Completion, ShellCompDirective, error) {\n\t// The last argument, which is not completely typed by the user,\n\t// should not be part of the list of arguments\n\ttoComplete := args[len(args)-1]\n\t// Copy trimmedArgs to a new slice to avoid mutating the caller's\n\t// backing array (which may be os.Args) when later appending \"--\".\n\ttrimmedArgs := make([]string, len(args)-1)\n\tcopy(trimmedArgs, args[:len(args)-1])\n\n\tvar finalCmd *Command\n\tvar finalArgs []string\n\tvar err error\n\t// Find the real command for which completion must be performed\n\t// check if we need to traverse here to parse local flags on parent commands\n\tif c.Root().TraverseChildren {\n\t\tfinalCmd, finalArgs, err = c.Root().Traverse(trimmedArgs)\n\t} else {\n\t\t// For Root commands that don't specify any value for their Args fields, when we call\n\t\t// Find(), if those Root commands don't have any sub-commands, they will accept arguments.\n\t\t// However, because we have added the __complete sub-command in the current code path, the\n\t\t// call to Find() -> legacyArgs() will return an error if there are any arguments.\n\t\t// To avoid this, we first remove the __complete command to get "} | |
| {"repo":"cobra","file":"completions.go","line":325,"symbol":"finalCmd","kind":"variable","lang":"go","code":"finalCmd *Command"} | |
| {"repo":"cobra","file":"completions.go","line":326,"symbol":"finalArgs","kind":"variable","lang":"go","code":"finalArgs []string"} | |
| {"repo":"cobra","file":"completions.go","line":327,"symbol":"err","kind":"variable","lang":"go","code":"err error"} | |
| {"repo":"cobra","file":"completions.go","line":429,"symbol":"completions","kind":"variable","lang":"go","code":"completions []Completion"} | |
| {"repo":"cobra","file":"completions.go","line":430,"symbol":"directive","kind":"variable","lang":"go","code":"directive ShellCompDirective"} | |
| {"repo":"cobra","file":"completions.go","line":568,"symbol":"completionFn","kind":"variable","lang":"go","doc":"Find the completion function for the flag or command","code":"completionFn CompletionFunc"} | |
| {"repo":"cobra","file":"completions.go","line":579,"symbol":"comps","kind":"variable","lang":"go","doc":"Go custom completion defined for this flag or command. Call the registered completion function to get the completions.","code":"comps []Completion"} | |
| {"repo":"cobra","file":"completions.go","line":587,"symbol":"helpOrVersionFlagPresent","kind":"function","lang":"go","code":"func helpOrVersionFlagPresent(cmd *Command) bool {\n\tif versionFlag := cmd.Flags().Lookup(\"version\"); versionFlag != nil &&\n\t\tlen(versionFlag.Annotations[FlagSetByCobraAnnotation]) > 0 && versionFlag.Changed {\n\t\treturn true\n\t}\n\tif helpFlag := cmd.Flags().Lookup(helpFlagName); helpFlag != nil &&\n\t\tlen(helpFlag.Annotations[FlagSetByCobraAnnotation]) > 0 && helpFlag.Changed {\n\t\treturn true\n\t}\n\treturn false\n}"} | |
| {"repo":"cobra","file":"completions.go","line":599,"symbol":"getFlagNameCompletions","kind":"function","lang":"go","code":"func getFlagNameCompletions(flag *pflag.Flag, toComplete string) []Completion {\n\tif nonCompletableFlag(flag) {\n\t\treturn []Completion{}\n\t}\n\n\tvar completions []Completion\n\tflagName := \"--\" + flag.Name\n\tif strings.HasPrefix(flagName, toComplete) {\n\t\t// Flag without the =\n\t\tcompletions = append(completions, CompletionWithDesc(flagName, flag.Usage))\n\n\t\t// Why suggest both long forms: --flag and --flag= ?\n\t\t// This forces the user to *always* have to type either an = or a space after the flag name.\n\t\t// Let's be nice and avoid making users have to do that.\n\t\t// Since boolean flags and shortname flags don't show the = form, let's go that route and never show it.\n\t\t// The = form will still work, we just won't suggest it.\n\t\t// This also makes the list of suggested flags shorter as we avoid all the = forms.\n\t\t//\n\t\t// if len(flag.NoOptDefVal) == 0 {\n\t\t// \t// Flag requires a value, so it can be suffixed with =\n\t\t// \tflagName += \"=\"\n\t\t// \tcompletions = append(completions, CompletionWithDesc(flagName, flag.Usage))\n\t\t// }\n\t}\n\n\tflagName = \"-\" + flag.Shorthand\n\tif len(flag.Shorthand) > 0 && strings.HasPrefix(flagName, toComplete) {\n\t\tcompletions = append(completions, CompletionWithDesc(flagName, fl"} | |
| {"repo":"cobra","file":"completions.go","line":604,"symbol":"completions","kind":"variable","lang":"go","code":"completions []Completion"} | |
| {"repo":"cobra","file":"completions.go","line":632,"symbol":"completeRequireFlags","kind":"function","lang":"go","code":"func completeRequireFlags(finalCmd *Command, toComplete string) []Completion {\n\tvar completions []Completion\n\n\tdoCompleteRequiredFlags := func(flag *pflag.Flag) {\n\t\tif _, present := flag.Annotations[BashCompOneRequiredFlag]; present {\n\t\t\tif !flag.Changed {\n\t\t\t\t// If the flag is not already present, we suggest it as a completion\n\t\t\t\tcompletions = append(completions, getFlagNameCompletions(flag, toComplete)...)\n\t\t\t}\n\t\t}\n\t}\n\n\t// We cannot use finalCmd.Flags() because we may not have called ParsedFlags() for commands\n\t// that have set DisableFlagParsing; it is ParseFlags() that merges the inherited and\n\t// non-inherited flags.\n\tfinalCmd.InheritedFlags().VisitAll(func(flag *pflag.Flag) {\n\t\tdoCompleteRequiredFlags(flag)\n\t})\n\tfinalCmd.NonInheritedFlags().VisitAll(func(flag *pflag.Flag) {\n\t\tdoCompleteRequiredFlags(flag)\n\t})\n\n\treturn completions\n}"} | |
| {"repo":"cobra","file":"completions.go","line":633,"symbol":"completions","kind":"variable","lang":"go","code":"completions []Completion"} | |
| {"repo":"cobra","file":"completions.go","line":657,"symbol":"checkIfFlagCompletion","kind":"function","lang":"go","code":"func checkIfFlagCompletion(finalCmd *Command, args []string, lastArg string) (*pflag.Flag, []string, string, error) {\n\tif finalCmd.DisableFlagParsing {\n\t\t// We only do flag completion if we are allowed to parse flags\n\t\t// This is important for commands which have requested to do their own flag completion.\n\t\treturn nil, args, lastArg, nil\n\t}\n\n\tvar flagName string\n\ttrimmedArgs := args\n\tflagWithEqual := false\n\torgLastArg := lastArg\n\n\t// When doing completion of a flag name, as soon as an argument starts with\n\t// a '-' we know it is a flag. We cannot use isFlagArg() here as that function\n\t// requires the flag name to be complete\n\tif len(lastArg) > 0 && lastArg[0] == '-' {\n\t\tif index := strings.Index(lastArg, \"=\"); index >= 0 {\n\t\t\t// Flag with an =\n\t\t\tif strings.HasPrefix(lastArg[:index], \"--\") {\n\t\t\t\t// Flag has full name\n\t\t\t\tflagName = lastArg[2:index]\n\t\t\t} else {\n\t\t\t\t// Flag is shorthand\n\t\t\t\t// We have to get the last shorthand flag name\n\t\t\t\t// e.g. `-asd` => d to provide the correct completion\n\t\t\t\t// https://github.com/spf13/cobra/issues/1257\n\t\t\t\tflagName = lastArg[index-1 : index]\n\t\t\t}\n\t\t\tlastArg = lastArg[index+1:]\n\t\t\tflagWithEqual = true\n\t\t} else {\n\t\t\t// Normal flag completion\n\t\t"} | |
| {"repo":"cobra","file":"completions.go","line":664,"symbol":"flagName","kind":"variable","lang":"go","code":"flagName string"} | |
| {"repo":"cobra","file":"completions.go","line":748,"symbol":"InitDefaultCompletionCmd","kind":"method","lang":"go","doc":"InitDefaultCompletionCmd adds a default 'completion' command to c. This function will do nothing if any of the following is true: 1- the feature has been explicitly disabled by the program, 2- c has no subcommands (to avoid creating one), 3- c already has a 'completion' command provided by the program.","code":"func (c *Command) InitDefaultCompletionCmd(args ...string) {\n\tif c.CompletionOptions.DisableDefaultCmd {\n\t\treturn\n\t}\n\n\tfor _, cmd := range c.commands {\n\t\tif cmd.Name() == compCmdName || cmd.HasAlias(compCmdName) {\n\t\t\t// A completion command is already available\n\t\t\treturn\n\t\t}\n\t}\n\n\thaveNoDescFlag := !c.CompletionOptions.DisableNoDescFlag && !c.CompletionOptions.DisableDescriptions\n\n\t// Special case to know if there are sub-commands or not.\n\thasSubCommands := false\n\tfor _, cmd := range c.commands {\n\t\tif cmd.Name() != ShellCompRequestCmd && cmd.Name() != helpCommandName {\n\t\t\t// We found a real sub-command (not 'help' or '__complete')\n\t\t\thasSubCommands = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tcompletionCmd := &Command{\n\t\tUse: compCmdName,\n\t\tShort: \"Generate the autocompletion script for the specified shell\",\n\t\tLong: fmt.Sprintf(`Generate the autocompletion script for %[1]s for the specified shell.\nSee each sub-command's help for details on how to use the generated script.\n`, c.Root().Name()),\n\t\tArgs: NoArgs,\n\t\tValidArgsFunction: NoFileCompletions,\n\t\tHidden: c.CompletionOptions.HiddenDefaultCmd,\n\t\tGroupID: c.completionCommandGroupID,\n\t}\n\tc.AddCommand(completionCmd)\n\n\t"} | |
| {"repo":"cobra","file":"completions.go","line":932,"symbol":"findFlag","kind":"function","lang":"go","code":"func findFlag(cmd *Command, name string) *pflag.Flag {\n\tflagSet := cmd.Flags()\n\tif len(name) == 1 {\n\t\t// First convert the short flag into a long flag\n\t\t// as the cmd.Flag() search only accepts long flags\n\t\tif short := flagSet.ShorthandLookup(name); short != nil {\n\t\t\tname = short.Name\n\t\t} else {\n\t\t\tset := cmd.InheritedFlags()\n\t\t\tif short = set.ShorthandLookup(name); short != nil {\n\t\t\t\tname = short.Name\n\t\t\t} else {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\t}\n\treturn cmd.Flag(name)\n}"} | |
| {"repo":"cobra","file":"completions.go","line":955,"symbol":"CompDebug","kind":"function","lang":"go","doc":"CompDebug prints the specified string to the same file as where the completion script prints its logs. Note that completion printouts should never be on stdout as they would be wrongly interpreted as actual completion choices by the completion script.","code":"func CompDebug(msg string, printToStdErr bool) {\n\tmsg = fmt.Sprintf(\"[Debug] %s\", msg)\n\n\t// Such logs are only printed when the user has set the environment\n\t// variable BASH_COMP_DEBUG_FILE to the path of some file to be used.\n\tif path := os.Getenv(\"BASH_COMP_DEBUG_FILE\"); path != \"\" {\n\t\t//nolint:gosec // G703:BASH_COMP_DEBUG_FILE intentionally user-controlled for completion debug logging.\n\t\tf, err := os.OpenFile(path,\n\t\t\tos.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)\n\t\tif err == nil {\n\t\t\tdefer f.Close()\n\t\t\tWriteStringAndCheck(f, msg)\n\t\t}\n\t}\n\n\tif printToStdErr {\n\t\t// Must print to stderr for this not to be read by the completion script.\n\t\tfmt.Fprint(os.Stderr, msg)\n\t}\n}"} | |
| {"repo":"cobra","file":"completions.go","line":980,"symbol":"CompDebugln","kind":"function","lang":"go","doc":"CompDebugln prints the specified string with a newline at the end to the same file as where the completion script prints its logs. Such logs are only printed when the user has set the environment variable BASH_COMP_DEBUG_FILE to the path of some file to be used.","code":"func CompDebugln(msg string, printToStdErr bool) {\n\tCompDebug(fmt.Sprintf(\"%s\\n\", msg), printToStdErr)\n}"} | |
| {"repo":"cobra","file":"completions.go","line":985,"symbol":"CompError","kind":"function","lang":"go","doc":"CompError prints the specified completion message to stderr.","code":"func CompError(msg string) {\n\tmsg = fmt.Sprintf(\"[Error] %s\", msg)\n\tCompDebug(msg, true)\n}"} | |
| {"repo":"cobra","file":"completions.go","line":991,"symbol":"CompErrorln","kind":"function","lang":"go","doc":"CompErrorln prints the specified completion message to stderr with a newline at the end.","code":"func CompErrorln(msg string) {\n\tCompError(fmt.Sprintf(\"%s\\n\", msg))\n}"} | |
| {"repo":"cobra","file":"completions.go","line":997,"symbol":"configEnvVarGlobalPrefix","kind":"constant","lang":"go","code":"configEnvVarGlobalPrefix = \"COBRA\""} | |
| {"repo":"cobra","file":"completions.go","line":998,"symbol":"configEnvVarSuffixDescriptions","kind":"constant","lang":"go","code":"configEnvVarSuffixDescriptions = \"COMPLETION_DESCRIPTIONS\""} | |
| {"repo":"cobra","file":"completions.go","line":1001,"symbol":"configEnvVarPrefixSubstRegexp","kind":"variable","lang":"go","code":"configEnvVarPrefixSubstRegexp = regexp.MustCompile(`[^A-Z0-9_]`)"} | |
| {"repo":"cobra","file":"completions.go","line":1006,"symbol":"configEnvVar","kind":"function","lang":"go","doc":"configEnvVar returns the name of the program-specific configuration environment variable. It has the format <PROGRAM>_<SUFFIX> where <PROGRAM> is the name of the root command in upper case, with all non-ASCII-alphanumeric characters replaced by `_`.","code":"func configEnvVar(name, suffix string) string {\n\t// This format should not be changed: users will be using it explicitly.\n\tv := strings.ToUpper(fmt.Sprintf(\"%s_%s\", name, suffix))\n\tv = configEnvVarPrefixSubstRegexp.ReplaceAllString(v, \"_\")\n\treturn v\n}"} | |
| {"repo":"cobra","file":"completions.go","line":1018,"symbol":"getEnvConfig","kind":"function","lang":"go","doc":"getEnvConfig returns the value of the configuration environment variable <PROGRAM>_<SUFFIX> where <PROGRAM> is the name of the root command in upper case, with all non-ASCII-alphanumeric characters replaced by `_`. If the value is empty or not set, the value of the environment variable COBRA_<SUFFIX> is returned instead.","code":"func getEnvConfig(cmd *Command, suffix string) string {\n\tv := os.Getenv(configEnvVar(cmd.Root().Name(), suffix))\n\tif v == \"\" {\n\t\tv = os.Getenv(configEnvVar(configEnvVarGlobalPrefix, suffix))\n\t}\n\treturn v\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":27,"symbol":"validArgsFunc","kind":"function","lang":"go","code":"func validArgsFunc(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\tif len(args) != 0 {\n\t\treturn nil, ShellCompDirectiveNoFileComp\n\t}\n\n\tvar completions []string\n\tfor _, comp := range []string{\"one\\tThe first\", \"two\\tThe second\"} {\n\t\tif strings.HasPrefix(comp, toComplete) {\n\t\t\tcompletions = append(completions, comp)\n\t\t}\n\t}\n\treturn completions, ShellCompDirectiveDefault\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":32,"symbol":"completions","kind":"variable","lang":"go","code":"completions []string"} | |
| {"repo":"cobra","file":"completions_test.go","line":41,"symbol":"validArgsFunc2","kind":"function","lang":"go","code":"func validArgsFunc2(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\tif len(args) != 0 {\n\t\treturn nil, ShellCompDirectiveNoFileComp\n\t}\n\n\tvar completions []string\n\tfor _, comp := range []string{\"three\\tThe third\", \"four\\tThe fourth\"} {\n\t\tif strings.HasPrefix(comp, toComplete) {\n\t\t\tcompletions = append(completions, comp)\n\t\t}\n\t}\n\treturn completions, ShellCompDirectiveDefault\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":46,"symbol":"completions","kind":"variable","lang":"go","code":"completions []string"} | |
| {"repo":"cobra","file":"completions_test.go","line":55,"symbol":"TestCmdNameCompletionInGo","kind":"function","lang":"go","code":"func TestCmdNameCompletionInGo(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\tchildCmd1 := &Command{\n\t\tUse: \"firstChild\",\n\t\tShort: \"First command\",\n\t\tRun: emptyRun,\n\t}\n\tchildCmd2 := &Command{\n\t\tUse: \"secondChild\",\n\t\tRun: emptyRun,\n\t}\n\thiddenCmd := &Command{\n\t\tUse: \"testHidden\",\n\t\tHidden: true, // Not completed\n\t\tRun: emptyRun,\n\t}\n\tdeprecatedCmd := &Command{\n\t\tUse: \"testDeprecated\",\n\t\tDeprecated: \"deprecated\", // Not completed\n\t\tRun: emptyRun,\n\t}\n\taliasedCmd := &Command{\n\t\tUse: \"aliased\",\n\t\tShort: \"A command with aliases\",\n\t\tAliases: []string{\"testAlias\", \"testSynonym\"}, // Not completed\n\t\tRun: emptyRun,\n\t}\n\n\trootCmd.AddCommand(childCmd1, childCmd2, hiddenCmd, deprecatedCmd, aliasedCmd)\n\n\t// Test that sub-command names are completed\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"aliased\",\n\t\t\"completion\",\n\t\t\"firstChild\",\n\t\t\"help\",\n\t\t\"secondChild\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected,"} | |
| {"repo":"cobra","file":"completions_test.go","line":157,"symbol":"TestNoCmdNameCompletionInGo","kind":"function","lang":"go","code":"func TestNoCmdNameCompletionInGo(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.Flags().String(\"localroot\", \"\", \"local root flag\")\n\n\tchildCmd1 := &Command{\n\t\tUse: \"childCmd1\",\n\t\tShort: \"First command\",\n\t\tArgs: MinimumNArgs(0),\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(childCmd1)\n\tchildCmd1.PersistentFlags().StringP(\"persistent\", \"p\", \"\", \"persistent flag\")\n\tpersistentFlag := childCmd1.PersistentFlags().Lookup(\"persistent\")\n\tchildCmd1.Flags().StringP(\"nonPersistent\", \"n\", \"\", \"non-persistent flag\")\n\tnonPersistentFlag := childCmd1.Flags().Lookup(\"nonPersistent\")\n\n\tchildCmd2 := &Command{\n\t\tUse: \"childCmd2\",\n\t\tRun: emptyRun,\n\t}\n\tchildCmd1.AddCommand(childCmd2)\n\n\t// Test that sub-command names are not completed if there is an argument already\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"childCmd1\", \"arg1\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that sub-command names are not completed if a loc"} | |
| {"repo":"cobra","file":"completions_test.go","line":322,"symbol":"TestValidArgsCompletionInGo","kind":"function","lang":"go","code":"func TestValidArgsCompletionInGo(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tValidArgs: []string{\"one\", \"two\", \"three\"},\n\t\tArgs: MinimumNArgs(1),\n\t}\n\n\t// Test that validArgs are completed\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"one\",\n\t\t\"two\",\n\t\t\"three\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that validArgs are completed with prefix\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"o\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"one\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that validArgs don't repeat\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"one\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\":0\",\n\t\t\"Comple"} | |
| {"repo":"cobra","file":"completions_test.go","line":376,"symbol":"TestValidArgsAndCmdCompletionInGo","kind":"function","lang":"go","code":"func TestValidArgsAndCmdCompletionInGo(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tValidArgs: []string{\"one\", \"two\"},\n\t\tRun: emptyRun,\n\t}\n\n\tchildCmd := &Command{\n\t\tUse: \"thechild\",\n\t\tRun: emptyRun,\n\t}\n\n\trootCmd.AddCommand(childCmd)\n\n\t// Test that both sub-commands and validArgs are completed\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"completion\",\n\t\t\"help\",\n\t\t\"thechild\",\n\t\t\"one\",\n\t\t\"two\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that both sub-commands and validArgs are completed with prefix\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"t\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"thechild\",\n\t\t\"two\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":426,"symbol":"TestValidArgsFuncAndCmdCompletionInGo","kind":"function","lang":"go","code":"func TestValidArgsFuncAndCmdCompletionInGo(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\n\tchildCmd := &Command{\n\t\tUse: \"thechild\",\n\t\tShort: \"The child command\",\n\t\tRun: emptyRun,\n\t}\n\n\trootCmd.AddCommand(childCmd)\n\n\t// Test that both sub-commands and validArgsFunction are completed\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"completion\",\n\t\t\"help\",\n\t\t\"thechild\",\n\t\t\"one\",\n\t\t\"two\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that both sub-commands and validArgs are completed with prefix\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"t\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"thechild\",\n\t\t\"two\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t"} | |
| {"repo":"cobra","file":"completions_test.go","line":493,"symbol":"TestFlagNameCompletionInGo","kind":"function","lang":"go","code":"func TestFlagNameCompletionInGo(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\tchildCmd := &Command{\n\t\tUse: \"childCmd\",\n\t\tVersion: \"1.2.3\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\trootCmd.Flags().IntP(\"first\", \"f\", -1, \"first flag\")\n\trootCmd.PersistentFlags().BoolP(\"second\", \"s\", false, \"second flag\")\n\tchildCmd.Flags().String(\"subFlag\", \"\", \"sub flag\")\n\n\t// Test that flag names are not shown if the user has not given the '-' prefix\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"childCmd\",\n\t\t\"completion\",\n\t\t\"help\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that flag names are completed\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"-\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"--first\",\n\t\t\"-f\",\n\t\t\"--help\",\n\t\t\"-h\",\n\t\t\"--second\",\n\t\t\"-s\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileCo"} | |
| {"repo":"cobra","file":"completions_test.go","line":583,"symbol":"TestFlagNameCompletionInGoWithDesc","kind":"function","lang":"go","code":"func TestFlagNameCompletionInGoWithDesc(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\tchildCmd := &Command{\n\t\tUse: \"childCmd\",\n\t\tShort: \"first command\",\n\t\tVersion: \"1.2.3\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\trootCmd.Flags().IntP(\"first\", \"f\", -1, \"first flag\\nlonger description for flag\")\n\trootCmd.PersistentFlags().BoolP(\"second\", \"s\", false, \"second flag\")\n\tchildCmd.Flags().String(\"subFlag\", \"\", \"sub flag\")\n\n\t// Test that flag names are not shown if the user has not given the '-' prefix\n\toutput, err := executeCommand(rootCmd, ShellCompRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"childCmd\\tfirst command\",\n\t\t\"completion\\tGenerate the autocompletion script for the specified shell\",\n\t\t\"help\\tHelp about any command\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that flag names are completed\n\toutput, err = executeCommand(rootCmd, ShellCompRequestCmd, \"-\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = stri"} | |
| {"repo":"cobra","file":"completions_test.go","line":676,"symbol":"customMultiString","kind":"type","lang":"go","doc":"customMultiString is a custom Value type that accepts multiple values, but does not include \"Slice\" or \"Array\" in its \"Type\" string.","code":"type customMultiString []string"} | |
| {"repo":"cobra","file":"completions_test.go","line":678,"symbol":"_","kind":"variable","lang":"go","code":"_ SliceValue = (*customMultiString)(nil)"} | |
| {"repo":"cobra","file":"completions_test.go","line":680,"symbol":"String","kind":"method","lang":"go","code":"func (s *customMultiString) String() string {\n\treturn fmt.Sprintf(\"%v\", *s)\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":684,"symbol":"Set","kind":"method","lang":"go","code":"func (s *customMultiString) Set(v string) error {\n\t*s = append(*s, v)\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":689,"symbol":"Type","kind":"method","lang":"go","code":"func (s *customMultiString) Type() string {\n\treturn \"multi string\"\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":693,"symbol":"GetSlice","kind":"method","lang":"go","code":"func (s *customMultiString) GetSlice() []string {\n\treturn *s\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":697,"symbol":"TestFlagNameCompletionRepeat","kind":"function","lang":"go","code":"func TestFlagNameCompletionRepeat(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\tchildCmd := &Command{\n\t\tUse: \"childCmd\",\n\t\tShort: \"first command\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\trootCmd.Flags().IntP(\"first\", \"f\", -1, \"first flag\")\n\tfirstFlag := rootCmd.Flags().Lookup(\"first\")\n\trootCmd.Flags().BoolP(\"second\", \"s\", false, \"second flag\")\n\tsecondFlag := rootCmd.Flags().Lookup(\"second\")\n\trootCmd.Flags().StringArrayP(\"array\", \"a\", nil, \"array flag\")\n\tarrayFlag := rootCmd.Flags().Lookup(\"array\")\n\trootCmd.Flags().IntSliceP(\"slice\", \"l\", nil, \"slice flag\")\n\tsliceFlag := rootCmd.Flags().Lookup(\"slice\")\n\trootCmd.Flags().BoolSliceP(\"bslice\", \"b\", nil, \"bool slice flag\")\n\tbsliceFlag := rootCmd.Flags().Lookup(\"bslice\")\n\trootCmd.Flags().VarP(&customMultiString{}, \"multi\", \"m\", \"multi string flag\")\n\tmultiFlag := rootCmd.Flags().Lookup(\"multi\")\n\n\t// Test that flag names are not repeated unless they are an array or slice\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"--first\", \"1\", \"--\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\t// Reset the flag for the next command\n\tfirstFlag.Changed = false\n\n\texpected := "} | |
| {"repo":"cobra","file":"completions_test.go","line":844,"symbol":"TestRequiredFlagNameCompletionInGo","kind":"function","lang":"go","code":"func TestRequiredFlagNameCompletionInGo(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tValidArgs: []string{\"realArg\"},\n\t\tRun: emptyRun,\n\t}\n\tchildCmd := &Command{\n\t\tUse: \"childCmd\",\n\t\tValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\t\treturn []string{\"subArg\"}, ShellCompDirectiveNoFileComp\n\t\t},\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\trootCmd.Flags().IntP(\"requiredFlag\", \"r\", -1, \"required flag\")\n\tassertNoErr(t, rootCmd.MarkFlagRequired(\"requiredFlag\"))\n\trequiredFlag := rootCmd.Flags().Lookup(\"requiredFlag\")\n\n\trootCmd.PersistentFlags().IntP(\"requiredPersistent\", \"p\", -1, \"required persistent\")\n\tassertNoErr(t, rootCmd.MarkPersistentFlagRequired(\"requiredPersistent\"))\n\trequiredPersistent := rootCmd.PersistentFlags().Lookup(\"requiredPersistent\")\n\n\trootCmd.Flags().StringP(\"release\", \"R\", \"\", \"Release name\")\n\n\tchildCmd.Flags().BoolP(\"subRequired\", \"s\", false, \"sub required flag\")\n\tassertNoErr(t, childCmd.MarkFlagRequired(\"subRequired\"))\n\tchildCmd.Flags().BoolP(\"subNotRequired\", \"n\", false, \"sub not required flag\")\n\n\t// Test that a required flag is suggested even without the - prefix\n\toutput, err := ex"} | |
| {"repo":"cobra","file":"completions_test.go","line":1038,"symbol":"TestFlagFileExtFilterCompletionInGo","kind":"function","lang":"go","code":"func TestFlagFileExtFilterCompletionInGo(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\n\t// No extensions. Should be ignored.\n\trootCmd.Flags().StringP(\"file\", \"f\", \"\", \"file flag\")\n\tassertNoErr(t, rootCmd.MarkFlagFilename(\"file\"))\n\n\t// Single extension\n\trootCmd.Flags().StringP(\"log\", \"l\", \"\", \"log flag\")\n\tassertNoErr(t, rootCmd.MarkFlagFilename(\"log\", \"log\"))\n\n\t// Multiple extensions\n\trootCmd.Flags().StringP(\"yaml\", \"y\", \"\", \"yaml flag\")\n\tassertNoErr(t, rootCmd.MarkFlagFilename(\"yaml\", \"yaml\", \"yml\"))\n\n\t// Directly using annotation\n\trootCmd.Flags().StringP(\"text\", \"t\", \"\", \"text flag\")\n\tassertNoErr(t, rootCmd.Flags().SetAnnotation(\"text\", BashCompFilenameExt, []string{\"txt\"}))\n\n\t// Test that the completion logic returns the proper info for the completion\n\t// script to handle the file filtering\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"--file\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\toutput, err = execute"} | |
| {"repo":"cobra","file":"completions_test.go","line":1160,"symbol":"TestFlagDirFilterCompletionInGo","kind":"function","lang":"go","code":"func TestFlagDirFilterCompletionInGo(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\n\t// Filter directories\n\trootCmd.Flags().StringP(\"dir\", \"d\", \"\", \"dir flag\")\n\tassertNoErr(t, rootCmd.MarkFlagDirname(\"dir\"))\n\n\t// Filter directories within a directory\n\trootCmd.Flags().StringP(\"subdir\", \"s\", \"\", \"subdir\")\n\tassertNoErr(t, rootCmd.Flags().SetAnnotation(\"subdir\", BashCompSubdirsInDir, []string{\"themes\"}))\n\n\t// Multiple directory specification get ignored\n\trootCmd.Flags().StringP(\"manydir\", \"m\", \"\", \"manydir\")\n\tassertNoErr(t, rootCmd.Flags().SetAnnotation(\"manydir\", BashCompSubdirsInDir, []string{\"themes\", \"colors\"}))\n\n\t// Test that the completion logic returns the proper info for the completion\n\t// script to handle the directory filtering\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"--dir\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\":16\",\n\t\t\"Completion ended with directive: ShellCompDirectiveFilterDirs\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"-d\", \"\")\n\tif e"} | |
| {"repo":"cobra","file":"completions_test.go","line":1276,"symbol":"TestValidArgsFuncCmdContext","kind":"function","lang":"go","code":"func TestValidArgsFuncCmdContext(t *testing.T) {\n\tvalidArgsFunc := func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\tctx := cmd.Context()\n\n\t\tif ctx == nil {\n\t\t\tt.Error(\"Received nil context in completion func\")\n\t\t} else if ctx.Value(\"testKey\") != \"123\" {\n\t\t\tt.Error(\"Received invalid context\")\n\t\t}\n\n\t\treturn nil, ShellCompDirectiveDefault\n\t}\n\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\tchildCmd := &Command{\n\t\tUse: \"childCmd\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\t//nolint:staticcheck // We can safely use a basic type as key in tests.\n\tctx := context.WithValue(context.Background(), \"testKey\", \"123\")\n\n\t// Test completing an empty string on the childCmd\n\t_, output, err := executeCommandWithContextC(ctx, rootCmd, ShellCompNoDescRequestCmd, \"childCmd\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":1318,"symbol":"TestValidArgsFuncSingleCmd","kind":"function","lang":"go","code":"func TestValidArgsFuncSingleCmd(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\n\t// Test completing an empty string\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"one\",\n\t\t\"two\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Check completing with a prefix\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"t\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"two\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":1357,"symbol":"TestValidArgsFuncSingleCmdInvalidArg","kind":"function","lang":"go","code":"func TestValidArgsFuncSingleCmdInvalidArg(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\t// If we don't specify a value for Args, this test fails.\n\t\t// This is only true for a root command without any subcommands, and is caused\n\t\t// by the fact that the __complete command becomes a subcommand when there should not be one.\n\t\t// The problem is in the implementation of legacyArgs().\n\t\tArgs: MinimumNArgs(1),\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\n\t// Check completing with wrong number of args\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"unexpectedArg\", \"t\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":1384,"symbol":"TestValidArgsFuncChildCmds","kind":"function","lang":"go","code":"func TestValidArgsFuncChildCmds(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild1Cmd := &Command{\n\t\tUse: \"child1\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\tchild2Cmd := &Command{\n\t\tUse: \"child2\",\n\t\tValidArgsFunction: validArgsFunc2,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child1Cmd, child2Cmd)\n\n\t// Test completion of first sub-command with empty argument\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"child1\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"one\",\n\t\t\"two\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test completion of first sub-command with a prefix to complete\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"child1\", \"t\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"two\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Error"} | |
| {"repo":"cobra","file":"completions_test.go","line":1488,"symbol":"TestValidArgsFuncAliases","kind":"function","lang":"go","code":"func TestValidArgsFuncAliases(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild := &Command{\n\t\tUse: \"child\",\n\t\tAliases: []string{\"son\", \"daughter\"},\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child)\n\n\t// Test completion of first sub-command with empty argument\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"son\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"one\",\n\t\t\"two\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test completion of first sub-command with a prefix to complete\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"daughter\", \"t\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"two\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Check completing with wrong number of args\n\tou"} | |
| {"repo":"cobra","file":"completions_test.go","line":1544,"symbol":"TestValidArgsFuncInBashScript","kind":"function","lang":"go","code":"func TestValidArgsFuncInBashScript(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild := &Command{\n\t\tUse: \"child\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child)\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, rootCmd.GenBashCompletion(buf))\n\toutput := buf.String()\n\n\tcheck(t, output, \"has_completion_function=1\")\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":1560,"symbol":"TestNoValidArgsFuncInBashScript","kind":"function","lang":"go","code":"func TestNoValidArgsFuncInBashScript(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild := &Command{\n\t\tUse: \"child\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child)\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, rootCmd.GenBashCompletion(buf))\n\toutput := buf.String()\n\n\tcheckOmit(t, output, \"has_completion_function=1\")\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":1575,"symbol":"TestCompleteCmdInBashScript","kind":"function","lang":"go","code":"func TestCompleteCmdInBashScript(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild := &Command{\n\t\tUse: \"child\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child)\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, rootCmd.GenBashCompletion(buf))\n\toutput := buf.String()\n\n\tcheck(t, output, ShellCompNoDescRequestCmd)\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":1591,"symbol":"TestCompleteNoDesCmdInZshScript","kind":"function","lang":"go","code":"func TestCompleteNoDesCmdInZshScript(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild := &Command{\n\t\tUse: \"child\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child)\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, rootCmd.GenZshCompletionNoDesc(buf))\n\toutput := buf.String()\n\n\tcheck(t, output, ShellCompNoDescRequestCmd)\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":1607,"symbol":"TestCompleteCmdInZshScript","kind":"function","lang":"go","code":"func TestCompleteCmdInZshScript(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild := &Command{\n\t\tUse: \"child\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child)\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, rootCmd.GenZshCompletion(buf))\n\toutput := buf.String()\n\n\tcheck(t, output, ShellCompRequestCmd)\n\tcheckOmit(t, output, ShellCompNoDescRequestCmd)\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":1624,"symbol":"TestFlagCompletionInGo","kind":"function","lang":"go","code":"func TestFlagCompletionInGo(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.Flags().IntP(\"introot\", \"i\", -1, \"help message for flag introot\")\n\tassertNoErr(t, rootCmd.RegisterFlagCompletionFunc(\"introot\", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\tcompletions := []string{}\n\t\tfor _, comp := range []string{\"1\\tThe first\", \"2\\tThe second\", \"10\\tThe tenth\"} {\n\t\t\tif strings.HasPrefix(comp, toComplete) {\n\t\t\t\tcompletions = append(completions, comp)\n\t\t\t}\n\t\t}\n\t\treturn completions, ShellCompDirectiveDefault\n\t}))\n\trootCmd.Flags().String(\"filename\", \"\", \"Enter a filename\")\n\tassertNoErr(t, rootCmd.RegisterFlagCompletionFunc(\"filename\", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\tcompletions := []string{}\n\t\tfor _, comp := range []string{\"file.yaml\\tYAML format\", \"myfile.json\\tJSON format\", \"file.xml\\tXML format\"} {\n\t\t\tif strings.HasPrefix(comp, toComplete) {\n\t\t\t\tcompletions = append(completions, comp)\n\t\t\t}\n\t\t}\n\t\treturn completions, ShellCompDirectiveNoSpace | ShellCompDirectiveNoFileComp\n\t}))\n\n\t// Test completing an empty string\n\toutput, err := executeCommand(rootCmd, ShellCo"} | |
| {"repo":"cobra","file":"completions_test.go","line":1717,"symbol":"TestValidArgsFuncChildCmdsWithDesc","kind":"function","lang":"go","code":"func TestValidArgsFuncChildCmdsWithDesc(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild1Cmd := &Command{\n\t\tUse: \"child1\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\tchild2Cmd := &Command{\n\t\tUse: \"child2\",\n\t\tValidArgsFunction: validArgsFunc2,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child1Cmd, child2Cmd)\n\n\t// Test completion of first sub-command with empty argument\n\toutput, err := executeCommand(rootCmd, ShellCompRequestCmd, \"child1\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"one\\tThe first\",\n\t\t\"two\\tThe second\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test completion of first sub-command with a prefix to complete\n\toutput, err = executeCommand(rootCmd, ShellCompRequestCmd, \"child1\", \"t\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"two\\tThe second\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif"} | |
| {"repo":"cobra","file":"completions_test.go","line":1821,"symbol":"TestFlagCompletionWithNotInterspersedArgs","kind":"function","lang":"go","code":"func TestFlagCompletionWithNotInterspersedArgs(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\tchildCmd := &Command{\n\t\tUse: \"child\",\n\t\tRun: emptyRun,\n\t\tValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\t\treturn []string{\"--validarg\", \"test\"}, ShellCompDirectiveDefault\n\t\t},\n\t}\n\tchildCmd2 := &Command{\n\t\tUse: \"child2\",\n\t\tRun: emptyRun,\n\t\tValidArgs: []string{\"arg1\", \"arg2\"},\n\t}\n\trootCmd.AddCommand(childCmd, childCmd2)\n\tchildCmd.Flags().Bool(\"bool\", false, \"test bool flag\")\n\tchildCmd.Flags().String(\"string\", \"\", \"test string flag\")\n\t_ = childCmd.RegisterFlagCompletionFunc(\"string\", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\treturn []string{\"myval\"}, ShellCompDirectiveDefault\n\t})\n\n\t// Test flag completion with no argument\n\toutput, err := executeCommand(rootCmd, ShellCompRequestCmd, \"child\", \"--\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"--bool\\ttest bool flag\",\n\t\t\"--help\\thelp for child\",\n\t\t\"--string\\ttest string flag\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\"} | |
| {"repo":"cobra","file":"completions_test.go","line":2044,"symbol":"TestFlagCompletionWorksRootCommandAddedAfterFlags","kind":"function","lang":"go","code":"func TestFlagCompletionWorksRootCommandAddedAfterFlags(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\tchildCmd := &Command{\n\t\tUse: \"child\",\n\t\tRun: emptyRun,\n\t\tValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\t\treturn []string{\"--validarg\", \"test\"}, ShellCompDirectiveDefault\n\t\t},\n\t}\n\tchildCmd.Flags().Bool(\"bool\", false, \"test bool flag\")\n\tchildCmd.Flags().String(\"string\", \"\", \"test string flag\")\n\t_ = childCmd.RegisterFlagCompletionFunc(\"string\", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\treturn []string{\"myval\"}, ShellCompDirectiveDefault\n\t})\n\n\t// Important: This is a test for https://github.com/spf13/cobra/issues/1437\n\t// Only add the subcommand after RegisterFlagCompletionFunc was called, do not change this order!\n\trootCmd.AddCommand(childCmd)\n\n\t// Test that flag completion works for the subcmd\n\toutput, err := executeCommand(rootCmd, ShellCompRequestCmd, \"child\", \"--string\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"myval\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \""} | |
| {"repo":"cobra","file":"completions_test.go","line":2079,"symbol":"TestFlagCompletionForPersistentFlagsCalledFromSubCmd","kind":"function","lang":"go","code":"func TestFlagCompletionForPersistentFlagsCalledFromSubCmd(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\trootCmd.PersistentFlags().String(\"string\", \"\", \"test string flag\")\n\t_ = rootCmd.RegisterFlagCompletionFunc(\"string\", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\treturn []string{\"myval\"}, ShellCompDirectiveDefault\n\t})\n\n\tchildCmd := &Command{\n\t\tUse: \"child\",\n\t\tRun: emptyRun,\n\t\tValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\t\treturn []string{\"--validarg\", \"test\"}, ShellCompDirectiveDefault\n\t\t},\n\t}\n\tchildCmd.Flags().Bool(\"bool\", false, \"test bool flag\")\n\trootCmd.AddCommand(childCmd)\n\n\t// Test that persistent flag completion works for the subcmd\n\toutput, err := executeCommand(rootCmd, ShellCompRequestCmd, \"child\", \"--string\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"myval\",\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":2121,"symbol":"TestFlagCompletionConcurrentRegistration","kind":"function","lang":"go","doc":"https://github.com/spf13/cobra/issues/1320 NOTE: this test can sometimes pass even if the code were to not handle concurrency properly. This is not great but the important part is that it should never fail. Therefore, if the tests fails sometimes, we will still be able to know there is a problem.","code":"func TestFlagCompletionConcurrentRegistration(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Run: emptyRun}\n\tconst maxFlags = 50\n\tfor i := 1; i < maxFlags; i += 2 {\n\t\tflagName := fmt.Sprintf(\"flag%d\", i)\n\t\trootCmd.Flags().String(flagName, \"\", fmt.Sprintf(\"test %s flag on root\", flagName))\n\t}\n\n\tchildCmd := &Command{\n\t\tUse: \"child\",\n\t\tRun: emptyRun,\n\t}\n\tfor i := 2; i <= maxFlags; i += 2 {\n\t\tflagName := fmt.Sprintf(\"flag%d\", i)\n\t\tchildCmd.Flags().String(flagName, \"\", fmt.Sprintf(\"test %s flag on child\", flagName))\n\t}\n\n\trootCmd.AddCommand(childCmd)\n\n\t// Register completion in different threads to test concurrency.\n\tvar wg sync.WaitGroup\n\tfor i := 1; i <= maxFlags; i++ {\n\t\tindex := i\n\t\tflagName := fmt.Sprintf(\"flag%d\", i)\n\t\twg.Add(1)\n\t\tgo func() {\n\t\t\tdefer wg.Done()\n\t\t\tcmd := rootCmd\n\t\t\tif index%2 == 0 {\n\t\t\t\tcmd = childCmd\n\t\t\t}\n\t\t\t_ = cmd.RegisterFlagCompletionFunc(flagName, func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\t\t\treturn []string{fmt.Sprintf(\"flag%d\", index)}, ShellCompDirectiveDefault\n\t\t\t})\n\t\t}()\n\t}\n\n\twg.Wait()\n\n\t// Test that flag completion works for each flag\n\tfor i := 1; i <= 6; i++ {\n\t\tvar output string\n\t\tvar err error\n\t\tflagName"} | |
| {"repo":"cobra","file":"completions_test.go","line":2123,"symbol":"maxFlags","kind":"constant","lang":"go","code":"maxFlags = 50"} | |
| {"repo":"cobra","file":"completions_test.go","line":2141,"symbol":"wg","kind":"variable","lang":"go","doc":"Register completion in different threads to test concurrency.","code":"wg sync.WaitGroup"} | |
| {"repo":"cobra","file":"completions_test.go","line":2162,"symbol":"output","kind":"variable","lang":"go","code":"output string"} | |
| {"repo":"cobra","file":"completions_test.go","line":2163,"symbol":"err","kind":"variable","lang":"go","code":"err error"} | |
| {"repo":"cobra","file":"completions_test.go","line":2187,"symbol":"TestFlagCompletionInGoWithDesc","kind":"function","lang":"go","code":"func TestFlagCompletionInGoWithDesc(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.Flags().IntP(\"introot\", \"i\", -1, \"help message for flag introot\")\n\tassertNoErr(t, rootCmd.RegisterFlagCompletionFunc(\"introot\", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\tcompletions := []string{}\n\t\tfor _, comp := range []string{\"1\\tThe first\", \"2\\tThe second\", \"10\\tThe tenth\"} {\n\t\t\tif strings.HasPrefix(comp, toComplete) {\n\t\t\t\tcompletions = append(completions, comp)\n\t\t\t}\n\t\t}\n\t\treturn completions, ShellCompDirectiveDefault\n\t}))\n\trootCmd.Flags().String(\"filename\", \"\", \"Enter a filename\")\n\tassertNoErr(t, rootCmd.RegisterFlagCompletionFunc(\"filename\", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\tcompletions := []string{}\n\t\tfor _, comp := range []string{\"file.yaml\\tYAML format\", \"myfile.json\\tJSON format\", \"file.xml\\tXML format\"} {\n\t\t\tif strings.HasPrefix(comp, toComplete) {\n\t\t\t\tcompletions = append(completions, comp)\n\t\t\t}\n\t\t}\n\t\treturn completions, ShellCompDirectiveNoSpace | ShellCompDirectiveNoFileComp\n\t}))\n\n\t// Test completing an empty string\n\toutput, err := executeCommand(rootCmd,"} | |
| {"repo":"cobra","file":"completions_test.go","line":2280,"symbol":"TestValidArgsNotValidArgsFunc","kind":"function","lang":"go","code":"func TestValidArgsNotValidArgsFunc(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tValidArgs: []string{\"one\", \"two\"},\n\t\tValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\t\treturn []string{\"three\", \"four\"}, ShellCompDirectiveNoFileComp\n\t\t},\n\t\tRun: emptyRun,\n\t}\n\n\t// Test that if both ValidArgs and ValidArgsFunction are present\n\t// only ValidArgs is considered\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"one\",\n\t\t\"two\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Check completing with a prefix\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"t\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"two\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":2323,"symbol":"TestArgAliasesCompletionInGo","kind":"function","lang":"go","code":"func TestArgAliasesCompletionInGo(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tArgs: OnlyValidArgs,\n\t\tValidArgs: []string{\"one\", \"two\", \"three\"},\n\t\tArgAliases: []string{\"un\", \"deux\", \"trois\"},\n\t\tRun: emptyRun,\n\t}\n\n\t// Test that argaliases are not completed when there are validargs that match\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"one\",\n\t\t\"two\",\n\t\t\"three\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that argaliases are not completed when there are validargs that match using a prefix\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"t\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"two\",\n\t\t\"three\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that argaliases are completed when there are no v"} | |
| {"repo":"cobra","file":"completions_test.go","line":2381,"symbol":"TestCompleteHelp","kind":"function","lang":"go","code":"func TestCompleteHelp(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild1Cmd := &Command{\n\t\tUse: \"child1\",\n\t\tRun: emptyRun,\n\t}\n\tchild2Cmd := &Command{\n\t\tUse: \"child2\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child1Cmd, child2Cmd)\n\n\tchild3Cmd := &Command{\n\t\tUse: \"child3\",\n\t\tRun: emptyRun,\n\t}\n\tchild1Cmd.AddCommand(child3Cmd)\n\n\t// Test that completion includes the help command\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"child1\",\n\t\t\"child2\",\n\t\t\"completion\",\n\t\t\"help\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test sub-commands are completed on first level of help command\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"help\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"child1\",\n\t\t\"child2\",\n\t\t\"completion\",\n\t\t\"help\", // \"<program> help help\" is a valid command, so should be completed\n\t\t\":4\",\n\t\t\"Completion ended with directiv"} | |
| {"repo":"cobra","file":"completions_test.go","line":2451,"symbol":"removeCompCmd","kind":"function","lang":"go","code":"func removeCompCmd(rootCmd *Command) {\n\t// Remove completion command for the next test\n\tfor _, cmd := range rootCmd.commands {\n\t\tif cmd.Name() == compCmdName {\n\t\t\trootCmd.RemoveCommand(cmd)\n\t\t\treturn\n\t\t}\n\t}\n}"} | |
| {"repo":"cobra","file":"completions_test.go","line":2461,"symbol":"TestDefaultCompletionCmd","kind":"function","lang":"go","code":"func TestDefaultCompletionCmd(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tArgs: NoArgs,\n\t\tRun: emptyRun,\n\t}\n\n\t// Test that when there are no sub-commands, the completion command is not created if it is not called directly.\n\tassertNoErr(t, rootCmd.Execute())\n\tfor _, cmd := range rootCmd.commands {\n\t\tif cmd.Name() == compCmdName {\n\t\t\tt.Errorf(\"Should not have a 'completion' command when there are no other sub-commands of root\")\n\t\t\tbreak\n\t\t}\n\t}\n\n\t// Test that when there are no sub-commands, the completion command is created when it is called directly.\n\t_, err := executeCommand(rootCmd, compCmdName)\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\t// Reset the arguments\n\trootCmd.args = nil\n\t// Remove completion command for the next test\n\tremoveCompCmd(rootCmd)\n\n\t// Add a sub-command\n\tsubCmd := &Command{\n\t\tUse: \"sub\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(subCmd)\n\n\t// Test that a completion command is created if there are other sub-commands\n\tfound := false\n\tassertNoErr(t, rootCmd.Execute())\n\tfor _, cmd := range rootCmd.commands {\n\t\tif cmd.Name() == compCmdName {\n\t\t\tfound = true\n\t\t\tbreak\n\t\t}\n\t}\n\tif !found {\n\t\tt.Errorf(\"Should have a 'completion' command when th"} | |
| {"repo":"cobra","file":"completions_test.go","line":2545,"symbol":"compCmd","kind":"variable","lang":"go","code":"compCmd *Command"} | |
| {"repo":"cobra","file":"completions_test.go","line":2607,"symbol":"TestCompleteCompletion","kind":"function","lang":"go","code":"func TestCompleteCompletion(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\n\t// Test that when there are no sub-commands, the 'completion' command is not completed\n\t// (because it is not created).\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"completion\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\":0\",\n\t\t\"Completion ended with directive: ShellCompDirectiveDefault\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that when there are no sub-commands, completion can be triggered for the default\n\t// 'completion' command\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"completion\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"bash\",\n\t\t\"fish\",\n\t\t\"powershell\",\n\t\t\"zsh\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Add a sub-command\n\tsubCmd := &Command{\n\t\tUse: \"sub\",\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(subCmd)\n\n\t// Test s"} | |
| {"repo":"cobra","file":"completions_test.go","line":2670,"symbol":"compCmd","kind":"variable","lang":"go","doc":"Test there are no completions for the sub-commands of the completion command","code":"compCmd *Command"} | |
| {"repo":"cobra","file":"completions_test.go","line":2694,"symbol":"TestMultipleShorthandFlagCompletion","kind":"function","lang":"go","code":"func TestMultipleShorthandFlagCompletion(t *testing.T) {\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tValidArgs: []string{\"foo\", \"bar\"},\n\t\tRun: emptyRun,\n\t}\n\tf := rootCmd.Flags()\n\tf.BoolP(\"short\", \"s\", false, \"short flag 1\")\n\tf.BoolP(\"short2\", \"d\", false, \"short flag 2\")\n\tf.StringP(\"short3\", \"f\", \"\", \"short flag 3\")\n\t_ = rootCmd.RegisterFlagCompletionFunc(\"short3\", func(*Command, []string, string) ([]string, ShellCompDirective) {\n\t\treturn []string{\"works\"}, ShellCompDirectiveNoFileComp\n\t})\n\n\t// Test that a single shorthand flag works\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"-s\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"foo\",\n\t\t\"bar\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Test that multiple boolean shorthand flags work\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"-sd\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"foo\",\n\t\t\"bar\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: Shell"} | |
| {"repo":"cobra","file":"completions_test.go","line":2787,"symbol":"TestCompleteWithDisableFlagParsing","kind":"function","lang":"go","code":"func TestCompleteWithDisableFlagParsing(t *testing.T) {\n\n\tflagValidArgs := func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\treturn []string{\"--flag\", \"-f\"}, ShellCompDirectiveNoFileComp\n\t}\n\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchildCmd := &Command{\n\t\tUse: \"child\",\n\t\tRun: emptyRun,\n\t\tDisableFlagParsing: true,\n\t\tValidArgsFunction: flagValidArgs,\n\t}\n\trootCmd.AddCommand(childCmd)\n\n\trootCmd.PersistentFlags().StringP(\"persistent\", \"p\", \"\", \"persistent flag\")\n\tchildCmd.Flags().StringP(\"nonPersistent\", \"n\", \"\", \"non-persistent flag\")\n\n\t// Test that when DisableFlagParsing==true, ValidArgsFunction is called to complete flag names,\n\t// after Cobra tried to complete the flags it knows about.\n\tchildCmd.DisableFlagParsing = true\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"child\", \"-\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"--persistent\",\n\t\t\"-p\",\n\t\t\"--nonPersistent\",\n\t\t\"-n\",\n\t\t\"--flag\",\n\t\t\"-f\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\""} | |
| {"repo":"cobra","file":"completions_test.go","line":2850,"symbol":"TestCompleteWithRootAndLegacyArgs","kind":"function","lang":"go","code":"func TestCompleteWithRootAndLegacyArgs(t *testing.T) {\n\t// Test a lonely root command which uses legacyArgs(). In such a case, the root\n\t// command should accept any number of arguments and completion should behave accordingly.\n\trootCmd := &Command{\n\t\tUse: \"root\",\n\t\tArgs: nil, // Args must be nil to trigger the legacyArgs() function\n\t\tRun: emptyRun,\n\t\tValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {\n\t\t\treturn []string{\"arg1\", \"arg2\"}, ShellCompDirectiveNoFileComp\n\t\t},\n\t}\n\n\t// Make sure the first arg is completed\n\toutput, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected := strings.Join([]string{\n\t\t\"arg1\",\n\t\t\"arg2\",\n\t\t\":4\",\n\t\t\"Completion ended with directive: ShellCompDirectiveNoFileComp\", \"\"}, \"\\n\")\n\n\tif output != expected {\n\t\tt.Errorf(\"expected: %q, got: %q\", expected, output)\n\t}\n\n\t// Make sure the completion of arguments continues\n\toutput, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, \"arg1\", \"\")\n\tif err != nil {\n\t\tt.Errorf(\"Unexpected error: %v\", err)\n\t}\n\n\texpected = strings.Join([]string{\n\t\t\"arg1\",\n\t\t\"arg2\",\n\t\t\":4\",\n\t\t\"Completi"} | |
| {"repo":"cobra","file":"completions_test.go","line":2896,"symbol":"TestCompletionFuncCompatibility","kind":"function","lang":"go","code":"func TestCompletionFuncCompatibility(t *testing.T) {\n\tt.Run(\"validate signature\", func(t *testing.T) {\n\t\tt.Run(\"format with []string\", func(t *testing.T) {\n\t\t\tvar userComp func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective)\n\n\t\t\t// check against new signature\n\t\t\tvar _ CompletionFunc = userComp //nolint:staticcheck // LHS type is needed for this use case\n\n\t\t\t// check Command accepts\n\t\t\tcmd := Command{\n\t\t\t\tValidArgsFunction: userComp,\n\t\t\t}\n\n\t\t\t_ = cmd.RegisterFlagCompletionFunc(\"foo\", userComp)\n\t\t})\n\n\t\tt.Run(\"format with []Completion\", func(t *testing.T) {\n\t\t\tvar userComp func(cmd *Command, args []string, toComplete string) ([]Completion, ShellCompDirective)\n\n\t\t\t// check against new signature\n\t\t\tvar _ CompletionFunc = userComp //nolint:staticcheck // LHS type is needed for this use case\n\t\t\t// check Command accepts\n\t\t\tcmd := Command{\n\t\t\t\tValidArgsFunction: userComp,\n\t\t\t}\n\n\t\t\t_ = cmd.RegisterFlagCompletionFunc(\"foo\", userComp)\n\t\t})\n\n\t\tt.Run(\"format with CompletionFunc\", func(t *testing.T) {\n\t\t\tvar userComp CompletionFunc\n\n\t\t\t// check helper against old signature\n\t\t\tvar _ func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) ="} | |
| {"repo":"cobra","file":"completions_test.go","line":2899,"symbol":"userComp","kind":"variable","lang":"go","code":"userComp func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective)"} | |
| {"repo":"cobra","file":"completions_test.go","line":2902,"symbol":"_","kind":"variable","lang":"go","doc":"check against new signature","code":"_ CompletionFunc = userComp"} | |
| {"repo":"cobra","file":"completions_test.go","line":2913,"symbol":"userComp","kind":"variable","lang":"go","code":"userComp func(cmd *Command, args []string, toComplete string) ([]Completion, ShellCompDirective)"} | |
| {"repo":"cobra","file":"completions_test.go","line":2916,"symbol":"_","kind":"variable","lang":"go","doc":"check against new signature","code":"_ CompletionFunc = userComp"} | |
| {"repo":"cobra","file":"completions_test.go","line":2926,"symbol":"userComp","kind":"variable","lang":"go","code":"userComp CompletionFunc"} | |
| {"repo":"cobra","file":"completions_test.go","line":2929,"symbol":"_","kind":"variable","lang":"go","doc":"check helper against old signature","code":"_ func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) = userComp"} | |
| {"repo":"cobra","file":"doc/cmd_test.go","line":24,"symbol":"emptyRun","kind":"function","lang":"go","code":"func emptyRun(*cobra.Command, []string) {}"} | |
| {"repo":"cobra","file":"doc/cmd_test.go","line":26,"symbol":"init","kind":"function","lang":"go","code":"func init() {\n\trootCmd.PersistentFlags().StringP(\"rootflag\", \"r\", \"two\", \"\")\n\trootCmd.PersistentFlags().StringP(\"strtwo\", \"t\", \"two\", \"help message for parent flag strtwo\")\n\n\techoCmd.PersistentFlags().StringP(\"strone\", \"s\", \"one\", \"help message for flag strone\")\n\techoCmd.PersistentFlags().BoolP(\"persistentbool\", \"p\", false, \"help message for flag persistentbool\")\n\techoCmd.Flags().IntP(\"intone\", \"i\", 123, \"help message for flag intone\")\n\techoCmd.Flags().BoolP(\"boolone\", \"b\", true, \"help message for flag boolone\")\n\n\ttimesCmd.PersistentFlags().StringP(\"strtwo\", \"t\", \"2\", \"help message for child flag strtwo\")\n\ttimesCmd.Flags().IntP(\"inttwo\", \"j\", 234, \"help message for flag inttwo\")\n\ttimesCmd.Flags().BoolP(\"booltwo\", \"c\", false, \"help message for flag booltwo\")\n\n\tprintCmd.PersistentFlags().StringP(\"strthree\", \"s\", \"three\", \"help message for flag strthree\")\n\tprintCmd.Flags().IntP(\"intthree\", \"i\", 345, \"help message for flag intthree\")\n\tprintCmd.Flags().BoolP(\"boolthree\", \"b\", true, \"help message for flag boolthree\")\n\n\techoCmd.AddCommand(timesCmd, echoSubCmd, deprecatedCmd)\n\trootCmd.AddCommand(printCmd, echoCmd, dummyCmd)\n}"} | |
| {"repo":"cobra","file":"doc/cmd_test.go","line":47,"symbol":"rootCmd","kind":"variable","lang":"go","code":"rootCmd = &cobra.Command{\n\tUse: \"root\",\n\tShort: \"Root short description\",\n\tLong: \"Root long description\",\n\tRun: emptyRun,\n}"} | |
| {"repo":"cobra","file":"doc/cmd_test.go","line":54,"symbol":"echoCmd","kind":"variable","lang":"go","code":"echoCmd = &cobra.Command{\n\tUse: \"echo [string to echo]\",\n\tAliases: []string{\"say\"},\n\tShort: \"Echo anything to the screen\",\n\tLong: \"an utterly useless command for testing\",\n\tExample: \"Just run cobra-test echo\",\n}"} | |
| {"repo":"cobra","file":"doc/cmd_test.go","line":62,"symbol":"echoSubCmd","kind":"variable","lang":"go","code":"echoSubCmd = &cobra.Command{\n\tUse: \"echosub [string to print]\",\n\tShort: \"second sub command for echo\",\n\tLong: \"an absolutely utterly useless command for testing gendocs!.\",\n\tRun: emptyRun,\n}"} | |
| {"repo":"cobra","file":"doc/cmd_test.go","line":69,"symbol":"timesCmd","kind":"variable","lang":"go","code":"timesCmd = &cobra.Command{\n\tUse: \"times [# times] [string to echo]\",\n\tSuggestFor: []string{\"counts\"},\n\tShort: \"Echo anything to the screen more times\",\n\tLong: `a slightly useless command for testing.`,\n\tRun: emptyRun,\n}"} | |
| {"repo":"cobra","file":"doc/cmd_test.go","line":77,"symbol":"deprecatedCmd","kind":"variable","lang":"go","code":"deprecatedCmd = &cobra.Command{\n\tUse: \"deprecated [can't do anything here]\",\n\tShort: \"A command which is deprecated\",\n\tLong: `an absolutely utterly useless command for testing deprecation!.`,\n\tDeprecated: \"Please use echo instead\",\n}"} | |
| {"repo":"cobra","file":"doc/cmd_test.go","line":84,"symbol":"printCmd","kind":"variable","lang":"go","code":"printCmd = &cobra.Command{\n\tUse: \"print [string to print]\",\n\tShort: \"Print anything to the screen\",\n\tLong: `an absolutely utterly useless command for testing.`,\n}"} | |
| {"repo":"cobra","file":"doc/cmd_test.go","line":90,"symbol":"dummyCmd","kind":"variable","lang":"go","code":"dummyCmd = &cobra.Command{\n\tUse: \"dummy [action]\",\n\tShort: \"Performs a dummy action\",\n}"} | |
| {"repo":"cobra","file":"doc/cmd_test.go","line":95,"symbol":"checkStringContains","kind":"function","lang":"go","code":"func checkStringContains(t *testing.T, got, expected string) {\n\tif !strings.Contains(got, expected) {\n\t\tt.Errorf(\"Expected to contain: \\n %v\\nGot:\\n %v\\n\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/cmd_test.go","line":101,"symbol":"checkStringOmits","kind":"function","lang":"go","code":"func checkStringOmits(t *testing.T, got, expected string) {\n\tif strings.Contains(got, expected) {\n\t\tt.Errorf(\"Expected to not contain: \\n %v\\nGot: %v\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/man_docs.go","line":38,"symbol":"GenManTree","kind":"function","lang":"go","doc":"GenManTree will generate a man page for this command and all descendants in the directory given. The header may be nil. This function may not work correctly if your command names have `-` in them. If you have `cmd` with two subcmds, `sub` and `sub-third`, and `sub` has a subcommand called `third` it is undefined which help output will be in the file `cmd-sub-third.1`.","code":"func GenManTree(cmd *cobra.Command, header *GenManHeader, dir string) error {\n\treturn GenManTreeFromOpts(cmd, GenManTreeOptions{\n\t\tHeader: header,\n\t\tPath: dir,\n\t\tCommandSeparator: \"-\",\n\t})\n}"} | |
| {"repo":"cobra","file":"doc/man_docs.go","line":48,"symbol":"GenManTreeFromOpts","kind":"function","lang":"go","doc":"GenManTreeFromOpts generates a man page for the command and all descendants. The pages are written to the opts.Path directory.","code":"func GenManTreeFromOpts(cmd *cobra.Command, opts GenManTreeOptions) error {\n\theader := opts.Header\n\tif header == nil {\n\t\theader = &GenManHeader{}\n\t}\n\tfor _, c := range cmd.Commands() {\n\t\tif !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {\n\t\t\tcontinue\n\t\t}\n\t\tif err := GenManTreeFromOpts(c, opts); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\tsection := \"1\"\n\tif header.Section != \"\" {\n\t\tsection = header.Section\n\t}\n\n\tseparator := \"_\"\n\tif opts.CommandSeparator != \"\" {\n\t\tseparator = opts.CommandSeparator\n\t}\n\tbasename := strings.ReplaceAll(cmd.CommandPath(), \" \", separator)\n\tfilename := filepath.Join(opts.Path, basename+\".\"+section)\n\tf, err := os.Create(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()\n\n\theaderCopy := *header\n\treturn GenMan(cmd, &headerCopy, f)\n}"} | |
| {"repo":"cobra","file":"doc/man_docs.go","line":84,"symbol":"GenManTreeOptions","kind":"type","lang":"go","doc":"GenManTreeOptions is the options for generating the man pages. Used only in GenManTreeFromOpts.","code":"type GenManTreeOptions struct {\n\tHeader *GenManHeader\n\tPath string\n\tCommandSeparator string\n}"} | |
| {"repo":"cobra","file":"doc/man_docs.go","line":94,"symbol":"GenManHeader","kind":"type","lang":"go","doc":"GenManHeader is a lot like the .TH header at the start of man pages. These include the title, section, date, source, and manual. We will use the current time if Date is unset and will use \"Auto generated by spf13/cobra\" if the Source is unset.","code":"type GenManHeader struct {\n\tTitle string\n\tSection string\n\tDate *time.Time\n\tdate string\n\tSource string\n\tManual string\n}"} | |
| {"repo":"cobra","file":"doc/man_docs.go","line":105,"symbol":"GenMan","kind":"function","lang":"go","doc":"GenMan will generate a man page for the given command and write it to w. The header argument may be nil, however obviously w may not.","code":"func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {\n\tif header == nil {\n\t\theader = &GenManHeader{}\n\t}\n\tif err := fillHeader(header, cmd.CommandPath(), cmd.DisableAutoGenTag); err != nil {\n\t\treturn err\n\t}\n\n\tb := genMan(cmd, header)\n\t_, err := w.Write(md2man.Render(b))\n\treturn err\n}"} | |
| {"repo":"cobra","file":"doc/man_docs.go","line":118,"symbol":"fillHeader","kind":"function","lang":"go","code":"func fillHeader(header *GenManHeader, name string, disableAutoGen bool) error {\n\tif header.Title == \"\" {\n\t\theader.Title = strings.ToUpper(strings.ReplaceAll(name, \" \", \"\\\\-\"))\n\t}\n\tif header.Section == \"\" {\n\t\theader.Section = \"1\"\n\t}\n\tif header.Date == nil {\n\t\tnow := time.Now()\n\t\tif epoch := os.Getenv(\"SOURCE_DATE_EPOCH\"); epoch != \"\" {\n\t\t\tunixEpoch, err := strconv.ParseInt(epoch, 10, 64)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"invalid SOURCE_DATE_EPOCH: %v\", err)\n\t\t\t}\n\t\t\tnow = time.Unix(unixEpoch, 0)\n\t\t}\n\t\theader.Date = &now\n\t}\n\theader.date = header.Date.Format(\"Jan 2006\")\n\tif header.Source == \"\" && !disableAutoGen {\n\t\theader.Source = \"Auto generated by spf13/cobra\"\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"doc/man_docs.go","line":143,"symbol":"manPreamble","kind":"function","lang":"go","code":"func manPreamble(buf io.StringWriter, header *GenManHeader, cmd *cobra.Command, dashedName string) {\n\tdescription := cmd.Long\n\tif len(description) == 0 {\n\t\tdescription = cmd.Short\n\t}\n\n\tcobra.WriteStringAndCheck(buf, fmt.Sprintf(`%% \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n# NAME\n`, header.Title, header.Section, header.date, header.Source, header.Manual))\n\tcobra.WriteStringAndCheck(buf, fmt.Sprintf(\"%s \\\\- %s\\n\\n\", dashedName, cmd.Short))\n\tcobra.WriteStringAndCheck(buf, \"# SYNOPSIS\\n\")\n\tcobra.WriteStringAndCheck(buf, fmt.Sprintf(\"**%s**\\n\\n\", cmd.UseLine()))\n\tcobra.WriteStringAndCheck(buf, \"# DESCRIPTION\\n\")\n\tcobra.WriteStringAndCheck(buf, description+\"\\n\\n\")\n}"} | |
| {"repo":"cobra","file":"doc/man_docs.go","line":159,"symbol":"manPrintFlags","kind":"function","lang":"go","code":"func manPrintFlags(buf io.StringWriter, flags *pflag.FlagSet) {\n\tflags.VisitAll(func(flag *pflag.Flag) {\n\t\tif len(flag.Deprecated) > 0 || flag.Hidden {\n\t\t\treturn\n\t\t}\n\t\tformat := \"\"\n\t\tif len(flag.Shorthand) > 0 && len(flag.ShorthandDeprecated) == 0 {\n\t\t\tformat = fmt.Sprintf(\"**-%s**, **--%s**\", flag.Shorthand, flag.Name)\n\t\t} else {\n\t\t\tformat = fmt.Sprintf(\"**--%s**\", flag.Name)\n\t\t}\n\t\tif len(flag.NoOptDefVal) > 0 {\n\t\t\tformat += \"[\"\n\t\t}\n\t\tif flag.Value.Type() == \"string\" {\n\t\t\t// put quotes on the value\n\t\t\tformat += \"=%q\"\n\t\t} else {\n\t\t\tformat += \"=%s\"\n\t\t}\n\t\tif len(flag.NoOptDefVal) > 0 {\n\t\t\tformat += \"]\"\n\t\t}\n\t\tformat += \"\\n\\t%s\\n\\n\"\n\t\tcobra.WriteStringAndCheck(buf, fmt.Sprintf(format, flag.DefValue, flag.Usage))\n\t})\n}"} | |
| {"repo":"cobra","file":"doc/man_docs.go","line":187,"symbol":"manPrintOptions","kind":"function","lang":"go","code":"func manPrintOptions(buf io.StringWriter, command *cobra.Command) {\n\tflags := command.NonInheritedFlags()\n\tif flags.HasAvailableFlags() {\n\t\tcobra.WriteStringAndCheck(buf, \"# OPTIONS\\n\")\n\t\tmanPrintFlags(buf, flags)\n\t\tcobra.WriteStringAndCheck(buf, \"\\n\")\n\t}\n\tflags = command.InheritedFlags()\n\tif flags.HasAvailableFlags() {\n\t\tcobra.WriteStringAndCheck(buf, \"# OPTIONS INHERITED FROM PARENT COMMANDS\\n\")\n\t\tmanPrintFlags(buf, flags)\n\t\tcobra.WriteStringAndCheck(buf, \"\\n\")\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/man_docs.go","line":202,"symbol":"genMan","kind":"function","lang":"go","code":"func genMan(cmd *cobra.Command, header *GenManHeader) []byte {\n\tcmd.InitDefaultHelpCmd()\n\tcmd.InitDefaultHelpFlag()\n\n\t// something like `rootcmd-subcmd1-subcmd2`\n\tdashCommandName := strings.ReplaceAll(cmd.CommandPath(), \" \", \"-\")\n\n\tbuf := new(bytes.Buffer)\n\n\tmanPreamble(buf, header, cmd, dashCommandName)\n\tmanPrintOptions(buf, cmd)\n\tif len(cmd.Example) > 0 {\n\t\tbuf.WriteString(\"# EXAMPLE\\n\")\n\t\tfmt.Fprintf(buf, \"```\\n%s\\n```\\n\", cmd.Example)\n\t}\n\tif hasSeeAlso(cmd) {\n\t\tbuf.WriteString(\"# SEE ALSO\\n\")\n\t\tseealsos := make([]string, 0)\n\t\tif cmd.HasParent() {\n\t\t\tparentPath := cmd.Parent().CommandPath()\n\t\t\tdashParentPath := strings.ReplaceAll(parentPath, \" \", \"-\")\n\t\t\tseealso := fmt.Sprintf(\"**%s(%s)**\", dashParentPath, header.Section)\n\t\t\tseealsos = append(seealsos, seealso)\n\t\t\tcmd.VisitParents(func(c *cobra.Command) {\n\t\t\t\tif c.DisableAutoGenTag {\n\t\t\t\t\tcmd.DisableAutoGenTag = c.DisableAutoGenTag\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t\tchildren := cmd.Commands()\n\t\tsort.Sort(byName(children))\n\t\tfor _, c := range children {\n\t\t\tif !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tseealso := fmt.Sprintf(\"**%s-%s(%s)**\", dashCommandName, c.Name(), header.Section)\n\t\t\tseealsos = append(see"} | |
| {"repo":"cobra","file":"doc/man_docs_test.go","line":29,"symbol":"assertNoErr","kind":"function","lang":"go","code":"func assertNoErr(t *testing.T, e error) {\n\tif e != nil {\n\t\tt.Error(e)\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/man_docs_test.go","line":35,"symbol":"translate","kind":"function","lang":"go","code":"func translate(in string) string {\n\treturn strings.ReplaceAll(in, \"-\", \"\\\\-\")\n}"} | |
| {"repo":"cobra","file":"doc/man_docs_test.go","line":39,"symbol":"TestGenManDoc","kind":"function","lang":"go","code":"func TestGenManDoc(t *testing.T) {\n\theader := &GenManHeader{\n\t\tTitle: \"Project\",\n\t\tSection: \"2\",\n\t}\n\n\t// We generate on a subcommand so we have both subcommands and parents\n\tbuf := new(bytes.Buffer)\n\tif err := GenMan(echoCmd, header, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\t// Make sure parent has - in CommandPath() in SEE ALSO:\n\tparentPath := echoCmd.Parent().CommandPath()\n\tdashParentPath := strings.ReplaceAll(parentPath, \" \", \"-\")\n\texpected := translate(dashParentPath)\n\texpected = expected + \"(\" + header.Section + \")\"\n\tcheckStringContains(t, output, expected)\n\n\tcheckStringContains(t, output, translate(echoCmd.Name()))\n\tcheckStringContains(t, output, translate(echoCmd.Name()))\n\tcheckStringContains(t, output, \"boolone\")\n\tcheckStringContains(t, output, \"rootflag\")\n\tcheckStringContains(t, output, translate(rootCmd.Name()))\n\tcheckStringContains(t, output, translate(echoSubCmd.Name()))\n\tcheckStringOmits(t, output, translate(deprecatedCmd.Name()))\n\tcheckStringContains(t, output, translate(\"Auto generated\"))\n}"} | |
| {"repo":"cobra","file":"doc/man_docs_test.go","line":69,"symbol":"TestGenManNoHiddenParents","kind":"function","lang":"go","code":"func TestGenManNoHiddenParents(t *testing.T) {\n\theader := &GenManHeader{\n\t\tTitle: \"Project\",\n\t\tSection: \"2\",\n\t}\n\n\t// We generate on a subcommand so we have both subcommands and parents\n\tfor _, name := range []string{\"rootflag\", \"strtwo\"} {\n\t\tf := rootCmd.PersistentFlags().Lookup(name)\n\t\tf.Hidden = true\n\t\tdefer func() { f.Hidden = false }()\n\t}\n\tbuf := new(bytes.Buffer)\n\tif err := GenMan(echoCmd, header, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\t// Make sure parent has - in CommandPath() in SEE ALSO:\n\tparentPath := echoCmd.Parent().CommandPath()\n\tdashParentPath := strings.ReplaceAll(parentPath, \" \", \"-\")\n\texpected := translate(dashParentPath)\n\texpected = expected + \"(\" + header.Section + \")\"\n\tcheckStringContains(t, output, expected)\n\n\tcheckStringContains(t, output, translate(echoCmd.Name()))\n\tcheckStringContains(t, output, translate(echoCmd.Name()))\n\tcheckStringContains(t, output, \"boolone\")\n\tcheckStringOmits(t, output, \"rootflag\")\n\tcheckStringContains(t, output, translate(rootCmd.Name()))\n\tcheckStringContains(t, output, translate(echoSubCmd.Name()))\n\tcheckStringOmits(t, output, translate(deprecatedCmd.Name()))\n\tcheckStringContains(t, output, translate(\"Auto ge"} | |
| {"repo":"cobra","file":"doc/man_docs_test.go","line":105,"symbol":"TestGenManNoGenTag","kind":"function","lang":"go","code":"func TestGenManNoGenTag(t *testing.T) {\n\techoCmd.DisableAutoGenTag = true\n\tdefer func() { echoCmd.DisableAutoGenTag = false }()\n\n\theader := &GenManHeader{\n\t\tTitle: \"Project\",\n\t\tSection: \"2\",\n\t}\n\n\t// We generate on a subcommand so we have both subcommands and parents\n\tbuf := new(bytes.Buffer)\n\tif err := GenMan(echoCmd, header, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\tunexpected := translate(\"#HISTORY\")\n\tcheckStringOmits(t, output, unexpected)\n\tunexpected = translate(\"Auto generated by spf13/cobra\")\n\tcheckStringOmits(t, output, unexpected)\n}"} | |
| {"repo":"cobra","file":"doc/man_docs_test.go","line":127,"symbol":"TestGenManSeeAlso","kind":"function","lang":"go","code":"func TestGenManSeeAlso(t *testing.T) {\n\trootCmd := &cobra.Command{Use: \"root\", Run: emptyRun}\n\taCmd := &cobra.Command{Use: \"aaa\", Run: emptyRun, Hidden: true} // #229\n\tbCmd := &cobra.Command{Use: \"bbb\", Run: emptyRun}\n\tcCmd := &cobra.Command{Use: \"ccc\", Run: emptyRun}\n\trootCmd.AddCommand(aCmd, bCmd, cCmd)\n\n\tbuf := new(bytes.Buffer)\n\theader := &GenManHeader{}\n\tif err := GenMan(rootCmd, header, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\tscanner := bufio.NewScanner(buf)\n\n\tif err := assertLineFound(scanner, \".SH SEE ALSO\"); err != nil {\n\t\tt.Fatalf(\"Couldn't find SEE ALSO section header: %v\", err)\n\t}\n\tif err := assertNextLineEquals(scanner, `\\fBroot-bbb(1)\\fP, \\fBroot-ccc(1)\\fP`); err != nil {\n\t\tt.Fatalf(\"Second line after SEE ALSO wasn't correct: %v\", err)\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/man_docs_test.go","line":149,"symbol":"TestManPrintFlagsHidesShortDeprecated","kind":"function","lang":"go","code":"func TestManPrintFlagsHidesShortDeprecated(t *testing.T) {\n\tc := &cobra.Command{}\n\tc.Flags().StringP(\"foo\", \"f\", \"default\", \"Foo flag\")\n\tassertNoErr(t, c.Flags().MarkShorthandDeprecated(\"foo\", \"don't use it no more\"))\n\n\tbuf := new(bytes.Buffer)\n\tmanPrintFlags(buf, c.Flags())\n\n\tgot := buf.String()\n\texpected := \"**--foo**=\\\"default\\\"\\n\\tFoo flag\\n\\n\"\n\tif got != expected {\n\t\tt.Errorf(\"Expected %v, got %v\", expected, got)\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/man_docs_test.go","line":164,"symbol":"TestGenManTree","kind":"function","lang":"go","code":"func TestGenManTree(t *testing.T) {\n\tc := &cobra.Command{Use: \"do [OPTIONS] arg1 arg2\"}\n\theader := &GenManHeader{Section: \"2\"}\n\ttmpdir, err := os.MkdirTemp(\"\", \"test-gen-man-tree\")\n\tif err != nil {\n\t\tt.Fatalf(\"Failed to create tmpdir: %s\", err.Error())\n\t}\n\tdefer os.RemoveAll(tmpdir)\n\n\tif err := GenManTree(c, header, tmpdir); err != nil {\n\t\tt.Fatalf(\"GenManTree failed: %s\", err.Error())\n\t}\n\n\tif _, err := os.Stat(filepath.Join(tmpdir, \"do.2\")); err != nil {\n\t\tt.Fatalf(\"Expected file 'do.2' to exist\")\n\t}\n\n\tif header.Title != \"\" {\n\t\tt.Fatalf(\"Expected header.Title to be unmodified\")\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/man_docs_test.go","line":186,"symbol":"assertLineFound","kind":"function","lang":"go","code":"func assertLineFound(scanner *bufio.Scanner, expectedLine string) error {\n\tfor scanner.Scan() {\n\t\tline := scanner.Text()\n\t\tif line == expectedLine {\n\t\t\treturn nil\n\t\t}\n\t}\n\n\tif err := scanner.Err(); err != nil {\n\t\treturn fmt.Errorf(\"scan failed: %s\", err)\n\t}\n\n\treturn fmt.Errorf(\"hit EOF before finding %v\", expectedLine)\n}"} | |
| {"repo":"cobra","file":"doc/man_docs_test.go","line":201,"symbol":"assertNextLineEquals","kind":"function","lang":"go","code":"func assertNextLineEquals(scanner *bufio.Scanner, expectedLine string) error {\n\tif scanner.Scan() {\n\t\tline := scanner.Text()\n\t\tif line == expectedLine {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"got %v, not %v\", line, expectedLine)\n\t}\n\n\tif err := scanner.Err(); err != nil {\n\t\treturn fmt.Errorf(\"scan failed: %v\", err)\n\t}\n\n\treturn fmt.Errorf(\"hit EOF before finding %v\", expectedLine)\n}"} | |
| {"repo":"cobra","file":"doc/man_docs_test.go","line":217,"symbol":"BenchmarkGenManToFile","kind":"function","lang":"go","code":"func BenchmarkGenManToFile(b *testing.B) {\n\tfile, err := os.CreateTemp(\"\", \"\")\n\tif err != nil {\n\t\tb.Fatal(err)\n\t}\n\tdefer os.Remove(file.Name())\n\tdefer file.Close()\n\n\tb.ResetTimer()\n\tfor i := 0; i < b.N; i++ {\n\t\tif err := GenMan(rootCmd, nil, file); err != nil {\n\t\t\tb.Fatal(err)\n\t\t}\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/man_examples_test.go","line":25,"symbol":"ExampleGenManTree","kind":"function","lang":"go","code":"func ExampleGenManTree() {\n\tcmd := &cobra.Command{\n\t\tUse: \"test\",\n\t\tShort: \"my test program\",\n\t}\n\theader := &doc.GenManHeader{\n\t\tTitle: \"MINE\",\n\t\tSection: \"3\",\n\t}\n\tcobra.CheckErr(doc.GenManTree(cmd, header, \"/tmp\"))\n}"} | |
| {"repo":"cobra","file":"doc/man_examples_test.go","line":37,"symbol":"ExampleGenMan","kind":"function","lang":"go","code":"func ExampleGenMan() {\n\tcmd := &cobra.Command{\n\t\tUse: \"test\",\n\t\tShort: \"my test program\",\n\t}\n\theader := &doc.GenManHeader{\n\t\tTitle: \"MINE\",\n\t\tSection: \"3\",\n\t}\n\tout := new(bytes.Buffer)\n\tcobra.CheckErr(doc.GenMan(cmd, header, out))\n\tfmt.Print(out.String())\n}"} | |
| {"repo":"cobra","file":"doc/md_docs.go","line":30,"symbol":"markdownExtension","kind":"constant","lang":"go","code":"markdownExtension = \".md\""} | |
| {"repo":"cobra","file":"doc/md_docs.go","line":32,"symbol":"printOptions","kind":"function","lang":"go","code":"func printOptions(buf *bytes.Buffer, cmd *cobra.Command, name string) error {\n\tflags := cmd.NonInheritedFlags()\n\tflags.SetOutput(buf)\n\tif flags.HasAvailableFlags() {\n\t\tbuf.WriteString(\"### Options\\n\\n```\\n\")\n\t\tflags.PrintDefaults()\n\t\tbuf.WriteString(\"```\\n\\n\")\n\t}\n\n\tparentFlags := cmd.InheritedFlags()\n\tparentFlags.SetOutput(buf)\n\tif parentFlags.HasAvailableFlags() {\n\t\tbuf.WriteString(\"### Options inherited from parent commands\\n\\n```\\n\")\n\t\tparentFlags.PrintDefaults()\n\t\tbuf.WriteString(\"```\\n\\n\")\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"doc/md_docs.go","line":52,"symbol":"GenMarkdown","kind":"function","lang":"go","doc":"GenMarkdown creates markdown output.","code":"func GenMarkdown(cmd *cobra.Command, w io.Writer) error {\n\treturn GenMarkdownCustom(cmd, w, func(s string) string { return s })\n}"} | |
| {"repo":"cobra","file":"doc/md_docs.go","line":57,"symbol":"GenMarkdownCustom","kind":"function","lang":"go","doc":"GenMarkdownCustom creates custom markdown output.","code":"func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {\n\tcmd.InitDefaultHelpCmd()\n\tcmd.InitDefaultHelpFlag()\n\n\tbuf := new(bytes.Buffer)\n\tname := cmd.CommandPath()\n\n\tbuf.WriteString(\"## \" + name + \"\\n\\n\")\n\tbuf.WriteString(cmd.Short + \"\\n\\n\")\n\tif len(cmd.Long) > 0 {\n\t\tbuf.WriteString(\"### Synopsis\\n\\n\")\n\t\tbuf.WriteString(cmd.Long + \"\\n\\n\")\n\t}\n\n\tif cmd.Runnable() {\n\t\tfmt.Fprintf(buf, \"```\\n%s\\n```\\n\\n\", cmd.UseLine())\n\t}\n\n\tif len(cmd.Example) > 0 {\n\t\tbuf.WriteString(\"### Examples\\n\\n\")\n\t\tfmt.Fprintf(buf, \"```\\n%s\\n```\\n\\n\", cmd.Example)\n\t}\n\n\tif err := printOptions(buf, cmd, name); err != nil {\n\t\treturn err\n\t}\n\tif hasSeeAlso(cmd) {\n\t\tbuf.WriteString(\"### SEE ALSO\\n\\n\")\n\t\tif cmd.HasParent() {\n\t\t\tparent := cmd.Parent()\n\t\t\tpname := parent.CommandPath()\n\t\t\tlink := pname + markdownExtension\n\t\t\tlink = strings.ReplaceAll(link, \" \", \"_\")\n\t\t\tfmt.Fprintf(buf, \"* [%s](%s)\\t - %s\\n\", pname, linkHandler(link), parent.Short)\n\t\t\tcmd.VisitParents(func(c *cobra.Command) {\n\t\t\t\tif c.DisableAutoGenTag {\n\t\t\t\t\tcmd.DisableAutoGenTag = c.DisableAutoGenTag\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\n\t\tchildren := cmd.Commands()\n\t\tsort.Sort(byName(children))\n\n\t\tfor _, child := range children {\n\t\t\t"} | |
| {"repo":"cobra","file":"doc/md_docs.go","line":125,"symbol":"GenMarkdownTree","kind":"function","lang":"go","doc":"GenMarkdownTree will generate a markdown page for this command and all descendants in the directory given. The header may be nil. This function may not work correctly if your command names have `-` in them. If you have `cmd` with two subcmds, `sub` and `sub-third`, and `sub` has a subcommand called `third`, it is undefined which help output will be in the file `cmd-sub-third.1`.","code":"func GenMarkdownTree(cmd *cobra.Command, dir string) error {\n\tidentity := func(s string) string { return s }\n\temptyStr := func(s string) string { return \"\" }\n\treturn GenMarkdownTreeCustom(cmd, dir, emptyStr, identity)\n}"} | |
| {"repo":"cobra","file":"doc/md_docs.go","line":133,"symbol":"GenMarkdownTreeCustom","kind":"function","lang":"go","doc":"GenMarkdownTreeCustom is the same as GenMarkdownTree, but with custom filePrepender and linkHandler.","code":"func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error {\n\tfor _, c := range cmd.Commands() {\n\t\tif !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {\n\t\t\tcontinue\n\t\t}\n\t\tif err := GenMarkdownTreeCustom(c, dir, filePrepender, linkHandler); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tbasename := strings.ReplaceAll(cmd.CommandPath(), \" \", \"_\") + markdownExtension\n\tfilename := filepath.Join(dir, basename)\n\tf, err := os.Create(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()\n\n\tif _, err := io.WriteString(f, filePrepender(filename)); err != nil {\n\t\treturn err\n\t}\n\tif err := GenMarkdownCustom(cmd, f, linkHandler); err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"doc/md_docs_test.go","line":26,"symbol":"TestGenMdDoc","kind":"function","lang":"go","code":"func TestGenMdDoc(t *testing.T) {\n\t// We generate on subcommand so we have both subcommands and parents.\n\tbuf := new(bytes.Buffer)\n\tif err := GenMarkdown(echoCmd, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\tcheckStringContains(t, output, echoCmd.Long)\n\tcheckStringContains(t, output, echoCmd.Example)\n\tcheckStringContains(t, output, \"boolone\")\n\tcheckStringContains(t, output, \"rootflag\")\n\tcheckStringContains(t, output, rootCmd.Short)\n\tcheckStringContains(t, output, echoSubCmd.Short)\n\tcheckStringOmits(t, output, deprecatedCmd.Short)\n\tcheckStringContains(t, output, \"Options inherited from parent commands\")\n}"} | |
| {"repo":"cobra","file":"doc/md_docs_test.go","line":44,"symbol":"TestGenMdDocWithNoLongOrSynopsis","kind":"function","lang":"go","code":"func TestGenMdDocWithNoLongOrSynopsis(t *testing.T) {\n\t// We generate on subcommand so we have both subcommands and parents.\n\tbuf := new(bytes.Buffer)\n\tif err := GenMarkdown(dummyCmd, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\tcheckStringContains(t, output, dummyCmd.Example)\n\tcheckStringContains(t, output, dummyCmd.Short)\n\tcheckStringContains(t, output, \"Options inherited from parent commands\")\n\tcheckStringOmits(t, output, \"### Synopsis\")\n}"} | |
| {"repo":"cobra","file":"doc/md_docs_test.go","line":58,"symbol":"TestGenMdNoHiddenParents","kind":"function","lang":"go","code":"func TestGenMdNoHiddenParents(t *testing.T) {\n\t// We generate on subcommand so we have both subcommands and parents.\n\tfor _, name := range []string{\"rootflag\", \"strtwo\"} {\n\t\tf := rootCmd.PersistentFlags().Lookup(name)\n\t\tf.Hidden = true\n\t\tdefer func() { f.Hidden = false }()\n\t}\n\tbuf := new(bytes.Buffer)\n\tif err := GenMarkdown(echoCmd, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\tcheckStringContains(t, output, echoCmd.Long)\n\tcheckStringContains(t, output, echoCmd.Example)\n\tcheckStringContains(t, output, \"boolone\")\n\tcheckStringOmits(t, output, \"rootflag\")\n\tcheckStringContains(t, output, rootCmd.Short)\n\tcheckStringContains(t, output, echoSubCmd.Short)\n\tcheckStringOmits(t, output, deprecatedCmd.Short)\n\tcheckStringOmits(t, output, \"Options inherited from parent commands\")\n}"} | |
| {"repo":"cobra","file":"doc/md_docs_test.go","line":81,"symbol":"TestGenMdNoTag","kind":"function","lang":"go","code":"func TestGenMdNoTag(t *testing.T) {\n\trootCmd.DisableAutoGenTag = true\n\tdefer func() { rootCmd.DisableAutoGenTag = false }()\n\n\tbuf := new(bytes.Buffer)\n\tif err := GenMarkdown(rootCmd, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\tcheckStringOmits(t, output, \"Auto generated\")\n}"} | |
| {"repo":"cobra","file":"doc/md_docs_test.go","line":94,"symbol":"TestGenMdTree","kind":"function","lang":"go","code":"func TestGenMdTree(t *testing.T) {\n\tc := &cobra.Command{Use: \"do [OPTIONS] arg1 arg2\"}\n\ttmpdir, err := os.MkdirTemp(\"\", \"test-gen-md-tree\")\n\tif err != nil {\n\t\tt.Fatalf(\"Failed to create tmpdir: %v\", err)\n\t}\n\tdefer os.RemoveAll(tmpdir)\n\n\tif err := GenMarkdownTree(c, tmpdir); err != nil {\n\t\tt.Fatalf(\"GenMarkdownTree failed: %v\", err)\n\t}\n\n\tif _, err := os.Stat(filepath.Join(tmpdir, \"do.md\")); err != nil {\n\t\tt.Fatalf(\"Expected file 'do.md' to exist\")\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/md_docs_test.go","line":111,"symbol":"BenchmarkGenMarkdownToFile","kind":"function","lang":"go","code":"func BenchmarkGenMarkdownToFile(b *testing.B) {\n\tfile, err := os.CreateTemp(\"\", \"\")\n\tif err != nil {\n\t\tb.Fatal(err)\n\t}\n\tdefer os.Remove(file.Name())\n\tdefer file.Close()\n\n\tb.ResetTimer()\n\tfor i := 0; i < b.N; i++ {\n\t\tif err := GenMarkdown(rootCmd, file); err != nil {\n\t\t\tb.Fatal(err)\n\t\t}\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/rest_docs.go","line":30,"symbol":"printOptionsReST","kind":"function","lang":"go","code":"func printOptionsReST(buf *bytes.Buffer, cmd *cobra.Command, name string) error {\n\tflags := cmd.NonInheritedFlags()\n\tflags.SetOutput(buf)\n\tif flags.HasAvailableFlags() {\n\t\tbuf.WriteString(\"Options\\n\")\n\t\tbuf.WriteString(\"~~~~~~~\\n\\n::\\n\\n\")\n\t\tflags.PrintDefaults()\n\t\tbuf.WriteString(\"\\n\")\n\t}\n\n\tparentFlags := cmd.InheritedFlags()\n\tparentFlags.SetOutput(buf)\n\tif parentFlags.HasAvailableFlags() {\n\t\tbuf.WriteString(\"Options inherited from parent commands\\n\")\n\t\tbuf.WriteString(\"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\n\\n::\\n\\n\")\n\t\tparentFlags.PrintDefaults()\n\t\tbuf.WriteString(\"\\n\")\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"doc/rest_docs.go","line":52,"symbol":"defaultLinkHandler","kind":"function","lang":"go","doc":"defaultLinkHandler for default ReST hyperlink markup","code":"func defaultLinkHandler(name, ref string) string {\n\treturn fmt.Sprintf(\"`%s <%s.rst>`_\", name, ref)\n}"} | |
| {"repo":"cobra","file":"doc/rest_docs.go","line":57,"symbol":"GenReST","kind":"function","lang":"go","doc":"GenReST creates reStructured Text output.","code":"func GenReST(cmd *cobra.Command, w io.Writer) error {\n\treturn GenReSTCustom(cmd, w, defaultLinkHandler)\n}"} | |
| {"repo":"cobra","file":"doc/rest_docs.go","line":62,"symbol":"GenReSTCustom","kind":"function","lang":"go","doc":"GenReSTCustom creates custom reStructured Text output.","code":"func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, string) string) error {\n\tcmd.InitDefaultHelpCmd()\n\tcmd.InitDefaultHelpFlag()\n\n\tbuf := new(bytes.Buffer)\n\tname := cmd.CommandPath()\n\n\tshort := cmd.Short\n\tlong := cmd.Long\n\tif len(long) == 0 {\n\t\tlong = short\n\t}\n\tref := strings.ReplaceAll(name, \" \", \"_\")\n\n\tbuf.WriteString(\".. _\" + ref + \":\\n\\n\")\n\tbuf.WriteString(name + \"\\n\")\n\tbuf.WriteString(strings.Repeat(\"-\", len(name)) + \"\\n\\n\")\n\tbuf.WriteString(short + \"\\n\\n\")\n\tbuf.WriteString(\"Synopsis\\n\")\n\tbuf.WriteString(\"~~~~~~~~\\n\\n\")\n\tbuf.WriteString(\"\\n\" + long + \"\\n\\n\")\n\n\tif cmd.Runnable() {\n\t\tfmt.Fprintf(buf, \"::\\n\\n %s\\n\\n\", cmd.UseLine())\n\t}\n\n\tif len(cmd.Example) > 0 {\n\t\tbuf.WriteString(\"Examples\\n\")\n\t\tbuf.WriteString(\"~~~~~~~~\\n\\n\")\n\t\tfmt.Fprintf(buf, \"::\\n\\n%s\\n\\n\", indentString(cmd.Example, \" \"))\n\t}\n\n\tif err := printOptionsReST(buf, cmd, name); err != nil {\n\t\treturn err\n\t}\n\tif hasSeeAlso(cmd) {\n\t\tbuf.WriteString(\"SEE ALSO\\n\")\n\t\tbuf.WriteString(\"~~~~~~~~\\n\\n\")\n\t\tif cmd.HasParent() {\n\t\t\tparent := cmd.Parent()\n\t\t\tpname := parent.CommandPath()\n\t\t\tref = strings.ReplaceAll(pname, \" \", \"_\")\n\t\t\tfmt.Fprintf(buf, \"* %s \\t - %s\\n\", linkHandler(pname, ref), parent.Sho"} | |
| {"repo":"cobra","file":"doc/rest_docs.go","line":138,"symbol":"GenReSTTree","kind":"function","lang":"go","doc":"GenReSTTree will generate a ReST page for this command and all descendants in the directory given. This function may not work correctly if your command names have `-` in them. If you have `cmd` with two subcmds, `sub` and `sub-third`, and `sub` has a subcommand called `third`, it is undefined which help output will be in the file `cmd-sub-third.1`.","code":"func GenReSTTree(cmd *cobra.Command, dir string) error {\n\temptyStr := func(s string) string { return \"\" }\n\treturn GenReSTTreeCustom(cmd, dir, emptyStr, defaultLinkHandler)\n}"} | |
| {"repo":"cobra","file":"doc/rest_docs.go","line":145,"symbol":"GenReSTTreeCustom","kind":"function","lang":"go","doc":"GenReSTTreeCustom is the same as GenReSTTree, but with custom filePrepender and linkHandler.","code":"func GenReSTTreeCustom(cmd *cobra.Command, dir string, filePrepender func(string) string, linkHandler func(string, string) string) error {\n\tfor _, c := range cmd.Commands() {\n\t\tif !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {\n\t\t\tcontinue\n\t\t}\n\t\tif err := GenReSTTreeCustom(c, dir, filePrepender, linkHandler); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tbasename := strings.ReplaceAll(cmd.CommandPath(), \" \", \"_\") + \".rst\"\n\tfilename := filepath.Join(dir, basename)\n\tf, err := os.Create(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()\n\n\tif _, err := io.WriteString(f, filePrepender(filename)); err != nil {\n\t\treturn err\n\t}\n\tif err := GenReSTCustom(cmd, f, linkHandler); err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"doc/rest_docs.go","line":173,"symbol":"indentString","kind":"function","lang":"go","doc":"indentString adapted from: https://github.com/kr/text/blob/main/indent.go","code":"func indentString(s, p string) string {\n\tvar res []byte\n\tb := []byte(s)\n\tprefix := []byte(p)\n\tbol := true\n\tfor _, c := range b {\n\t\tif bol && c != '\\n' {\n\t\t\tres = append(res, prefix...)\n\t\t}\n\t\tres = append(res, c)\n\t\tbol = c == '\\n'\n\t}\n\treturn string(res)\n}"} | |
| {"repo":"cobra","file":"doc/rest_docs.go","line":174,"symbol":"res","kind":"variable","lang":"go","code":"res []byte"} | |
| {"repo":"cobra","file":"doc/rest_docs_test.go","line":26,"symbol":"TestGenRSTDoc","kind":"function","lang":"go","code":"func TestGenRSTDoc(t *testing.T) {\n\t// We generate on a subcommand so we have both subcommands and parents\n\tbuf := new(bytes.Buffer)\n\tif err := GenReST(echoCmd, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\tcheckStringContains(t, output, echoCmd.Long)\n\tcheckStringContains(t, output, echoCmd.Example)\n\tcheckStringContains(t, output, \"boolone\")\n\tcheckStringContains(t, output, \"rootflag\")\n\tcheckStringContains(t, output, rootCmd.Short)\n\tcheckStringContains(t, output, echoSubCmd.Short)\n\tcheckStringOmits(t, output, deprecatedCmd.Short)\n}"} | |
| {"repo":"cobra","file":"doc/rest_docs_test.go","line":43,"symbol":"TestGenRSTNoHiddenParents","kind":"function","lang":"go","code":"func TestGenRSTNoHiddenParents(t *testing.T) {\n\t// We generate on a subcommand so we have both subcommands and parents\n\tfor _, name := range []string{\"rootflag\", \"strtwo\"} {\n\t\tf := rootCmd.PersistentFlags().Lookup(name)\n\t\tf.Hidden = true\n\t\tdefer func() { f.Hidden = false }()\n\t}\n\tbuf := new(bytes.Buffer)\n\tif err := GenReST(echoCmd, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\tcheckStringContains(t, output, echoCmd.Long)\n\tcheckStringContains(t, output, echoCmd.Example)\n\tcheckStringContains(t, output, \"boolone\")\n\tcheckStringOmits(t, output, \"rootflag\")\n\tcheckStringContains(t, output, rootCmd.Short)\n\tcheckStringContains(t, output, echoSubCmd.Short)\n\tcheckStringOmits(t, output, deprecatedCmd.Short)\n\tcheckStringOmits(t, output, \"Options inherited from parent commands\")\n}"} | |
| {"repo":"cobra","file":"doc/rest_docs_test.go","line":66,"symbol":"TestGenRSTNoTag","kind":"function","lang":"go","code":"func TestGenRSTNoTag(t *testing.T) {\n\trootCmd.DisableAutoGenTag = true\n\tdefer func() { rootCmd.DisableAutoGenTag = false }()\n\n\tbuf := new(bytes.Buffer)\n\tif err := GenReST(rootCmd, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\tunexpected := \"Auto generated\"\n\tcheckStringOmits(t, output, unexpected)\n}"} | |
| {"repo":"cobra","file":"doc/rest_docs_test.go","line":80,"symbol":"TestGenRSTTree","kind":"function","lang":"go","code":"func TestGenRSTTree(t *testing.T) {\n\tc := &cobra.Command{Use: \"do [OPTIONS] arg1 arg2\"}\n\n\ttmpdir, err := os.MkdirTemp(\"\", \"test-gen-rst-tree\")\n\tif err != nil {\n\t\tt.Fatalf(\"Failed to create tmpdir: %s\", err.Error())\n\t}\n\tdefer os.RemoveAll(tmpdir)\n\n\tif err := GenReSTTree(c, tmpdir); err != nil {\n\t\tt.Fatalf(\"GenReSTTree failed: %s\", err.Error())\n\t}\n\n\tif _, err := os.Stat(filepath.Join(tmpdir, \"do.rst\")); err != nil {\n\t\tt.Fatalf(\"Expected file 'do.rst' to exist\")\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/rest_docs_test.go","line":98,"symbol":"BenchmarkGenReSTToFile","kind":"function","lang":"go","code":"func BenchmarkGenReSTToFile(b *testing.B) {\n\tfile, err := os.CreateTemp(\"\", \"\")\n\tif err != nil {\n\t\tb.Fatal(err)\n\t}\n\tdefer os.Remove(file.Name())\n\tdefer file.Close()\n\n\tb.ResetTimer()\n\tfor i := 0; i < b.N; i++ {\n\t\tif err := GenReST(rootCmd, file); err != nil {\n\t\t\tb.Fatal(err)\n\t\t}\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/util.go","line":26,"symbol":"hasSeeAlso","kind":"function","lang":"go","doc":"Test to see if we have a reason to print See Also information in docs Basically this is a test for a parent command or a subcommand which is both not deprecated and not the autogenerated help command.","code":"func hasSeeAlso(cmd *cobra.Command) bool {\n\tif cmd.HasParent() {\n\t\treturn true\n\t}\n\tfor _, c := range cmd.Commands() {\n\t\tif !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {\n\t\t\tcontinue\n\t\t}\n\t\treturn true\n\t}\n\treturn false\n}"} | |
| {"repo":"cobra","file":"doc/util.go","line":41,"symbol":"forceMultiLine","kind":"function","lang":"go","doc":"Temporary workaround for yaml lib generating incorrect yaml with long strings that do not contain \\n.","code":"func forceMultiLine(s string) string {\n\tif len(s) > 60 && !strings.Contains(s, \"\\n\") {\n\t\ts += \"\\n\"\n\t}\n\treturn s\n}"} | |
| {"repo":"cobra","file":"doc/util.go","line":48,"symbol":"byName","kind":"type","lang":"go","code":"type byName []*cobra.Command"} | |
| {"repo":"cobra","file":"doc/util.go","line":50,"symbol":"Len","kind":"method","lang":"go","code":"func (s byName) Len() int { return len(s) }"} | |
| {"repo":"cobra","file":"doc/util.go","line":51,"symbol":"Swap","kind":"method","lang":"go","code":"func (s byName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }"} | |
| {"repo":"cobra","file":"doc/util.go","line":52,"symbol":"Less","kind":"method","lang":"go","code":"func (s byName) Less(i, j int) bool { return s[i].Name() < s[j].Name() }"} | |
| {"repo":"cobra","file":"doc/yaml_docs.go","line":30,"symbol":"cmdOption","kind":"type","lang":"go","code":"type cmdOption struct {\n\tName string\n\tShorthand string `yaml:\",omitempty\"`\n\tDefaultValue string `yaml:\"default_value,omitempty\"`\n\tUsage string `yaml:\",omitempty\"`\n}"} | |
| {"repo":"cobra","file":"doc/yaml_docs.go","line":37,"symbol":"cmdDoc","kind":"type","lang":"go","code":"type cmdDoc struct {\n\tName string\n\tSynopsis string `yaml:\",omitempty\"`\n\tDescription string `yaml:\",omitempty\"`\n\tUsage string `yaml:\",omitempty\"`\n\tOptions []cmdOption `yaml:\",omitempty\"`\n\tInheritedOptions []cmdOption `yaml:\"inherited_options,omitempty\"`\n\tExample string `yaml:\",omitempty\"`\n\tSeeAlso []string `yaml:\"see_also,omitempty\"`\n}"} | |
| {"repo":"cobra","file":"doc/yaml_docs.go","line":53,"symbol":"GenYamlTree","kind":"function","lang":"go","doc":"GenYamlTree creates yaml structured ref files for this command and all descendants in the directory given. This function may not work correctly if your command names have `-` in them. If you have `cmd` with two subcmds, `sub` and `sub-third`, and `sub` has a subcommand called `third` it is undefined which help output will be in the file `cmd-sub-third.1`.","code":"func GenYamlTree(cmd *cobra.Command, dir string) error {\n\tidentity := func(s string) string { return s }\n\temptyStr := func(s string) string { return \"\" }\n\treturn GenYamlTreeCustom(cmd, dir, emptyStr, identity)\n}"} | |
| {"repo":"cobra","file":"doc/yaml_docs.go","line":60,"symbol":"GenYamlTreeCustom","kind":"function","lang":"go","doc":"GenYamlTreeCustom creates yaml structured ref files.","code":"func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error {\n\tfor _, c := range cmd.Commands() {\n\t\tif !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {\n\t\t\tcontinue\n\t\t}\n\t\tif err := GenYamlTreeCustom(c, dir, filePrepender, linkHandler); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tbasename := strings.ReplaceAll(cmd.CommandPath(), \" \", \"_\") + \".yaml\"\n\tfilename := filepath.Join(dir, basename)\n\tf, err := os.Create(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()\n\n\tif _, err := io.WriteString(f, filePrepender(filename)); err != nil {\n\t\treturn err\n\t}\n\tif err := GenYamlCustom(cmd, f, linkHandler); err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"doc/yaml_docs.go","line":88,"symbol":"GenYaml","kind":"function","lang":"go","doc":"GenYaml creates yaml output.","code":"func GenYaml(cmd *cobra.Command, w io.Writer) error {\n\treturn GenYamlCustom(cmd, w, func(s string) string { return s })\n}"} | |
| {"repo":"cobra","file":"doc/yaml_docs.go","line":93,"symbol":"GenYamlCustom","kind":"function","lang":"go","doc":"GenYamlCustom creates custom yaml output.","code":"func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error {\n\tcmd.InitDefaultHelpCmd()\n\tcmd.InitDefaultHelpFlag()\n\n\tyamlDoc := cmdDoc{}\n\tyamlDoc.Name = cmd.CommandPath()\n\n\tyamlDoc.Synopsis = forceMultiLine(cmd.Short)\n\tyamlDoc.Description = forceMultiLine(cmd.Long)\n\n\tif cmd.Runnable() {\n\t\tyamlDoc.Usage = cmd.UseLine()\n\t}\n\n\tif len(cmd.Example) > 0 {\n\t\tyamlDoc.Example = cmd.Example\n\t}\n\n\tflags := cmd.NonInheritedFlags()\n\tif flags.HasFlags() {\n\t\tyamlDoc.Options = genFlagResult(flags)\n\t}\n\tflags = cmd.InheritedFlags()\n\tif flags.HasFlags() {\n\t\tyamlDoc.InheritedOptions = genFlagResult(flags)\n\t}\n\n\tif hasSeeAlso(cmd) {\n\t\tresult := []string{}\n\t\tif cmd.HasParent() {\n\t\t\tparent := cmd.Parent()\n\t\t\tresult = append(result, parent.CommandPath()+\" - \"+parent.Short)\n\t\t}\n\t\tchildren := cmd.Commands()\n\t\tsort.Sort(byName(children))\n\t\tfor _, child := range children {\n\t\t\tif !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tresult = append(result, child.CommandPath()+\" - \"+child.Short)\n\t\t}\n\t\tyamlDoc.SeeAlso = result\n\t}\n\n\tfinal, err := yaml.Marshal(&yamlDoc)\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n\n\tif _, err := w.Write(final)"} | |
| {"repo":"cobra","file":"doc/yaml_docs.go","line":149,"symbol":"genFlagResult","kind":"function","lang":"go","code":"func genFlagResult(flags *pflag.FlagSet) []cmdOption {\n\tvar result []cmdOption\n\n\tflags.VisitAll(func(flag *pflag.Flag) {\n\t\t// Todo, when we mark a shorthand is deprecated, but specify an empty message.\n\t\t// The flag.ShorthandDeprecated is empty as the shorthand is deprecated.\n\t\t// Using len(flag.ShorthandDeprecated) > 0 can't handle this, others are ok.\n\t\tif len(flag.ShorthandDeprecated) == 0 && len(flag.Shorthand) > 0 {\n\t\t\topt := cmdOption{\n\t\t\t\tflag.Name,\n\t\t\t\tflag.Shorthand,\n\t\t\t\tflag.DefValue,\n\t\t\t\tforceMultiLine(flag.Usage),\n\t\t\t}\n\t\t\tresult = append(result, opt)\n\t\t} else {\n\t\t\topt := cmdOption{\n\t\t\t\tName: flag.Name,\n\t\t\t\tDefaultValue: forceMultiLine(flag.DefValue),\n\t\t\t\tUsage: forceMultiLine(flag.Usage),\n\t\t\t}\n\t\t\tresult = append(result, opt)\n\t\t}\n\t})\n\n\treturn result\n}"} | |
| {"repo":"cobra","file":"doc/yaml_docs.go","line":150,"symbol":"result","kind":"variable","lang":"go","code":"result []cmdOption"} | |
| {"repo":"cobra","file":"doc/yaml_docs_test.go","line":27,"symbol":"TestGenYamlDoc","kind":"function","lang":"go","code":"func TestGenYamlDoc(t *testing.T) {\n\t// We generate on s subcommand so we have both subcommands and parents\n\tbuf := new(bytes.Buffer)\n\tif err := GenYaml(echoCmd, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\tcheckStringContains(t, output, echoCmd.Long)\n\tcheckStringContains(t, output, echoCmd.Example)\n\tcheckStringContains(t, output, \"boolone\")\n\tcheckStringContains(t, output, \"rootflag\")\n\tcheckStringContains(t, output, rootCmd.Short)\n\tcheckStringContains(t, output, echoSubCmd.Short)\n\tcheckStringContains(t, output, fmt.Sprintf(\"- %s - %s\", echoSubCmd.CommandPath(), echoSubCmd.Short))\n}"} | |
| {"repo":"cobra","file":"doc/yaml_docs_test.go","line":44,"symbol":"TestGenYamlNoTag","kind":"function","lang":"go","code":"func TestGenYamlNoTag(t *testing.T) {\n\trootCmd.DisableAutoGenTag = true\n\tdefer func() { rootCmd.DisableAutoGenTag = false }()\n\n\tbuf := new(bytes.Buffer)\n\tif err := GenYaml(rootCmd, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\tcheckStringOmits(t, output, \"Auto generated\")\n}"} | |
| {"repo":"cobra","file":"doc/yaml_docs_test.go","line":57,"symbol":"TestGenYamlTree","kind":"function","lang":"go","code":"func TestGenYamlTree(t *testing.T) {\n\tc := &cobra.Command{Use: \"do [OPTIONS] arg1 arg2\"}\n\n\ttmpdir, err := os.MkdirTemp(\"\", \"test-gen-yaml-tree\")\n\tif err != nil {\n\t\tt.Fatalf(\"Failed to create tmpdir: %s\", err.Error())\n\t}\n\tdefer os.RemoveAll(tmpdir)\n\n\tif err := GenYamlTree(c, tmpdir); err != nil {\n\t\tt.Fatalf(\"GenYamlTree failed: %s\", err.Error())\n\t}\n\n\tif _, err := os.Stat(filepath.Join(tmpdir, \"do.yaml\")); err != nil {\n\t\tt.Fatalf(\"Expected file 'do.yaml' to exist\")\n\t}\n}"} | |
| {"repo":"cobra","file":"doc/yaml_docs_test.go","line":75,"symbol":"TestGenYamlDocRunnable","kind":"function","lang":"go","code":"func TestGenYamlDocRunnable(t *testing.T) {\n\t// Testing a runnable command: should contain the \"usage\" field\n\tbuf := new(bytes.Buffer)\n\tif err := GenYaml(rootCmd, buf); err != nil {\n\t\tt.Fatal(err)\n\t}\n\toutput := buf.String()\n\n\tcheckStringContains(t, output, \"usage: \"+rootCmd.Use)\n}"} | |
| {"repo":"cobra","file":"doc/yaml_docs_test.go","line":86,"symbol":"BenchmarkGenYamlToFile","kind":"function","lang":"go","code":"func BenchmarkGenYamlToFile(b *testing.B) {\n\tfile, err := os.CreateTemp(\"\", \"\")\n\tif err != nil {\n\t\tb.Fatal(err)\n\t}\n\tdefer os.Remove(file.Name())\n\tdefer file.Close()\n\n\tb.ResetTimer()\n\tfor i := 0; i < b.N; i++ {\n\t\tif err := GenYaml(rootCmd, file); err != nil {\n\t\t\tb.Fatal(err)\n\t\t}\n\t}\n}"} | |
| {"repo":"cobra","file":"fish_completions.go","line":25,"symbol":"genFishComp","kind":"function","lang":"go","code":"func genFishComp(buf io.StringWriter, name string, includeDesc bool) {\n\t// Variables should not contain a '-' or ':' character\n\tnameForVar := name\n\tnameForVar = strings.ReplaceAll(nameForVar, \"-\", \"_\")\n\tnameForVar = strings.ReplaceAll(nameForVar, \":\", \"_\")\n\n\tcompCmd := ShellCompRequestCmd\n\tif !includeDesc {\n\t\tcompCmd = ShellCompNoDescRequestCmd\n\t}\n\tWriteStringAndCheck(buf, fmt.Sprintf(\"# fish completion for %-36s -*- shell-script -*-\\n\", name))\n\tWriteStringAndCheck(buf, fmt.Sprintf(`\nfunction __%[1]s_debug\n set -l file \"$BASH_COMP_DEBUG_FILE\"\n if test -n \"$file\"\n echo \"$argv\" >> $file\n end\nend\n\nfunction __%[1]s_perform_completion\n __%[1]s_debug \"Starting __%[1]s_perform_completion\"\n\n # Extract all args except the last one\n set -l args (commandline -opc)\n # Extract the last arg and escape it in case it is a space or wildcard\n set -l lastArg (string escape -- (commandline -ct))\n\n __%[1]s_debug \"args: $args\"\n __%[1]s_debug \"last arg: $lastArg\"\n\n # Disable ActiveHelp which is not supported for fish shell\n set -l requestComp \"%[10]s=0 $args[1] %[3]s $(string join ' ' -- (string escape -- $args[2..-1])) $lastArg\"\n\n __%[1]s_debug \"Calling $req"} | |
| {"repo":"cobra","file":"fish_completions.go","line":276,"symbol":"GenFishCompletion","kind":"method","lang":"go","doc":"GenFishCompletion generates fish completion file and writes to the passed writer.","code":"func (c *Command) GenFishCompletion(w io.Writer, includeDesc bool) error {\n\tbuf := new(bytes.Buffer)\n\tgenFishComp(buf, c.Name(), includeDesc)\n\t_, err := buf.WriteTo(w)\n\treturn err\n}"} | |
| {"repo":"cobra","file":"fish_completions.go","line":284,"symbol":"GenFishCompletionFile","kind":"method","lang":"go","doc":"GenFishCompletionFile generates fish completion file.","code":"func (c *Command) GenFishCompletionFile(filename string, includeDesc bool) error {\n\toutFile, err := os.Create(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer outFile.Close()\n\n\treturn c.GenFishCompletion(outFile, includeDesc)\n}"} | |
| {"repo":"cobra","file":"fish_completions_test.go","line":26,"symbol":"TestCompleteNoDesCmdInFishScript","kind":"function","lang":"go","code":"func TestCompleteNoDesCmdInFishScript(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild := &Command{\n\t\tUse: \"child\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child)\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, rootCmd.GenFishCompletion(buf, false))\n\toutput := buf.String()\n\n\tcheck(t, output, ShellCompNoDescRequestCmd)\n}"} | |
| {"repo":"cobra","file":"fish_completions_test.go","line":42,"symbol":"TestCompleteCmdInFishScript","kind":"function","lang":"go","code":"func TestCompleteCmdInFishScript(t *testing.T) {\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild := &Command{\n\t\tUse: \"child\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child)\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, rootCmd.GenFishCompletion(buf, true))\n\toutput := buf.String()\n\n\tcheck(t, output, ShellCompRequestCmd)\n\tcheckOmit(t, output, ShellCompNoDescRequestCmd)\n}"} | |
| {"repo":"cobra","file":"fish_completions_test.go","line":59,"symbol":"TestProgWithDash","kind":"function","lang":"go","code":"func TestProgWithDash(t *testing.T) {\n\trootCmd := &Command{Use: \"root-dash\", Args: NoArgs, Run: emptyRun}\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, rootCmd.GenFishCompletion(buf, false))\n\toutput := buf.String()\n\n\t// Functions name should have replace the '-'\n\tcheck(t, output, \"__root_dash_perform_completion\")\n\tcheckOmit(t, output, \"__root-dash_perform_completion\")\n\n\t// The command name should not have replaced the '-'\n\tcheck(t, output, \"-c root-dash\")\n\tcheckOmit(t, output, \"-c root_dash\")\n}"} | |
| {"repo":"cobra","file":"fish_completions_test.go","line":74,"symbol":"TestProgWithColon","kind":"function","lang":"go","code":"func TestProgWithColon(t *testing.T) {\n\trootCmd := &Command{Use: \"root:colon\", Args: NoArgs, Run: emptyRun}\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, rootCmd.GenFishCompletion(buf, false))\n\toutput := buf.String()\n\n\t// Functions name should have replace the ':'\n\tcheck(t, output, \"__root_colon_perform_completion\")\n\tcheckOmit(t, output, \"__root:colon_perform_completion\")\n\n\t// The command name should not have replaced the ':'\n\tcheck(t, output, \"-c root:colon\")\n\tcheckOmit(t, output, \"-c root_colon\")\n}"} | |
| {"repo":"cobra","file":"fish_completions_test.go","line":89,"symbol":"TestFishCompletionNoActiveHelp","kind":"function","lang":"go","code":"func TestFishCompletionNoActiveHelp(t *testing.T) {\n\tc := &Command{Use: \"c\", Run: emptyRun}\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, c.GenFishCompletion(buf, true))\n\toutput := buf.String()\n\n\t// check that active help is being disabled\n\tactiveHelpVar := activeHelpEnvVar(c.Name())\n\tcheck(t, output, fmt.Sprintf(\"%s=0\", activeHelpVar))\n}"} | |
| {"repo":"cobra","file":"fish_completions_test.go","line":101,"symbol":"TestGenFishCompletionFile","kind":"function","lang":"go","code":"func TestGenFishCompletionFile(t *testing.T) {\n\ttmpFile, err := os.CreateTemp(\"\", \"cobra-test\")\n\tif err != nil {\n\t\tt.Fatal(err.Error())\n\t}\n\n\tdefer os.Remove(tmpFile.Name())\n\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild := &Command{\n\t\tUse: \"child\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child)\n\n\tassertNoErr(t, rootCmd.GenFishCompletionFile(tmpFile.Name(), false))\n}"} | |
| {"repo":"cobra","file":"fish_completions_test.go","line":120,"symbol":"TestFailGenFishCompletionFile","kind":"function","lang":"go","code":"func TestFailGenFishCompletionFile(t *testing.T) {\n\ttmpDir, err := os.MkdirTemp(\"\", \"cobra-test\")\n\tif err != nil {\n\t\tt.Fatal(err.Error())\n\t}\n\n\tdefer os.RemoveAll(tmpDir)\n\n\tf, _ := os.OpenFile(filepath.Join(tmpDir, \"test\"), os.O_CREATE, 0400)\n\tdefer f.Close()\n\n\trootCmd := &Command{Use: \"root\", Args: NoArgs, Run: emptyRun}\n\tchild := &Command{\n\t\tUse: \"child\",\n\t\tValidArgsFunction: validArgsFunc,\n\t\tRun: emptyRun,\n\t}\n\trootCmd.AddCommand(child)\n\n\tgot := rootCmd.GenFishCompletionFile(f.Name(), false)\n\tif !errors.Is(got, os.ErrPermission) {\n\t\tt.Errorf(\"got: %s, want: %s\", got.Error(), os.ErrPermission.Error())\n\t}\n}"} | |
| {"repo":"cobra","file":"flag_groups.go","line":26,"symbol":"requiredAsGroupAnnotation","kind":"constant","lang":"go","code":"requiredAsGroupAnnotation = \"cobra_annotation_required_if_others_set\""} | |
| {"repo":"cobra","file":"flag_groups.go","line":27,"symbol":"oneRequiredAnnotation","kind":"constant","lang":"go","code":"oneRequiredAnnotation = \"cobra_annotation_one_required\""} | |
| {"repo":"cobra","file":"flag_groups.go","line":28,"symbol":"mutuallyExclusiveAnnotation","kind":"constant","lang":"go","code":"mutuallyExclusiveAnnotation = \"cobra_annotation_mutually_exclusive\""} | |
| {"repo":"cobra","file":"flag_groups.go","line":33,"symbol":"MarkFlagsRequiredTogether","kind":"method","lang":"go","doc":"MarkFlagsRequiredTogether marks the given flags with annotations so that Cobra errors if the command is invoked with a subset (but not all) of the given flags.","code":"func (c *Command) MarkFlagsRequiredTogether(flagNames ...string) {\n\tc.mergePersistentFlags()\n\tfor _, v := range flagNames {\n\t\tf := c.Flags().Lookup(v)\n\t\tif f == nil {\n\t\t\tpanic(fmt.Sprintf(\"Failed to find flag %q and mark it as being required in a flag group\", v))\n\t\t}\n\t\tif err := c.Flags().SetAnnotation(v, requiredAsGroupAnnotation, append(f.Annotations[requiredAsGroupAnnotation], strings.Join(flagNames, \" \"))); err != nil {\n\t\t\t// Only errs if the flag isn't found.\n\t\t\tpanic(err)\n\t\t}\n\t}\n}"} | |
| {"repo":"cobra","file":"flag_groups.go","line":49,"symbol":"MarkFlagsOneRequired","kind":"method","lang":"go","doc":"MarkFlagsOneRequired marks the given flags with annotations so that Cobra errors if the command is invoked without at least one flag from the given set of flags.","code":"func (c *Command) MarkFlagsOneRequired(flagNames ...string) {\n\tc.mergePersistentFlags()\n\tfor _, v := range flagNames {\n\t\tf := c.Flags().Lookup(v)\n\t\tif f == nil {\n\t\t\tpanic(fmt.Sprintf(\"Failed to find flag %q and mark it as being in a one-required flag group\", v))\n\t\t}\n\t\tif err := c.Flags().SetAnnotation(v, oneRequiredAnnotation, append(f.Annotations[oneRequiredAnnotation], strings.Join(flagNames, \" \"))); err != nil {\n\t\t\t// Only errs if the flag isn't found.\n\t\t\tpanic(err)\n\t\t}\n\t}\n}"} | |
| {"repo":"cobra","file":"flag_groups.go","line":65,"symbol":"MarkFlagsMutuallyExclusive","kind":"method","lang":"go","doc":"MarkFlagsMutuallyExclusive marks the given flags with annotations so that Cobra errors if the command is invoked with more than one flag from the given set of flags.","code":"func (c *Command) MarkFlagsMutuallyExclusive(flagNames ...string) {\n\tc.mergePersistentFlags()\n\tfor _, v := range flagNames {\n\t\tf := c.Flags().Lookup(v)\n\t\tif f == nil {\n\t\t\tpanic(fmt.Sprintf(\"Failed to find flag %q and mark it as being in a mutually exclusive flag group\", v))\n\t\t}\n\t\t// Each time this is called is a single new entry; this allows it to be a member of multiple groups if needed.\n\t\tif err := c.Flags().SetAnnotation(v, mutuallyExclusiveAnnotation, append(f.Annotations[mutuallyExclusiveAnnotation], strings.Join(flagNames, \" \"))); err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}\n}"} | |
| {"repo":"cobra","file":"flag_groups.go","line":81,"symbol":"ValidateFlagGroups","kind":"method","lang":"go","doc":"ValidateFlagGroups validates the mutuallyExclusive/oneRequired/requiredAsGroup logic and returns the first error encountered.","code":"func (c *Command) ValidateFlagGroups() error {\n\tif c.DisableFlagParsing {\n\t\treturn nil\n\t}\n\n\tflags := c.Flags()\n\n\t// groupStatus format is the list of flags as a unique ID,\n\t// then a map of each flag name and whether it is set or not.\n\tgroupStatus := map[string]map[string]bool{}\n\toneRequiredGroupStatus := map[string]map[string]bool{}\n\tmutuallyExclusiveGroupStatus := map[string]map[string]bool{}\n\tflags.VisitAll(func(pflag *flag.Flag) {\n\t\tprocessFlagForGroupAnnotation(flags, pflag, requiredAsGroupAnnotation, groupStatus)\n\t\tprocessFlagForGroupAnnotation(flags, pflag, oneRequiredAnnotation, oneRequiredGroupStatus)\n\t\tprocessFlagForGroupAnnotation(flags, pflag, mutuallyExclusiveAnnotation, mutuallyExclusiveGroupStatus)\n\t})\n\n\tif err := validateRequiredFlagGroups(groupStatus); err != nil {\n\t\treturn err\n\t}\n\tif err := validateOneRequiredFlagGroups(oneRequiredGroupStatus); err != nil {\n\t\treturn err\n\t}\n\tif err := validateExclusiveFlagGroups(mutuallyExclusiveGroupStatus); err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"flag_groups.go","line":111,"symbol":"hasAllFlags","kind":"function","lang":"go","code":"func hasAllFlags(fs *flag.FlagSet, flagnames ...string) bool {\n\tfor _, fname := range flagnames {\n\t\tf := fs.Lookup(fname)\n\t\tif f == nil {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}"} | |
| {"repo":"cobra","file":"flag_groups.go","line":121,"symbol":"processFlagForGroupAnnotation","kind":"function","lang":"go","code":"func processFlagForGroupAnnotation(flags *flag.FlagSet, pflag *flag.Flag, annotation string, groupStatus map[string]map[string]bool) {\n\tgroupInfo, found := pflag.Annotations[annotation]\n\tif found {\n\t\tfor _, group := range groupInfo {\n\t\t\tif groupStatus[group] == nil {\n\t\t\t\tflagnames := strings.Split(group, \" \")\n\n\t\t\t\t// Only consider this flag group at all if all the flags are defined.\n\t\t\t\tif !hasAllFlags(flags, flagnames...) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tgroupStatus[group] = make(map[string]bool, len(flagnames))\n\t\t\t\tfor _, name := range flagnames {\n\t\t\t\t\tgroupStatus[group][name] = false\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tgroupStatus[group][pflag.Name] = pflag.Changed\n\t\t}\n\t}\n}"} | |
| {"repo":"cobra","file":"flag_groups.go","line":144,"symbol":"validateRequiredFlagGroups","kind":"function","lang":"go","code":"func validateRequiredFlagGroups(data map[string]map[string]bool) error {\n\tkeys := sortedKeys(data)\n\tfor _, flagList := range keys {\n\t\tflagnameAndStatus := data[flagList]\n\n\t\tunset := []string{}\n\t\tfor flagname, isSet := range flagnameAndStatus {\n\t\t\tif !isSet {\n\t\t\t\tunset = append(unset, flagname)\n\t\t\t}\n\t\t}\n\t\tif len(unset) == len(flagnameAndStatus) || len(unset) == 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\t// Sort values, so they can be tested/scripted against consistently.\n\t\tsort.Strings(unset)\n\t\treturn fmt.Errorf(\"if any flags in the group [%v] are set they must all be set; missing %v\", flagList, unset)\n\t}\n\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"flag_groups.go","line":167,"symbol":"validateOneRequiredFlagGroups","kind":"function","lang":"go","code":"func validateOneRequiredFlagGroups(data map[string]map[string]bool) error {\n\tkeys := sortedKeys(data)\n\tfor _, flagList := range keys {\n\t\tflagnameAndStatus := data[flagList]\n\t\tvar set []string\n\t\tfor flagname, isSet := range flagnameAndStatus {\n\t\t\tif isSet {\n\t\t\t\tset = append(set, flagname)\n\t\t\t}\n\t\t}\n\t\tif len(set) >= 1 {\n\t\t\tcontinue\n\t\t}\n\n\t\t// Sort values, so they can be tested/scripted against consistently.\n\t\tsort.Strings(set)\n\t\treturn fmt.Errorf(\"at least one of the flags in the group [%v] is required\", flagList)\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"flag_groups.go","line":171,"symbol":"set","kind":"variable","lang":"go","code":"set []string"} | |
| {"repo":"cobra","file":"flag_groups.go","line":188,"symbol":"validateExclusiveFlagGroups","kind":"function","lang":"go","code":"func validateExclusiveFlagGroups(data map[string]map[string]bool) error {\n\tkeys := sortedKeys(data)\n\tfor _, flagList := range keys {\n\t\tflagnameAndStatus := data[flagList]\n\t\tvar set []string\n\t\tfor flagname, isSet := range flagnameAndStatus {\n\t\t\tif isSet {\n\t\t\t\tset = append(set, flagname)\n\t\t\t}\n\t\t}\n\t\tif len(set) == 0 || len(set) == 1 {\n\t\t\tcontinue\n\t\t}\n\n\t\t// Sort values, so they can be tested/scripted against consistently.\n\t\tsort.Strings(set)\n\t\treturn fmt.Errorf(\"if any flags in the group [%v] are set none of the others can be; %v were all set\", flagList, set)\n\t}\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"flag_groups.go","line":192,"symbol":"set","kind":"variable","lang":"go","code":"set []string"} | |
| {"repo":"cobra","file":"flag_groups.go","line":209,"symbol":"sortedKeys","kind":"function","lang":"go","code":"func sortedKeys(m map[string]map[string]bool) []string {\n\tkeys := make([]string, len(m))\n\ti := 0\n\tfor k := range m {\n\t\tkeys[i] = k\n\t\ti++\n\t}\n\tsort.Strings(keys)\n\treturn keys\n}"} | |
| {"repo":"cobra","file":"flag_groups.go","line":225,"symbol":"enforceFlagGroupsForCompletion","kind":"method","lang":"go","doc":"enforceFlagGroupsForCompletion will do the following: - when a flag in a group is present, other flags in the group will be marked required - when none of the flags in a one-required group are present, all flags in the group will be marked required - when a flag in a mutually exclusive group is present, other flags in the group will be marked as hidden This allows the standard completion logic to behave appropriately for flag groups","code":"func (c *Command) enforceFlagGroupsForCompletion() {\n\tif c.DisableFlagParsing {\n\t\treturn\n\t}\n\n\tflags := c.Flags()\n\tgroupStatus := map[string]map[string]bool{}\n\toneRequiredGroupStatus := map[string]map[string]bool{}\n\tmutuallyExclusiveGroupStatus := map[string]map[string]bool{}\n\tc.Flags().VisitAll(func(pflag *flag.Flag) {\n\t\tprocessFlagForGroupAnnotation(flags, pflag, requiredAsGroupAnnotation, groupStatus)\n\t\tprocessFlagForGroupAnnotation(flags, pflag, oneRequiredAnnotation, oneRequiredGroupStatus)\n\t\tprocessFlagForGroupAnnotation(flags, pflag, mutuallyExclusiveAnnotation, mutuallyExclusiveGroupStatus)\n\t})\n\n\t// If a flag that is part of a group is present, we make all the other flags\n\t// of that group required so that the shell completion suggests them automatically\n\tfor flagList, flagnameAndStatus := range groupStatus {\n\t\tfor _, isSet := range flagnameAndStatus {\n\t\t\tif isSet {\n\t\t\t\t// One of the flags of the group is set, mark the other ones as required\n\t\t\t\tfor _, fName := range strings.Split(flagList, \" \") {\n\t\t\t\t\t_ = c.MarkFlagRequired(fName)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// If none of the flags of a one-required group are present, we make all the flags\n\t// of that group required so that the she"} | |
| {"repo":"cobra","file":"flag_groups_test.go","line":22,"symbol":"TestValidateFlagGroups","kind":"function","lang":"go","code":"func TestValidateFlagGroups(t *testing.T) {\n\tgetCmd := func() *Command {\n\t\tc := &Command{\n\t\t\tUse: \"testcmd\",\n\t\t\tRun: func(cmd *Command, args []string) {\n\t\t\t}}\n\t\t// Define lots of flags to utilize for testing.\n\t\tfor _, v := range []string{\"a\", \"b\", \"c\", \"d\"} {\n\t\t\tc.Flags().String(v, \"\", \"\")\n\t\t}\n\t\tfor _, v := range []string{\"e\", \"f\", \"g\"} {\n\t\t\tc.PersistentFlags().String(v, \"\", \"\")\n\t\t}\n\t\tsubC := &Command{\n\t\t\tUse: \"subcmd\",\n\t\t\tRun: func(cmd *Command, args []string) {\n\t\t\t}}\n\t\tsubC.Flags().String(\"subonly\", \"\", \"\")\n\t\tc.AddCommand(subC)\n\t\treturn c\n\t}\n\n\t// Each test case uses a unique command from the function above.\n\ttestcases := []struct {\n\t\tdesc string\n\t\tflagGroupsRequired []string\n\t\tflagGroupsOneRequired []string\n\t\tflagGroupsExclusive []string\n\t\tsubCmdFlagGroupsRequired []string\n\t\tsubCmdFlagGroupsOneRequired []string\n\t\tsubCmdFlagGroupsExclusive []string\n\t\targs []string\n\t\texpectErr string\n\t}{\n\t\t{\n\t\t\tdesc: \"No flags no problem\",\n\t\t}, {\n\t\t\tdesc: \"No flags no problem even with conflicting groups\",\n\t\t\tflagGroupsRequired: []string{\"a b\"},\n\t\t\tflagGroupsExclusive: []string{\"a b\"},\n\t\t}, {"} | |
| {"repo":"cobra","file":"go.mod","line":1,"symbol":"github.com/spf13/cobra","kind":"module","lang":"gomod","code":"module github.com/spf13/cobra"} | |
| {"repo":"cobra","file":"powershell_completions.go","line":28,"symbol":"genPowerShellComp","kind":"function","lang":"go","code":"func genPowerShellComp(buf io.StringWriter, name string, includeDesc bool) {\n\t// Variables should not contain a '-' or ':' character\n\tnameForVar := name\n\tnameForVar = strings.ReplaceAll(nameForVar, \"-\", \"_\")\n\tnameForVar = strings.ReplaceAll(nameForVar, \":\", \"_\")\n\n\tcompCmd := ShellCompRequestCmd\n\tif !includeDesc {\n\t\tcompCmd = ShellCompNoDescRequestCmd\n\t}\n\tWriteStringAndCheck(buf, fmt.Sprintf(`# powershell completion for %-36[1]s -*- shell-script -*-\n\nfunction __%[1]s_debug {\n if ($env:BASH_COMP_DEBUG_FILE) {\n \"$args\" | Out-File -Append -FilePath \"$env:BASH_COMP_DEBUG_FILE\"\n }\n}\n\nfilter __%[1]s_escapeStringWithSpecialChars {\n`+\" $_ -replace '\\\\s|#|@|\\\\$|;|,|''|\\\\{|\\\\}|\\\\(|\\\\)|\\\"|`|\\\\||<|>|&','`$&'\"+`\n}\n\n[scriptblock]${__%[2]sCompleterBlock} = {\n param(\n $WordToComplete,\n $CommandAst,\n $CursorPosition\n )\n\n # Get the current command line and convert into a string\n $Command = $CommandAst.CommandElements\n $Command = \"$Command\"\n\n __%[1]s_debug \"\"\n __%[1]s_debug \"========= starting completion logic ==========\"\n __%[1]s_debug \"WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition\"\n\n #"} | |
| {"repo":"cobra","file":"powershell_completions.go","line":313,"symbol":"genPowerShellCompletion","kind":"method","lang":"go","code":"func (c *Command) genPowerShellCompletion(w io.Writer, includeDesc bool) error {\n\tbuf := new(bytes.Buffer)\n\tgenPowerShellComp(buf, c.Name(), includeDesc)\n\t_, err := buf.WriteTo(w)\n\treturn err\n}"} | |
| {"repo":"cobra","file":"powershell_completions.go","line":320,"symbol":"genPowerShellCompletionFile","kind":"method","lang":"go","code":"func (c *Command) genPowerShellCompletionFile(filename string, includeDesc bool) error {\n\toutFile, err := os.Create(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer outFile.Close()\n\n\treturn c.genPowerShellCompletion(outFile, includeDesc)\n}"} | |
| {"repo":"cobra","file":"powershell_completions.go","line":331,"symbol":"GenPowerShellCompletionFile","kind":"method","lang":"go","doc":"GenPowerShellCompletionFile generates powershell completion file without descriptions.","code":"func (c *Command) GenPowerShellCompletionFile(filename string) error {\n\treturn c.genPowerShellCompletionFile(filename, false)\n}"} | |
| {"repo":"cobra","file":"powershell_completions.go","line":337,"symbol":"GenPowerShellCompletion","kind":"method","lang":"go","doc":"GenPowerShellCompletion generates powershell completion file without descriptions and writes it to the passed writer.","code":"func (c *Command) GenPowerShellCompletion(w io.Writer) error {\n\treturn c.genPowerShellCompletion(w, false)\n}"} | |
| {"repo":"cobra","file":"powershell_completions.go","line":342,"symbol":"GenPowerShellCompletionFileWithDesc","kind":"method","lang":"go","doc":"GenPowerShellCompletionFileWithDesc generates powershell completion file with descriptions.","code":"func (c *Command) GenPowerShellCompletionFileWithDesc(filename string) error {\n\treturn c.genPowerShellCompletionFile(filename, true)\n}"} | |
| {"repo":"cobra","file":"powershell_completions.go","line":348,"symbol":"GenPowerShellCompletionWithDesc","kind":"method","lang":"go","doc":"GenPowerShellCompletionWithDesc generates powershell completion file with descriptions and writes it to the passed writer.","code":"func (c *Command) GenPowerShellCompletionWithDesc(w io.Writer) error {\n\treturn c.genPowerShellCompletion(w, true)\n}"} | |
| {"repo":"cobra","file":"powershell_completions_test.go","line":23,"symbol":"TestPwshCompletionNoActiveHelp","kind":"function","lang":"go","code":"func TestPwshCompletionNoActiveHelp(t *testing.T) {\n\tc := &Command{Use: \"c\", Run: emptyRun}\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, c.GenPowerShellCompletion(buf))\n\toutput := buf.String()\n\n\t// check that active help is being disabled\n\tactiveHelpVar := activeHelpEnvVar(c.Name())\n\tcheck(t, output, fmt.Sprintf(\"${env:%s}=0\", activeHelpVar))\n}"} | |
| {"repo":"cobra","file":"shell_completions.go","line":24,"symbol":"MarkFlagRequired","kind":"method","lang":"go","doc":"MarkFlagRequired instructs the various shell completion implementations to prioritize the named flag when performing completion, and causes your command to report an error if invoked without the flag.","code":"func (c *Command) MarkFlagRequired(name string) error {\n\treturn MarkFlagRequired(c.Flags(), name)\n}"} | |
| {"repo":"cobra","file":"shell_completions.go","line":31,"symbol":"MarkPersistentFlagRequired","kind":"method","lang":"go","doc":"MarkPersistentFlagRequired instructs the various shell completion implementations to prioritize the named persistent flag when performing completion, and causes your command to report an error if invoked without the flag.","code":"func (c *Command) MarkPersistentFlagRequired(name string) error {\n\treturn MarkFlagRequired(c.PersistentFlags(), name)\n}"} | |
| {"repo":"cobra","file":"shell_completions.go","line":38,"symbol":"MarkFlagRequired","kind":"function","lang":"go","doc":"MarkFlagRequired instructs the various shell completion implementations to prioritize the named flag when performing completion, and causes your command to report an error if invoked without the flag.","code":"func MarkFlagRequired(flags *pflag.FlagSet, name string) error {\n\treturn flags.SetAnnotation(name, BashCompOneRequiredFlag, []string{\"true\"})\n}"} | |
| {"repo":"cobra","file":"shell_completions.go","line":44,"symbol":"MarkFlagFilename","kind":"method","lang":"go","doc":"MarkFlagFilename instructs the various shell completion implementations to limit completions for the named flag to the specified file extensions.","code":"func (c *Command) MarkFlagFilename(name string, extensions ...string) error {\n\treturn MarkFlagFilename(c.Flags(), name, extensions...)\n}"} | |
| {"repo":"cobra","file":"shell_completions.go","line":54,"symbol":"MarkFlagCustom","kind":"method","lang":"go","doc":"MarkFlagCustom adds the BashCompCustom annotation to the named flag, if it exists. The bash completion script will call the bash function f for the flag. This will only work for bash completion. It is recommended to instead use c.RegisterFlagCompletionFunc(...) which allows to register a Go function which will work across all shells.","code":"func (c *Command) MarkFlagCustom(name string, f string) error {\n\treturn MarkFlagCustom(c.Flags(), name, f)\n}"} | |
| {"repo":"cobra","file":"shell_completions.go","line":61,"symbol":"MarkPersistentFlagFilename","kind":"method","lang":"go","doc":"MarkPersistentFlagFilename instructs the various shell completion implementations to limit completions for the named persistent flag to the specified file extensions.","code":"func (c *Command) MarkPersistentFlagFilename(name string, extensions ...string) error {\n\treturn MarkFlagFilename(c.PersistentFlags(), name, extensions...)\n}"} | |
| {"repo":"cobra","file":"shell_completions.go","line":67,"symbol":"MarkFlagFilename","kind":"function","lang":"go","doc":"MarkFlagFilename instructs the various shell completion implementations to limit completions for the named flag to the specified file extensions.","code":"func MarkFlagFilename(flags *pflag.FlagSet, name string, extensions ...string) error {\n\treturn flags.SetAnnotation(name, BashCompFilenameExt, extensions)\n}"} | |
| {"repo":"cobra","file":"shell_completions.go","line":77,"symbol":"MarkFlagCustom","kind":"function","lang":"go","doc":"MarkFlagCustom adds the BashCompCustom annotation to the named flag, if it exists. The bash completion script will call the bash function f for the flag. This will only work for bash completion. It is recommended to instead use c.RegisterFlagCompletionFunc(...) which allows to register a Go function which will work across all shells.","code":"func MarkFlagCustom(flags *pflag.FlagSet, name string, f string) error {\n\treturn flags.SetAnnotation(name, BashCompCustom, []string{f})\n}"} | |
| {"repo":"cobra","file":"shell_completions.go","line":83,"symbol":"MarkFlagDirname","kind":"method","lang":"go","doc":"MarkFlagDirname instructs the various shell completion implementations to limit completions for the named flag to directory names.","code":"func (c *Command) MarkFlagDirname(name string) error {\n\treturn MarkFlagDirname(c.Flags(), name)\n}"} | |
| {"repo":"cobra","file":"shell_completions.go","line":90,"symbol":"MarkPersistentFlagDirname","kind":"method","lang":"go","doc":"MarkPersistentFlagDirname instructs the various shell completion implementations to limit completions for the named persistent flag to directory names.","code":"func (c *Command) MarkPersistentFlagDirname(name string) error {\n\treturn MarkFlagDirname(c.PersistentFlags(), name)\n}"} | |
| {"repo":"cobra","file":"shell_completions.go","line":96,"symbol":"MarkFlagDirname","kind":"function","lang":"go","doc":"MarkFlagDirname instructs the various shell completion implementations to limit completions for the named flag to directory names.","code":"func MarkFlagDirname(flags *pflag.FlagSet, name string) error {\n\treturn flags.SetAnnotation(name, BashCompSubdirsInDir, []string{})\n}"} | |
| {"repo":"cobra","file":"zsh_completions.go","line":25,"symbol":"GenZshCompletionFile","kind":"method","lang":"go","doc":"GenZshCompletionFile generates zsh completion file including descriptions.","code":"func (c *Command) GenZshCompletionFile(filename string) error {\n\treturn c.genZshCompletionFile(filename, true)\n}"} | |
| {"repo":"cobra","file":"zsh_completions.go","line":31,"symbol":"GenZshCompletion","kind":"method","lang":"go","doc":"GenZshCompletion generates zsh completion file including descriptions and writes it to the passed writer.","code":"func (c *Command) GenZshCompletion(w io.Writer) error {\n\treturn c.genZshCompletion(w, true)\n}"} | |
| {"repo":"cobra","file":"zsh_completions.go","line":36,"symbol":"GenZshCompletionFileNoDesc","kind":"method","lang":"go","doc":"GenZshCompletionFileNoDesc generates zsh completion file without descriptions.","code":"func (c *Command) GenZshCompletionFileNoDesc(filename string) error {\n\treturn c.genZshCompletionFile(filename, false)\n}"} | |
| {"repo":"cobra","file":"zsh_completions.go","line":42,"symbol":"GenZshCompletionNoDesc","kind":"method","lang":"go","doc":"GenZshCompletionNoDesc generates zsh completion file without descriptions and writes it to the passed writer.","code":"func (c *Command) GenZshCompletionNoDesc(w io.Writer) error {\n\treturn c.genZshCompletion(w, false)\n}"} | |
| {"repo":"cobra","file":"zsh_completions.go","line":55,"symbol":"MarkZshCompPositionalArgumentFile","kind":"method","lang":"go","doc":"default for every argument. One can disable file completion on a per-argument basis by using ValidArgsFunction and ShellCompDirectiveNoFileComp. To achieve file extension filtering, one can use ValidArgsFunction and ShellCompDirectiveFilterFileExt. Deprecated","code":"func (c *Command) MarkZshCompPositionalArgumentFile(argPosition int, patterns ...string) error {\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"zsh_completions.go","line":66,"symbol":"MarkZshCompPositionalArgumentWords","kind":"method","lang":"go","doc":"been disabled. To achieve the same behavior across all shells, one can use ValidArgs (for the first argument only) or ValidArgsFunction for any argument (can include the first one also). Deprecated","code":"func (c *Command) MarkZshCompPositionalArgumentWords(argPosition int, words ...string) error {\n\treturn nil\n}"} | |
| {"repo":"cobra","file":"zsh_completions.go","line":70,"symbol":"genZshCompletionFile","kind":"method","lang":"go","code":"func (c *Command) genZshCompletionFile(filename string, includeDesc bool) error {\n\toutFile, err := os.Create(filename)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer outFile.Close()\n\n\treturn c.genZshCompletion(outFile, includeDesc)\n}"} | |
| {"repo":"cobra","file":"zsh_completions.go","line":80,"symbol":"genZshCompletion","kind":"method","lang":"go","code":"func (c *Command) genZshCompletion(w io.Writer, includeDesc bool) error {\n\tbuf := new(bytes.Buffer)\n\tgenZshComp(buf, c.Name(), includeDesc)\n\t_, err := buf.WriteTo(w)\n\treturn err\n}"} | |
| {"repo":"cobra","file":"zsh_completions.go","line":87,"symbol":"genZshComp","kind":"function","lang":"go","code":"func genZshComp(buf io.StringWriter, name string, includeDesc bool) {\n\tcompCmd := ShellCompRequestCmd\n\tif !includeDesc {\n\t\tcompCmd = ShellCompNoDescRequestCmd\n\t}\n\tWriteStringAndCheck(buf, fmt.Sprintf(`#compdef %[1]s\ncompdef _%[1]s %[1]s\n\n# zsh completion for %-36[1]s -*- shell-script -*-\n\n__%[1]s_debug()\n{\n local file=\"$BASH_COMP_DEBUG_FILE\"\n if [[ -n ${file} ]]; then\n echo \"$*\" >> \"${file}\"\n fi\n}\n\n_%[1]s()\n{\n local shellCompDirectiveError=%[3]d\n local shellCompDirectiveNoSpace=%[4]d\n local shellCompDirectiveNoFileComp=%[5]d\n local shellCompDirectiveFilterFileExt=%[6]d\n local shellCompDirectiveFilterDirs=%[7]d\n local shellCompDirectiveKeepOrder=%[8]d\n\n local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder\n local -a completions\n\n __%[1]s_debug \"\\n========= starting completion logic ==========\"\n __%[1]s_debug \"CURRENT: ${CURRENT}, words[*]: ${words[*]}\"\n\n # The user could have moved the cursor backwards on the command-line.\n # We need to trigger completion from the $CURRENT location, so we need\n # to truncate the command-line ($words) up to the $CURRENT location.\n # (We cannot use $CURSO"} | |
| {"repo":"cobra","file":"zsh_completions_test.go","line":23,"symbol":"TestZshCompletionWithActiveHelp","kind":"function","lang":"go","code":"func TestZshCompletionWithActiveHelp(t *testing.T) {\n\tc := &Command{Use: \"c\", Run: emptyRun}\n\n\tbuf := new(bytes.Buffer)\n\tassertNoErr(t, c.GenZshCompletion(buf))\n\toutput := buf.String()\n\n\t// check that active help is not being disabled\n\tactiveHelpVar := activeHelpEnvVar(c.Name())\n\tcheckOmit(t, output, fmt.Sprintf(\"%s=0\", activeHelpVar))\n}"} | |