mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-10 20:05:55 +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
41 lines
804 B
Go
41 lines
804 B
Go
package clilapi
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
|
)
|
|
|
|
type configGetter = func() *csconfig.Config
|
|
|
|
type cliLapi struct {
|
|
cfg configGetter
|
|
}
|
|
|
|
func New(cfg configGetter) *cliLapi {
|
|
return &cliLapi{
|
|
cfg: cfg,
|
|
}
|
|
}
|
|
|
|
func (cli *cliLapi) NewCommand() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "lapi [action]",
|
|
Short: "Manage interaction with Local API (LAPI)",
|
|
DisableAutoGenTag: true,
|
|
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
|
|
if err := cli.cfg().LoadAPIClient(); err != nil {
|
|
return fmt.Errorf("loading api client: %w", err)
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.AddCommand(cli.newRegisterCmd())
|
|
cmd.AddCommand(cli.newStatusCmd())
|
|
cmd.AddCommand(cli.newContextCmd())
|
|
|
|
return cmd
|
|
}
|