$ show ahmetb/kubectl-foreach
kubectl-foreach is a Go-based CLI tool designed to run kubectl commands against multiple Kubernetes contexts in parallel. It retrieves context lists from kubeconfig, applies user-defined filters (exact match, regex, exclusion) to select target contexts, executes the provided kubectl command concurrently for each context, and prefixes output lines with context names for clarity. The architecture is monolithic with clear separation of concerns: argument parsing, filtering, context matching, and parallel execution are isolated into distinct modules. Key dependencies include kubectl (for context retrieval and command execution) and third-party libraries for colored output (gchalk), testing (testify), and concurrency management (golang.org/x/sync).
The LLM identified 3 files worth highlighting for reuse:
Separates command-line arguments into tool arguments and subcommand arguments using '--' as a delimiter. Isolated, dependency-free, and reusable in any CLI tool requiring this pattern.
Parses filter strings (exact match, regex, exclusion) into a filter interface. Self-contained with no internal dependencies, demonstrating clean string filtering logic applicable to any list-filtering scenario.
Provides synchronized and prefixing writers for safe, prefixed concurrent output from multiple goroutines. Reusable in any concurrent program needing to avoid output interleaving and add contextual prefixes.