Skip to content

Conversation

@james00012
Copy link
Contributor

@james00012 james00012 commented Nov 3, 2025

Summary

Refactors the monolithic commands/cli.go (~800 lines) into focused, modular files for better code organization and maintainability.

Changes

Commands Directory:

  • aws_commands.go (new) - AWS command handlers
  • gcp_commands.go (new) - GCP command handlers
  • flags.go (new) - Reusable flag definitions
  • helpers.go (new) - Shared utility functions
  • cli.go (simplified) - CLI setup only (~100 lines)
  • cli_test.go (updated) - Enhanced tests
  • errors.go (updated) - New structured error types

Supporting:

  • config/config.go - Added ApplyTimeFilters() helper (10 lines)

Notes

  • GCP --resource-type and --exclude-resource-type flags are currently ignored (will be implemented in future PR)
  • Added timeout validation to prevent negative/zero values
  • No functional changes to CLI behavior

Stats: 10 files changed, 963 insertions(+), 755 deletions(-)

@james00012 james00012 requested a review from denis256 as a code owner November 3, 2025 01:52
@james00012 james00012 force-pushed the refactor/commands-directory-only branch 2 times, most recently from dd7bf5c to d809013 Compare November 3, 2025 02:00
This commit refactors the commands directory by:
- Extracting AWS command handlers to aws_commands.go
- Extracting GCP command handlers to gcp_commands.go
- Creating reusable flag helpers in flags.go
- Creating shared helper functions in helpers.go
- Adding new error types to errors.go for better error handling
- Simplifying cli.go to use the new modular structure

Minimal supporting change:
- Added config.ApplyTimeFilters() helper method (10 lines)

These changes improve code organization and maintainability without
changing functionality. All telemetry event names remain as string literals
to keep changes minimal and focused on commands directory structure.
@james00012 james00012 force-pushed the refactor/commands-directory-only branch from d809013 to bdb53e1 Compare November 3, 2025 02:01
Address code review feedback:
- Add documentation noting that GCP --resource-type and --exclude-resource-type
  flags are currently ignored (will be implemented in future PR)
- Add validation to ensure timeout parameter is positive
- Prevents confusing behavior where users expect filtering but get none

// CombineFlags combines multiple flag slices into one
func CombineFlags(flagSets ...[]cli.Flag) []cli.Flag {
var combined []cli.Flag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cibsuder to pre-allocate combined slice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! In this case, CombineFlags is only called during CLI initialization (not in a hot path), and we're combining a small number of flag sets. The performance benefit of pre-allocation would be negligible here, while the two-pass approach adds complexity (e.g., calculating the length and preallocating). I think the simpler, more readable version is better suited for this use case. WDYT?

denis256
denis256 previously approved these changes Nov 3, 2025
- Add TrackCommandLifecycle helper to reduce telemetry boilerplate
- Update all command handlers (awsNuke, awsDefaults, awsInspect, gcpNuke, gcpInspect) to use new helper
- Consolidate parseLogLevel usage in awsDefaults for consistent error handling
- Remove unused logging import from aws_commands.go

This refactoring reduces code duplication and improves maintainability,
making it easier to integrate with OpenTelemetry in the future.
@james00012 james00012 merged commit 617fa9d into master Nov 6, 2025
3 checks passed
@james00012 james00012 deleted the refactor/commands-directory-only branch November 6, 2025 04:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants