Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mikebz
Copy link
Contributor

@mikebz mikebz commented Jun 15, 2025

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 the bugreport, hydrate, and initialize 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.

@mikebz mikebz requested a review from Copilot June 15, 2025 04:39
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from mikebz. For more information see the Kubernetes Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot

This comment was marked as outdated.

@mikebz mikebz requested a review from Copilot June 16, 2025 00:27
Copilot

This comment was marked as outdated.

@mikebz mikebz requested a review from Copilot June 16, 2025 03:44
Copilot

This comment was marked as outdated.

@mikebz mikebz requested a review from Copilot June 16, 2025 04:13
Copilot

This comment was marked as outdated.

@mikebz
Copy link
Contributor Author

mikebz commented Jun 19, 2025

/ok-to-test

@mikebz mikebz requested a review from Copilot June 19, 2025 20:05
Copilot

This comment was marked as outdated.

@mikebz mikebz marked this pull request as ready for review June 19, 2025 21:28
@google-oss-prow google-oss-prow bot requested a review from Camila-B June 19, 2025 21:28
@mikebz
Copy link
Contributor Author

mikebz commented Jun 19, 2025

/label tide/merge-method-squash

@google-oss-prow google-oss-prow bot added the tide/merge-method-squash Use squash on submit label Jun 19, 2025
@mikebz
Copy link
Contributor Author

mikebz commented Jun 24, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copilot

This comment was marked as outdated.

Copy link

@Copilot Copilot AI left a 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

Comment on lines +22 to +27
func init() {
// Initialize flags for the version command
// This separation keeps flag definitions isolated from command execution logic
flags.AddClientTimeout(Cmd)
}

Copy link
Preview

Copilot AI Aug 1, 2025

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.

Suggested change
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)
Copy link
Preview

Copilot AI Aug 1, 2025

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.

Suggested change
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
Copy link
Preview

Copilot AI Aug 1, 2025

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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants