Merge pull request #449 from cloudskiff/fix/filterFlagRepeat
Enforce one occurrence of filter flagmain
commit
7a52ef3e90
|
@ -60,9 +60,14 @@ func NewScanCmd() *cobra.Command {
|
|||
}
|
||||
opts.Output = *out
|
||||
|
||||
filterFlag, _ := cmd.Flags().GetString("filter")
|
||||
if filterFlag != "" {
|
||||
expr, err := filter.BuildExpression(filterFlag)
|
||||
filterFlag, _ := cmd.Flags().GetStringArray("filter")
|
||||
|
||||
if len(filterFlag) > 1 {
|
||||
return errors.New("Filter flag should be specified only once")
|
||||
}
|
||||
|
||||
if len(filterFlag) == 1 && filterFlag[0] != "" {
|
||||
expr, err := filter.BuildExpression(filterFlag[0])
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to parse filter expression")
|
||||
}
|
||||
|
@ -79,16 +84,14 @@ func NewScanCmd() *cobra.Command {
|
|||
}
|
||||
|
||||
fl := cmd.Flags()
|
||||
fl.BoolP(
|
||||
fl.Bool(
|
||||
"quiet",
|
||||
"",
|
||||
false,
|
||||
"Do not display anything but scan results",
|
||||
)
|
||||
fl.StringP(
|
||||
fl.StringArray(
|
||||
"filter",
|
||||
"",
|
||||
"",
|
||||
[]string{},
|
||||
"JMESPath expression to filter on\n"+
|
||||
"Examples : \n"+
|
||||
" - Type == 'aws_s3_bucket' (will filter only s3 buckets)\n"+
|
||||
|
|
|
@ -78,6 +78,7 @@ func TestScanCmd_Invalid(t *testing.T) {
|
|||
{args: []string{"scan", "--from", "tfstate+foobar://test"}, expected: "Unsupported IaC backend 'foobar': \nAccepted values are: s3,http,https"},
|
||||
{args: []string{"scan", "--from", "tfstate:///tmp/test", "--from", "tfstate+toto://test"}, expected: "Unsupported IaC backend 'toto': \nAccepted values are: s3,http,https"},
|
||||
{args: []string{"scan", "--filter", "Type='test'"}, expected: "unable to parse filter expression: SyntaxError: Expected tRbracket, received: tUnknown"},
|
||||
{args: []string{"scan", "--filter", "Type='test'", "--filter", "Type='test2'"}, expected: "Filter flag should be specified only once"},
|
||||
}
|
||||
|
||||
for _, tt := range cases {
|
||||
|
|
Loading…
Reference in New Issue