Skip to content
Myr

Fix two word flags (#807)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Daisuke Taniwaki · committed by Eric Paris · parent 7547e83 · Browse files · 2 files+16 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+16 added−1 removed

  • other:+16 added−1 removed

2 files+16 added−1 removed

modified:bash_completions_test.go+10 added
93 unmodified lines
94 // Subdirectories in a given directory.95 rootCmd.Flags().String("theme", "", "theme to use (located in /themes/THEMENAME/)")96 rootCmd.Flags().SetAnnotation("theme", BashCompSubdirsInDir, []string{"themes"})9798 // For two word flags check99 rootCmd.Flags().StringP("two", "t", "", "this is two word flags")100 rootCmd.Flags().BoolP("two-w-default", "T", false, "this is not two word flags")101102 echoCmd := &Command{103 Use: "echo [string to echo]",104 Aliases: []string{"say"},105 Short: "Echo anything to the screen",
80 unmodified lines
186 check(t, output, fmt.Sprintf(`flags_completion+=("__%s_handle_subdirs_in_dir_flag themes")`, rootCmd.Name()))187 // check for subdirs_in_dir flags in a subcommand188 checkRegex(t, output, fmt.Sprintf(`_root_echo\(\)\n{[^}]*flags_completion\+=\("__%s_handle_subdirs_in_dir_flag config"\)`, rootCmd.Name()))189190 // check two word flags191 check(t, output, `two_word_flags+=("--two")`)192 check(t, output, `two_word_flags+=("-t")`)193 checkOmit(t, output, `two_word_flags+=("--two-w-default")`)194 checkOmit(t, output, `two_word_flags+=("-T")`)195196 checkOmit(t, output, deprecatedCmd.Name())197198 // If available, run shellcheck against the script.199 if err := exec.Command("which", "shellcheck").Run(); err != nil {
38 unmodified lines
modified:bash_completions.go+6 added-1 removed
197 unmodified lines
198 fi199 fi200201 # skip the argument to a two word flag202 if __%[1]s_contains_word "${words[c]}" "${two_word_flags[@]}"; then202 if [[ ${words[c]} != *"="* ]] && __%[1]s_contains_word "${words[c]}" "${two_word_flags[@]}"; then203 __%[1]s_debug "${FUNCNAME[0]}: found a flag ${words[c]}, skip the next argument"204 c=$((c+1))205 # if we are looking for a flags value, don't show commands206 if [[ $c -eq $cword ]]; then207 commands=()
171 unmodified lines
379 format += "="380 }381 format += "\")\n"382 buf.WriteString(fmt.Sprintf(format, name))383 if len(flag.NoOptDefVal) == 0 {384 format = " two_word_flags+=(\"--%s\")\n"385 buf.WriteString(fmt.Sprintf(format, name))386 }387 writeFlagHandler(buf, "--"+name, flag.Annotations, cmd)388}389390func writeLocalNonPersistentFlag(buf *bytes.Buffer, flag *pflag.Flag) {
205 unmodified lines