mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 04:15:54 +02:00
* cscsli: remove unused Command.Args setting * cscli: review/update argument number checking cscli will consistently print the help text if the number of arguments is wrong for the command, but not for other types of errors. * fix func tests * lint
46 lines
1 KiB
Go
46 lines
1 KiB
Go
package clihubtest
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/args"
|
|
)
|
|
|
|
func (cli *cliHubTest) newEvalCmd() *cobra.Command {
|
|
var evalExpression string
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "eval",
|
|
Short: "eval [test_name]...",
|
|
Args: args.MinimumNArgs(1),
|
|
DisableAutoGenTag: true,
|
|
RunE: func(_ *cobra.Command, args []string) error {
|
|
for _, testName := range args {
|
|
test, err := hubPtr.LoadTestItem(testName)
|
|
if err != nil {
|
|
return fmt.Errorf("can't load test: %+v", err)
|
|
}
|
|
|
|
err = test.ParserAssert.LoadTest(test.ParserResultFile)
|
|
if err != nil {
|
|
return fmt.Errorf("can't load test results from '%s': %+v", test.ParserResultFile, err)
|
|
}
|
|
|
|
output, err := test.ParserAssert.EvalExpression(evalExpression)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Print(output)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.PersistentFlags().StringVarP(&evalExpression, "expr", "e", "", "Expression to eval")
|
|
|
|
return cmd
|
|
}
|