(subcommands []string)
| 187 | } |
| 188 | |
| 189 | func generateRuleSuggestions(subcommands []string) []string { |
| 190 | var suggestions []string |
| 191 | seen := map[string]bool{} |
| 192 | for _, sub := range subcommands { |
| 193 | prefix := GetSimpleCommandPrefix(sub) |
| 194 | if prefix != "" && !seen[prefix] { |
| 195 | seen[prefix] = true |
| 196 | suggestions = append(suggestions, fmt.Sprintf("Bash(%s:*)", prefix)) |
| 197 | if len(suggestions) >= MaxSuggestedRulesForCompound { |
| 198 | return suggestions |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | if len(suggestions) != 0 { |
| 203 | return suggestions |
| 204 | } |
| 205 | for _, sub := range subcommands { |
| 206 | if len(suggestions) >= MaxSuggestedRulesForCompound { |
| 207 | break |
| 208 | } |
| 209 | cleaned := strings.TrimSpace(sub) |
| 210 | if len([]rune(cleaned)) > 80 { |
| 211 | cleaned = firstCommandRunes(cleaned, 77) + "..." |
| 212 | } |
| 213 | if cleaned != "" && !seen[cleaned] { |
| 214 | seen[cleaned] = true |
| 215 | suggestions = append(suggestions, fmt.Sprintf("Bash(%s)", cleaned)) |
| 216 | } |
| 217 | } |
| 218 | return suggestions |
| 219 | } |
| 220 | |
| 221 | func firstCommandRunes(text string, limit int) string { |
| 222 | if limit <= 0 { |
no test coverage detected