Skip to content

Commit

Permalink
feat: check if filters does not empty on add & remove
Browse files Browse the repository at this point in the history
Signed-off-by: Matthis Holleville <matthish29@gmail.com>
  • Loading branch information
matthisholleville committed Mar 31, 2023
1 parent 9aa0e89 commit 975813d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/filters/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ var addCmd = &cobra.Command{
// Verify filter exist
invalidFilters := []string{}
for _, f := range filters {
if f == "" {
color.Red("Filter cannot be empty. Please use correct syntax.")
os.Exit(1)
}
foundFilter := false
for _, filter := range analyzer.ListFilters() {
if filter == f {
Expand Down
8 changes: 8 additions & 0 deletions cmd/filters/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ var removeCmd = &cobra.Command{
defaultFilters = []string{}
}

// Check if input filters is not empty
for _, f := range filters {
if f == "" {
color.Red("Filter cannot be empty. Please use correct syntax.")
os.Exit(1)
}
}

// verify dupplicate filters example: k8sgpt filters remove Pod Pod
uniqueFilters, dupplicatedFilters := util.RemoveDuplicates(filters)
if len(dupplicatedFilters) != 0 {
Expand Down

0 comments on commit 975813d

Please sign in to comment.