Skip to content

Commit

Permalink
fix after rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor committed Apr 13, 2020
1 parent 11cd7b9 commit 0744038
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions bash_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ func prepareCustomAnnotationsForFlags(cmd *Command) {
}

func writeFlags(buf io.StringWriter, cmd *Command) {
prepareCustomAnnotationsForFlags(cmd)
WrStringAndCheck(buf, ` flags=()
prepareCustomAnnotationsForFlags(cmd)
WrStringAndCheck(buf, ` flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
Expand Down Expand Up @@ -553,11 +553,11 @@ func writeRequiredNouns(buf io.StringWriter, cmd *Command) {
for _, value := range cmd.ValidArgs {
// Remove any description that may be included following a tab character.
// Descriptions are not supported by bash completion.
value = strings.Split(value, "\t")[0]
WrStringAndCheck(buf, fmt.Sprintf(" must_have_one_noun+=(%q)\n", value))
value = strings.Split(value, "\t")[0]
WrStringAndCheck(buf, fmt.Sprintf(" must_have_one_noun+=(%q)\n", value))
}
if cmd.ValidArgsFunction != nil {
buf.WriteString(" has_completion_function=1\n")
WrStringAndCheck(buf, " has_completion_function=1\n")
}
}

Expand Down
2 changes: 1 addition & 1 deletion custom_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func CompDebug(msg string, printToStdErr bool) {
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err == nil {
defer f.Close()
f.WriteString(msg)
WrStringAndCheck(f, msg)
}
}

Expand Down
22 changes: 11 additions & 11 deletions custom_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func TestValidArgsFuncInBashScript(t *testing.T) {
rootCmd.AddCommand(child)

buf := new(bytes.Buffer)
rootCmd.GenBashCompletion(buf)
er(rootCmd.GenBashCompletion(buf))
output := buf.String()

check(t, output, "has_completion_function=1")
Expand All @@ -285,7 +285,7 @@ func TestNoValidArgsFuncInBashScript(t *testing.T) {
rootCmd.AddCommand(child)

buf := new(bytes.Buffer)
rootCmd.GenBashCompletion(buf)
er(rootCmd.GenBashCompletion(buf))
output := buf.String()

checkOmit(t, output, "has_completion_function=1")
Expand All @@ -301,7 +301,7 @@ func TestCompleteCmdInBashScript(t *testing.T) {
rootCmd.AddCommand(child)

buf := new(bytes.Buffer)
rootCmd.GenBashCompletion(buf)
er(rootCmd.GenBashCompletion(buf))
output := buf.String()

check(t, output, ShellCompNoDescRequestCmd)
Expand All @@ -317,7 +317,7 @@ func TestCompleteNoDesCmdInFishScript(t *testing.T) {
rootCmd.AddCommand(child)

buf := new(bytes.Buffer)
rootCmd.GenFishCompletion(buf, false)
er(rootCmd.GenFishCompletion(buf, false))
output := buf.String()

check(t, output, ShellCompNoDescRequestCmd)
Expand All @@ -333,7 +333,7 @@ func TestCompleteCmdInFishScript(t *testing.T) {
rootCmd.AddCommand(child)

buf := new(bytes.Buffer)
rootCmd.GenFishCompletion(buf, true)
er(rootCmd.GenFishCompletion(buf, true))
output := buf.String()

check(t, output, ShellCompRequestCmd)
Expand All @@ -346,25 +346,25 @@ func TestFlagCompletionInGo(t *testing.T) {
Run: emptyRun,
}
rootCmd.Flags().IntP("introot", "i", -1, "help message for flag introot")
rootCmd.RegisterFlagCompletionFunc("introot", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
er(rootCmd.RegisterFlagCompletionFunc("introot", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
completions := []string{}
for _, comp := range []string{"1\tThe first", "2\tThe second", "10\tThe tenth"} {
if strings.HasPrefix(comp, toComplete) {
completions = append(completions, comp)
}
}
return completions, ShellCompDirectiveDefault
})
}))
rootCmd.Flags().String("filename", "", "Enter a filename")
rootCmd.RegisterFlagCompletionFunc("filename", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
er(rootCmd.RegisterFlagCompletionFunc("filename", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
completions := []string{}
for _, comp := range []string{"file.yaml\tYAML format", "myfile.json\tJSON format", "file.xml\tXML format"} {
if strings.HasPrefix(comp, toComplete) {
completions = append(completions, comp)
}
}
return completions, ShellCompDirectiveNoSpace | ShellCompDirectiveNoFileComp
})
}))

// Test completing an empty string
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "--introot", "")
Expand Down Expand Up @@ -543,15 +543,15 @@ func TestFlagCompletionInGoWithDesc(t *testing.T) {
Run: emptyRun,
}
rootCmd.Flags().IntP("introot", "i", -1, "help message for flag introot")
rootCmd.RegisterFlagCompletionFunc("introot", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
er(rootCmd.RegisterFlagCompletionFunc("introot", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
completions := []string{}
for _, comp := range []string{"1\tThe first", "2\tThe second", "10\tThe tenth"} {
if strings.HasPrefix(comp, toComplete) {
completions = append(completions, comp)
}
}
return completions, ShellCompDirectiveDefault
})
}))
rootCmd.Flags().String("filename", "", "Enter a filename")
rootCmd.RegisterFlagCompletionFunc("filename", func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
completions := []string{}
Expand Down
6 changes: 3 additions & 3 deletions fish_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"os"
)

func genFishComp(buf *bytes.Buffer, name string, includeDesc bool) {
func genFishComp(buf io.StringWriter, name string, includeDesc bool) {
compCmd := ShellCompRequestCmd
if !includeDesc {
compCmd = ShellCompNoDescRequestCmd
}
buf.WriteString(fmt.Sprintf("# fish completion for %-36s -*- shell-script -*-\n", name))
buf.WriteString(fmt.Sprintf(`
WrStringAndCheck(buf, fmt.Sprintf("# fish completion for %-36s -*- shell-script -*-\n", name))
WrStringAndCheck(buf, fmt.Sprintf(`
function __%[1]s_debug
set file "$BASH_COMP_DEBUG_FILE"
if test -n "$file"
Expand Down

0 comments on commit 0744038

Please sign in to comment.