Skip to content

Commit 184cf08

Browse files
committed
main.go: Correct autocompletions for all commands
1 parent 358b70a commit 184cf08

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ func main() {
114114
fmt.Printf("Given QR code successfully registered as \"%v\".\n", name)
115115
return nil
116116
},
117+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
118+
if len(args) == 1 {
119+
return nil, cobra.ShellCompDirectiveDefault
120+
}
121+
122+
return nil, cobra.ShellCompDirectiveNoFileComp
123+
},
117124
}
118125

119126
cmdScan.Flags().BoolVarP(
@@ -147,6 +154,7 @@ func main() {
147154
fmt.Printf("Given secret successfully registered as \"%v\".\n", name)
148155
return nil
149156
},
157+
ValidArgsFunction: cobra.NoFileCompletions,
150158
}
151159

152160
var cmdList = &cobra.Command{
@@ -164,6 +172,7 @@ func main() {
164172
}
165173
return nil
166174
},
175+
ValidArgsFunction: cobra.NoFileCompletions,
167176
}
168177

169178
var cmdGet = &cobra.Command{
@@ -259,6 +268,7 @@ func main() {
259268
fmt.Println(gotp.NewDefaultTOTP(secret).Now())
260269
return nil
261270
},
271+
ValidArgsFunction: cobra.NoFileCompletions,
262272
}
263273

264274
var rootCmd = &cobra.Command{Use: "totp", Short: "Simple TOTP CLI, powered by keychain of macOS", Version: "1.1.2"}

0 commit comments

Comments
 (0)