update.go 868 B

12345678910111213141516171819202122232425262728293031323334
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/crowdsecurity/crowdsec/pkg/cwhub"
  5. log "github.com/sirupsen/logrus"
  6. "github.com/spf13/cobra"
  7. )
  8. func NewUpdateCmd() *cobra.Command {
  9. /* ---- UPDATE COMMAND */
  10. var cmdUpdate = &cobra.Command{
  11. Use: "update",
  12. Short: "Fetch available configs from hub",
  13. Long: `
  14. Fetches the [.index.json](https://github.com/crowdsecurity/hub/blob/master/.index.json) file from hub, containing the list of available configs.
  15. `,
  16. Args: cobra.ExactArgs(0),
  17. PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
  18. if !config.configured {
  19. return fmt.Errorf("you must configure cli before interacting with hub.")
  20. }
  21. return nil
  22. },
  23. Run: func(cmd *cobra.Command, args []string) {
  24. if err := cwhub.UpdateHubIdx(); err != nil {
  25. log.Fatalf("Failed to get Hub index : %v", err)
  26. }
  27. },
  28. }
  29. return cmdUpdate
  30. }