Skip to content

Commit

Permalink
Remove unused name filter
Browse files Browse the repository at this point in the history
  • Loading branch information
daaru00 committed Mar 8, 2021
1 parent c3dbcfe commit bd6dd55
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 54 deletions.
5 changes: 0 additions & 5 deletions cmd/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ func NewCommand(globalFlags []cli.Flag) *cli.Command {
Aliases: []string{"l"},
Usage: "Automatically select last canary run",
},
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Usage: "Filter canary name",
},
}...),
Action: Action,
ArgsUsage: "[path...]",
Expand Down
3 changes: 3 additions & 0 deletions internal/canary/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func (c *Canary) GetFlatTags(separator string) *string {

// Iterate over tags and concatenated them
for _, value := range c.Tags {
if len(value) == 0 {
continue
}
if len(flat) != 0 {
flat += separator
}
Expand Down
49 changes: 0 additions & 49 deletions internal/config/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,13 @@ package config
import (
"errors"
"fmt"
"path/filepath"

"github.com/AlecAivazis/survey/v2"
"github.com/aws/aws-sdk-go/service/synthetics"
"github.com/daaru00/aws-canary-cli/internal/canary"
"github.com/urfave/cli/v2"
)

// FilterCanariesByName filter canaries by name flag
func FilterCanariesByName(canaries *[]*canary.Canary, names *[]string) []*canary.Canary {
selectedCanaries := []*canary.Canary{}

// Check for provided canaries name
for _, canary := range *canaries {
for _, name := range *names {
match, _ := filepath.Match(name, canary.Name)
if match {
selectedCanaries = append(selectedCanaries, canary)
break
}
}
}

return selectedCanaries
}

// AskMultipleCanariesSelection ask user to select multiple canaries
func AskMultipleCanariesSelection(c *cli.Context, canaries []*canary.Canary) (*[]*canary.Canary, error) {
selectedCanaries := []*canary.Canary{}
Expand All @@ -43,19 +24,6 @@ func AskMultipleCanariesSelection(c *cli.Context, canaries []*canary.Canary) (*[
return &canaries, nil
}

// Check for provided canaries name
names := c.StringSlice("name")
if len(c.StringSlice("name")) > 0 {
selectedCanaries = FilterCanariesByName(&canaries, &names)

// Check if at least one canary was found
if len(selectedCanaries) == 0 {
return &selectedCanaries, errors.New("Cannot find any canaries that match provided name filters")
}

return &selectedCanaries, nil
}

// Build table
header := fmt.Sprintf("%-25s\t%-20s", "Name", "Tags")
var options []string
Expand Down Expand Up @@ -88,28 +56,11 @@ func AskMultipleCanariesSelection(c *cli.Context, canaries []*canary.Canary) (*[

// AskSingleCanarySelection ask user to select canaries
func AskSingleCanarySelection(c *cli.Context, canaries []*canary.Canary) (*canary.Canary, error) {
selectedCanaries := []*canary.Canary{}

// Check if single canary
if len(canaries) == 1 {
return canaries[0], nil
}

// Check for provided canaries name
name := c.String("name")
if len(c.String("name")) > 0 {
selectedCanaries = FilterCanariesByName(&canaries, &[]string{
name,
})

// Check if a canary was found
if len(selectedCanaries) == 0 {
return nil, errors.New("Cannot find canary that match provided name filter")
}

return selectedCanaries[0], nil
}

// Build table
header := fmt.Sprintf("%-25s\t%-20s", "Name", "Tags")
var options []string
Expand Down

0 comments on commit bd6dd55

Please sign in to comment.