-
-
Notifications
You must be signed in to change notification settings - Fork 374
refactor: reorganize commands directory for better code organization #958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
dd7bf5c to
d809013
Compare
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.
d809013 to
bdb53e1
Compare
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
- 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.
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 handlersgcp_commands.go(new) - GCP command handlersflags.go(new) - Reusable flag definitionshelpers.go(new) - Shared utility functionscli.go(simplified) - CLI setup only (~100 lines)cli_test.go(updated) - Enhanced testserrors.go(updated) - New structured error typesSupporting:
config/config.go- AddedApplyTimeFilters()helper (10 lines)Notes
--resource-typeand--exclude-resource-typeflags are currently ignored (will be implemented in future PR)Stats: 10 files changed, 963 insertions(+), 755 deletions(-)