Skip to content

Commit

Permalink
fix <nil> output in completion script generation
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Mar 3, 2021
1 parent 8dfb458 commit 6d32c09
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"os"

"github.com/rsteube/carapace"
"github.com/spf13/cobra"
Expand All @@ -22,10 +23,14 @@ Scripts can be directly sourced (though using pre-generated versions is recommen
zsh : source <(lab completion)`,
ValidArgs: []string{"bash", "elvish", "fish", "powershell", "xonsh", "zsh"},
Run: func(cmd *cobra.Command, args []string) {
shell := ""
if len(args) > 0 {
fmt.Println(carapace.Gen(cmd).Snippet(args[0]))
shell = args[0]
}
if script, err := carapace.Gen(cmd).Snippet(shell); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
} else {
fmt.Println(carapace.Gen(cmd).Snippet(""))
fmt.Println(script)
}
},
}
Expand Down

0 comments on commit 6d32c09

Please sign in to comment.