Skip to content

Commit 79d2b50

Browse files
[fp-enhancer] Improve pkg/cli: use sliceutil.Filter/Map for functional slice operations (#19705)
1 parent 740f35b commit 79d2b50

3 files changed

Lines changed: 9 additions & 17 deletions

File tree

pkg/cli/audit_report_analysis.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ func generateFindings(processedRun ProcessedRun, metrics MetricsData, errors []E
105105

106106
// Missing tool findings
107107
if len(processedRun.MissingTools) > 0 {
108-
toolNames := make([]string, 0, min(3, len(processedRun.MissingTools)))
109-
for i := 0; i < len(processedRun.MissingTools) && i < 3; i++ {
110-
toolNames = append(toolNames, processedRun.MissingTools[i].Tool)
111-
}
108+
toolNames := sliceutil.Map(processedRun.MissingTools[:min(3, len(processedRun.MissingTools))], func(t MissingToolReport) string { return t.Tool })
112109
desc := "Missing tools: " + strings.Join(toolNames, ", ")
113110
if len(processedRun.MissingTools) > 3 {
114111
desc += fmt.Sprintf(" (and %d more)", len(processedRun.MissingTools)-3)

pkg/cli/firewall_log.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/github/gh-aw/pkg/console"
1414
"github.com/github/gh-aw/pkg/logger"
15+
"github.com/github/gh-aw/pkg/sliceutil"
1516
)
1617

1718
var firewallLogLog = logger.New("cli:firewall_log")
@@ -352,14 +353,11 @@ func analyzeFirewallLogs(runDir string, verbose bool) (*FirewallAnalysis, error)
352353
}
353354

354355
// Filter for firewall log files (they typically have "access" or "firewall" in the name)
355-
var firewallLogs []string
356-
for _, file := range files {
356+
firewallLogs := sliceutil.Filter(files, func(file string) bool {
357357
basename := filepath.Base(file)
358-
if strings.Contains(basename, "firewall") ||
359-
(strings.Contains(basename, "access") && !strings.Contains(basename, "access-")) {
360-
firewallLogs = append(firewallLogs, file)
361-
}
362-
}
358+
return strings.Contains(basename, "firewall") ||
359+
(strings.Contains(basename, "access") && !strings.Contains(basename, "access-"))
360+
})
363361

364362
if len(firewallLogs) == 0 {
365363
firewallLogLog.Print("No firewall logs found")

pkg/cli/mcp_list_tools.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,9 @@ func completeMCPListToolsArgs(cmd *cobra.Command, args []string, toComplete stri
210210
// First argument: MCP server names are not easily discoverable without a workflow
211211
// For now, provide no file completion but suggest common server names
212212
if len(args) == 0 {
213-
var filtered []string
214-
for _, s := range commonMCPServerNames {
215-
if toComplete == "" || strings.HasPrefix(s, toComplete) {
216-
filtered = append(filtered, s)
217-
}
218-
}
213+
filtered := sliceutil.Filter(commonMCPServerNames, func(s string) bool {
214+
return toComplete == "" || strings.HasPrefix(s, toComplete)
215+
})
219216
return filtered, cobra.ShellCompDirectiveNoFileComp
220217
}
221218
// Second argument: complete workflow names

0 commit comments

Comments
 (0)