Skip to content

Commit

Permalink
add duplicate command warning (#3174)
Browse files Browse the repository at this point in the history
Co-authored-by: Trajan0x <[email protected]>
  • Loading branch information
trajan0x and trajan0x authored Sep 26, 2024
1 parent 3af3438 commit 3e75b0d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/commandline/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commandline
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/util/sets"
"os"
"os/signal"
"os/user"
Expand Down Expand Up @@ -90,11 +91,18 @@ func GenerateShellCommand(shellCommands []*cli.Command) *cli.Command {
// pruneShellCommands gets a list of commands including the shell command.
func pruneShellCommands(commands []*cli.Command) (prunedCommands []*cli.Command) {
// initialize shell commands
nameSet := sets.NewString()

Check warning on line 94 in core/commandline/shell.go

View check run for this annotation

Codecov / codecov/patch

core/commandline/shell.go#L94

Added line #L94 was not covered by tests
for _, command := range commands {
if command.Name != shellCommandName {
prunedCommands = append(prunedCommands, command)
}
if !nameSet.Has(command.Name) {
fmt.Printf("Command %s already exists, skipping\n", command.Name)
}

Check warning on line 101 in core/commandline/shell.go

View check run for this annotation

Codecov / codecov/patch

core/commandline/shell.go#L99-L101

Added lines #L99 - L101 were not covered by tests

nameSet.Insert(command.Name)

Check warning on line 103 in core/commandline/shell.go

View check run for this annotation

Codecov / codecov/patch

core/commandline/shell.go#L103

Added line #L103 was not covered by tests
}

return prunedCommands
}

Expand Down

0 comments on commit 3e75b0d

Please sign in to comment.