From bd6dd558a93f6bd32818bcf996deca89eb2f134d Mon Sep 17 00:00:00 2001 From: Fabio Gollinucci Date: Mon, 8 Mar 2021 22:28:13 +0100 Subject: [PATCH] Remove unused name filter --- cmd/logs/logs.go | 5 ---- internal/canary/canary.go | 3 +++ internal/config/input.go | 49 --------------------------------------- 3 files changed, 3 insertions(+), 54 deletions(-) diff --git a/cmd/logs/logs.go b/cmd/logs/logs.go index 0835ec9..20c4250 100644 --- a/cmd/logs/logs.go +++ b/cmd/logs/logs.go @@ -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...]", diff --git a/internal/canary/canary.go b/internal/canary/canary.go index 1439e76..86326d7 100644 --- a/internal/canary/canary.go +++ b/internal/canary/canary.go @@ -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 } diff --git a/internal/config/input.go b/internal/config/input.go index d7d78c5..bba4cd4 100644 --- a/internal/config/input.go +++ b/internal/config/input.go @@ -3,7 +3,6 @@ package config import ( "errors" "fmt" - "path/filepath" "github.com/AlecAivazis/survey/v2" "github.com/aws/aws-sdk-go/service/synthetics" @@ -11,24 +10,6 @@ import ( "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{} @@ -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 @@ -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