Skip to content

Commit 84bd703

Browse files
PowerStateFailureJonathan S. Katz
authored andcommitted
pgo: generate Bash completion on-demand (#667) (#902)
1 parent 7739459 commit 84bd703

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pgo/cmd/root.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,19 @@ func initConfig() {
8484

8585
GetCredentials()
8686

87-
generateBashCompletion()
87+
if os.Getenv("GENERATE_BASH_COMPLETION") != "" {
88+
if err := generateBashCompletion(); err != nil {
89+
fmt.Printf("Error generating Bash completion: %v", err)
90+
}
91+
}
8892
}
8993

90-
func generateBashCompletion() {
91-
file, err2 := os.Create("/tmp/pgo-bash-completion.out")
92-
if err2 != nil {
93-
fmt.Println("Error: ", err2.Error())
94+
func generateBashCompletion() error {
95+
log.Debugf("generating bash completion script")
96+
file, err := os.Create("/tmp/pgo-bash-completion.out")
97+
if err != nil {
98+
return err
9499
}
95100
defer file.Close()
96-
RootCmd.GenBashCompletion(file)
101+
return RootCmd.GenBashCompletion(file)
97102
}

0 commit comments

Comments
 (0)