crowdsec/cmd/crowdsec-cli/clihubtest/list.go
mmetc 57539f61b4
refact cscli - don't export functions if not required (#3224)
* unexport subcommand constructors

* unexport internal methods

* lint + rename local variables
2024-09-11 15:38:15 +02:00

42 lines
845 B
Go

package clihubtest
import (
"encoding/json"
"errors"
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
)
func (cli *cliHubTest) newListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "list",
DisableAutoGenTag: true,
RunE: func(_ *cobra.Command, _ []string) error {
cfg := cli.cfg()
if err := hubPtr.LoadAllTests(); err != nil {
return fmt.Errorf("unable to load all tests: %w", err)
}
switch cfg.Cscli.Output {
case "human":
hubTestListTable(color.Output, cfg.Cscli.Color, hubPtr.Tests)
case "json":
j, err := json.MarshalIndent(hubPtr.Tests, " ", " ")
if err != nil {
return err
}
fmt.Println(string(j))
default:
return errors.New("only human/json output modes are supported")
}
return nil
},
}
return cmd
}