-
Notifications
You must be signed in to change notification settings - Fork 49
refactored the nomos commands for better separation of concerns #1742
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
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/ok-to-test |
/label tide/merge-method-squash |
/gemini review |
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.
Code Review
This pull request refactors the nomos commands for better separation of concerns. The changes introduce separate execution logic, flag handling, and parameter encapsulation for the bugreport
, hydrate
, and initialize
commands. Additionally, redundant code is removed, and shared functionality is centralized. Overall, the changes look good and improve the modularity and maintainability of the code.
cmd/nomos/bugreport/bugreport.go
Outdated
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.
I'd really prefer if these changes preserved the git history - could this be refactored in a way that is more surgical? That would also make review easier
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.
the initial refactor was done with an LLM. I think if someone wants to restart this they will probably going to need to take this over, but I am OK either way.
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.
Pull Request Overview
This PR refactors the nomos
command structure by separating business logic from Cobra command dependencies, enabling better modularity and testability. The refactoring decouples command execution logic from CLI framework specifics, making it easier to unit test the core functionality.
- Introduces separate execution logic, flag handling, and parameter encapsulation for multiple commands
- Creates new
exec.go
files containing framework-independent execution functions - Centralizes flag definitions in dedicated
flags.go
files for better organization
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
cmd/nomos/vet/flags.go | Creates structured flag management with default values and centralized flag definitions |
cmd/nomos/vet/exec.go | Extracts core vet logic into framework-independent execution function |
cmd/nomos/vet/cmd.go | Refactors command definition to use new execution pattern |
cmd/nomos/version/exec.go | Creates framework-independent version command execution logic |
cmd/nomos/version/cmd.go | Refactors version command to use new execution pattern |
cmd/nomos/status/flags.go | Introduces structured flag management for status command |
cmd/nomos/status/exec.go | Extracts status logic into framework-independent execution function |
cmd/nomos/status/cmd.go | Refactors status command to use new execution pattern |
cmd/nomos/initialize/flags.go | Creates structured flag management for initialize command |
cmd/nomos/initialize/exec.go | Extracts initialize logic into framework-independent execution function |
cmd/nomos/initialize/cmd.go | Refactors initialize command to use new execution pattern |
cmd/nomos/hydrate/flags.go | Creates structured flag management for hydrate command |
cmd/nomos/hydrate/exec.go | Extracts hydrate logic into framework-independent execution function |
cmd/nomos/hydrate/cmd.go | Refactors hydrate command to use new execution pattern |
cmd/nomos/bugreport/exec.go | Creates framework-independent bugreport execution logic |
cmd/nomos/bugreport/cmd.go | Refactors bugreport command to use new execution pattern |
func init() { | ||
// Initialize flags for the version command | ||
// This separation keeps flag definitions isolated from command execution logic | ||
flags.AddClientTimeout(Cmd) | ||
} | ||
|
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.
[nitpick] The init() function should be placed after the Cmd variable declaration for better code organization and readability, following Go conventions where init functions typically appear at the end of files.
func init() { | |
// Initialize flags for the version command | |
// This separation keeps flag definitions isolated from command execution logic | |
flags.AddClientTimeout(Cmd) | |
} |
Copilot uses AI. Check for mistakes.
func init() { | ||
// Initialize flags for the version command | ||
// This separation keeps flag definitions isolated from command execution logic | ||
flags.AddClientTimeout(Cmd) |
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.
The function call should be flags.AddContexts(Cmd)
instead of flags.AddClientTimeout(Cmd)
to maintain consistency with the original version command that adds context flags.
flags.AddClientTimeout(Cmd) | |
flags.AddContexts(Cmd) |
Copilot uses AI. Check for mistakes.
@@ -350,7 +350,7 @@ func TestRepoState_PrintRows(t *testing.T) { | |||
for _, tc := range testCases { | |||
t.Run(tc.name, func(t *testing.T) { | |||
var buffer bytes.Buffer | |||
tc.repo.printRows(&buffer) | |||
tc.repo.printRows(&buffer, true) // Enable resource status for tests |
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.
The printRows method signature has changed to accept two parameters (nameFilter and showResourceStatus), but this call only passes one parameter. It should be tc.repo.printRows(&buffer, "", true)
to match the new signature.
tc.repo.printRows(&buffer, true) // Enable resource status for tests | |
tc.repo.printRows(&buffer, "", true) // Enable resource status for tests |
Copilot uses AI. Check for mistakes.
This pull request refactors the
nomos
command structure by decoupling business logic from Cobra command dependencies, improving modularity and maintainability. The changes introduce separate execution logic, flag handling, and parameter encapsulation for thebugreport
,hydrate
, andinitialize
commands. Additionally, redundant code is removed, and shared functionality is centralized.This is the first step in the attempt to move more testing from e2e to unit tests.