Skip to content

Commit

Permalink
fix: after rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor committed Jul 11, 2020
1 parent 4f39370 commit 1f6cd54
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
24 changes: 12 additions & 12 deletions custom_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,17 +720,17 @@ func TestRequiredFlagNameCompletionInGo(t *testing.T) {
rootCmd.AddCommand(childCmd)

rootCmd.Flags().IntP("requiredFlag", "r", -1, "required flag")
rootCmd.MarkFlagRequired("requiredFlag")
er(rootCmd.MarkFlagRequired("requiredFlag"))
requiredFlag := rootCmd.Flags().Lookup("requiredFlag")

rootCmd.PersistentFlags().IntP("requiredPersistent", "p", -1, "required persistent")
rootCmd.MarkPersistentFlagRequired("requiredPersistent")
er(rootCmd.MarkPersistentFlagRequired("requiredPersistent"))
requiredPersistent := rootCmd.PersistentFlags().Lookup("requiredPersistent")

rootCmd.Flags().StringP("release", "R", "", "Release name")

childCmd.Flags().BoolP("subRequired", "s", false, "sub required flag")
childCmd.MarkFlagRequired("subRequired")
er(childCmd.MarkFlagRequired("subRequired"))
childCmd.Flags().BoolP("subNotRequired", "n", false, "sub not required flag")

// Test that a required flag is suggested even without the - prefix
Expand Down Expand Up @@ -904,19 +904,19 @@ func TestFlagFileExtFilterCompletionInGo(t *testing.T) {

// No extensions. Should be ignored.
rootCmd.Flags().StringP("file", "f", "", "file flag")
rootCmd.MarkFlagFilename("file")
er(rootCmd.MarkFlagFilename("file"))

// Single extension
rootCmd.Flags().StringP("log", "l", "", "log flag")
rootCmd.MarkFlagFilename("log", "log")
er(rootCmd.MarkFlagFilename("log", "log"))

// Multiple extensions
rootCmd.Flags().StringP("yaml", "y", "", "yaml flag")
rootCmd.MarkFlagFilename("yaml", "yaml", "yml")
er(rootCmd.MarkFlagFilename("yaml", "yaml", "yml"))

// Directly using annotation
rootCmd.Flags().StringP("text", "t", "", "text flag")
rootCmd.Flags().SetAnnotation("text", BashCompFilenameExt, []string{"txt"})
er(rootCmd.Flags().SetAnnotation("text", BashCompFilenameExt, []string{"txt"}))

// Test that the completion logic returns the proper info for the completion
// script to handle the file filtering
Expand Down Expand Up @@ -1026,15 +1026,15 @@ func TestFlagDirFilterCompletionInGo(t *testing.T) {

// Filter directories
rootCmd.Flags().StringP("dir", "d", "", "dir flag")
rootCmd.MarkFlagDirname("dir")
er(rootCmd.MarkFlagDirname("dir"))

// Filter directories within a directory
rootCmd.Flags().StringP("subdir", "s", "", "subdir")
rootCmd.Flags().SetAnnotation("subdir", BashCompSubdirsInDir, []string{"themes"})
er(rootCmd.Flags().SetAnnotation("subdir", BashCompSubdirsInDir, []string{"themes"}))

// Multiple directory specification get ignored
rootCmd.Flags().StringP("manydir", "m", "", "manydir")
rootCmd.Flags().SetAnnotation("manydir", BashCompSubdirsInDir, []string{"themes", "colors"})
er(rootCmd.Flags().SetAnnotation("manydir", BashCompSubdirsInDir, []string{"themes", "colors"}))

// Test that the completion logic returns the proper info for the completion
// script to handle the directory filtering
Expand Down Expand Up @@ -1417,7 +1417,7 @@ func TestCompleteNoDesCmdInZshScript(t *testing.T) {
rootCmd.AddCommand(child)

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

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

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

check(t, output, ShellCompRequestCmd)
Expand Down
6 changes: 3 additions & 3 deletions fish_completions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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 @@ -31,7 +31,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 @@ -41,7 +41,7 @@ func TestCompleteCmdInFishScript(t *testing.T) {
func TestProgWithDash(t *testing.T) {
rootCmd := &Command{Use: "root-dash", Args: NoArgs, Run: emptyRun}
buf := new(bytes.Buffer)
rootCmd.GenFishCompletion(buf, false)
er(rootCmd.GenFishCompletion(buf, false))
output := buf.String()

// Functions name should have replace the '-'
Expand Down
4 changes: 2 additions & 2 deletions zsh_completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ func (c *Command) genZshCompletion(w io.Writer, includeDesc bool) error {
return err
}

func genZshComp(buf *bytes.Buffer, name string, includeDesc bool) {
func genZshComp(buf io.StringWriter, name string, includeDesc bool) {
compCmd := ShellCompRequestCmd
if !includeDesc {
compCmd = ShellCompNoDescRequestCmd
}
buf.WriteString(fmt.Sprintf(`#compdef _%[1]s %[1]s
WrStringAndCheck(buf, fmt.Sprintf(`#compdef _%[1]s %[1]s
# zsh completion for %-36[1]s -*- shell-script -*-
Expand Down

0 comments on commit 1f6cd54

Please sign in to comment.