(t *testing.T)
| 3155 | } |
| 3156 | |
| 3157 | func TestCompletionForOneRequiredGroupFlags(t *testing.T) { |
| 3158 | getCmd := func() *Command { |
| 3159 | rootCmd := &Command{ |
| 3160 | Use: "root", |
| 3161 | Run: emptyRun, |
| 3162 | } |
| 3163 | childCmd := &Command{ |
| 3164 | Use: "child", |
| 3165 | ValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) { |
| 3166 | return []string{"subArg"}, ShellCompDirectiveNoFileComp |
| 3167 | }, |
| 3168 | Run: emptyRun, |
| 3169 | } |
| 3170 | rootCmd.AddCommand(childCmd) |
| 3171 | |
| 3172 | rootCmd.PersistentFlags().Int("ingroup1", -1, "ingroup1") |
| 3173 | rootCmd.PersistentFlags().String("ingroup2", "", "ingroup2") |
| 3174 | |
| 3175 | childCmd.Flags().Bool("ingroup3", false, "ingroup3") |
| 3176 | childCmd.Flags().Bool("nogroup", false, "nogroup") |
| 3177 | |
| 3178 | // Add flags to a group |
| 3179 | childCmd.MarkFlagsOneRequired("ingroup1", "ingroup2", "ingroup3") |
| 3180 | |
| 3181 | return rootCmd |
| 3182 | } |
| 3183 | |
| 3184 | // Each test case uses a unique command from the function above. |
| 3185 | testcases := []struct { |
| 3186 | desc string |
| 3187 | args []string |
| 3188 | expectedOutput string |
| 3189 | }{ |
| 3190 | { |
| 3191 | desc: "flags in group suggested without - prefix", |
| 3192 | args: []string{"child", ""}, |
| 3193 | expectedOutput: strings.Join([]string{ |
| 3194 | "--ingroup1", |
| 3195 | "--ingroup2", |
| 3196 | "--ingroup3", |
| 3197 | "subArg", |
| 3198 | ":4", |
| 3199 | "Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"), |
| 3200 | }, |
| 3201 | { |
| 3202 | desc: "flags in group suggested with - prefix", |
| 3203 | args: []string{"child", "-"}, |
| 3204 | expectedOutput: strings.Join([]string{ |
| 3205 | "--ingroup1", |
| 3206 | "--ingroup2", |
| 3207 | "--ingroup3", |
| 3208 | ":4", |
| 3209 | "Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"), |
| 3210 | }, |
| 3211 | { |
| 3212 | desc: "when any flag in group present, other flags in group not suggested without - prefix", |
| 3213 | args: []string{"child", "--ingroup2", "value", ""}, |
| 3214 | expectedOutput: strings.Join([]string{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…