Skip to content

Commit

Permalink
🐛 Fix CLI completion generation (QD-9907)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Sep 16, 2024
1 parent 0183d62 commit cac836c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func isHelpOrVersion(args []string) bool {
return len(args) == 2 && (args[1] == "--help" || args[1] == "-h" || args[1] == "help" || args[1] == "--version" || args[1] == "-v")
}

func isCompletionRequested(args []string) bool {
return args[1] == "completion"
}

// isCommandRequested checks if any command is requested.
func isCommandRequested(commands []*cobra.Command, args []string) string {
for _, c := range commands {
Expand All @@ -45,7 +49,7 @@ func isCommandRequested(commands []*cobra.Command, args []string) string {

// setDefaultCommandIfNeeded sets default scan command if no other command is requested.
func setDefaultCommandIfNeeded(rootCmd *cobra.Command, args []string) {
if !(isHelpOrVersion(args) || isCommandRequested(rootCmd.Commands(), args[1:]) != "") {
if !(isHelpOrVersion(args) || isCommandRequested(rootCmd.Commands(), args[1:]) != "" || isCompletionRequested(args)) {
newArgs := append([]string{"scan"}, args[1:]...)
rootCmd.SetArgs(newArgs)
}
Expand Down

0 comments on commit cac836c

Please sign in to comment.