diff --git a/cmd/crowdsec-cli/item_suggest.go b/cmd/crowdsec-cli/item_suggest.go index e9db3b7b9df..af7211e8017 100644 --- a/cmd/crowdsec-cli/item_suggest.go +++ b/cmd/crowdsec-cli/item_suggest.go @@ -12,10 +12,10 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/cwhub" ) -const MaxDistance = 7 +// suggestNearestMessage returns a message with the most similar item name, if one is found +func suggestNearestMessage(hub *cwhub.Hub, itemType string, itemName string) string { + const maxDistance = 7 -// SuggestNearestMessage returns a message with the most similar item name, if one is found -func SuggestNearestMessage(hub *cwhub.Hub, itemType string, itemName string) string { score := 100 nearest := "" @@ -29,7 +29,7 @@ func SuggestNearestMessage(hub *cwhub.Hub, itemType string, itemName string) str msg := fmt.Sprintf("can't find '%s' in %s", itemName, itemType) - if score < MaxDistance { + if score < maxDistance { msg += fmt.Sprintf(", did you mean '%s'?", nearest) } diff --git a/cmd/crowdsec-cli/itemcommands.go b/cmd/crowdsec-cli/itemcommands.go index 6b9476d024f..b4007830e6c 100644 --- a/cmd/crowdsec-cli/itemcommands.go +++ b/cmd/crowdsec-cli/itemcommands.go @@ -214,7 +214,7 @@ func itemsInstallRunner(it hubItemType) func(cmd *cobra.Command, args []string) for _, name := range args { item := hub.GetItem(it.name, name) if item == nil { - msg := SuggestNearestMessage(hub, it.name, name) + msg := suggestNearestMessage(hub, it.name, name) if !ignoreError { return fmt.Errorf(msg) } diff --git a/cmd/crowdsec-cli/utils.go b/cmd/crowdsec-cli/utils.go index eb7fb51e02e..362a8942f71 100644 --- a/cmd/crowdsec-cli/utils.go +++ b/cmd/crowdsec-cli/utils.go @@ -13,14 +13,12 @@ import ( ) func printHelp(cmd *cobra.Command) { - err := cmd.Help() - if err != nil { + if err := cmd.Help(); err != nil { log.Fatalf("unable to print help(): %s", err) } } func manageCliDecisionAlerts(ip *string, ipRange *string, scope *string, value *string) error { - /*if a range is provided, change the scope*/ if *ipRange != "" { _, _, err := net.ParseCIDR(*ipRange) @@ -50,7 +48,6 @@ func manageCliDecisionAlerts(ip *string, ipRange *string, scope *string, value * } func getDBClient() (*database.Client, error) { - var err error if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI { return nil, err }