Skip to content

Commit f244ff3

Browse files
authored
Merge pull request #15 from gugahoi/fix/completion-project-id
fix(completion): do not require project for completion command
2 parents ce89fa6 + cf77b9d commit f244ff3

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

pkg/cmd/root.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ var rootCmd = &cobra.Command{
2222
Short: "perform actions on firestore",
2323
SilenceUsage: true,
2424
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
25+
if isCompletionCommand(cmd) {
26+
return nil
27+
}
28+
2529
if projectId == "" {
2630
envValue := os.Getenv("PROJECT_ID")
2731
if envValue == "" {
@@ -48,6 +52,16 @@ var rootCmd = &cobra.Command{
4852
},
4953
}
5054

55+
func isCompletionCommand(cmd *cobra.Command) bool {
56+
for cmd != nil {
57+
if cmd.Name() == "completion" || cmd.Name() == cobra.ShellCompRequestCmd {
58+
return true
59+
}
60+
cmd = cmd.Parent()
61+
}
62+
return false
63+
}
64+
5165
// Execute adds all child commands to the root command and sets flags appropriately.
5266
// This is called by main.main(). It only needs to happen once to the rootCmd.
5367
func Execute() {

0 commit comments

Comments
 (0)