Skip to content

fix(cli): reorganize internal CLI packages#115

Merged
Agent-Hellboy merged 3 commits intomainfrom
cli/internal_cli_reorg
May 1, 2026
Merged

fix(cli): reorganize internal CLI packages#115
Agent-Hellboy merged 3 commits intomainfrom
cli/internal_cli_reorg

Conversation

@Agent-Hellboy
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown
Contributor

@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 CLI infrastructure by introducing a core package to centralize shared dependencies, configuration, and utilities, reducing circular dependencies. It also introduces dedicated packages for certmanager, kube, platformstatus, registry, and setup/plan to improve modularity. Several improvements were suggested: replacing global Swap functions with dependency injection to avoid race conditions in tests, using f.Chmod instead of os.Chmod for security, and ensuring all output goes through the centralized core.DefaultPrinter rather than fmt.Print.

Comment thread internal/cli/core/exec.go Outdated
Comment on lines +18 to +22
func SwapExecCommand(f func(string, ...string) *exec.Cmd) (restore func()) {
prev := execCommand
execCommand = f
return func() { execCommand = prev }
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Similar to SwapDefaultKubectlClient, SwapExecCommand modifies a global variable execCommand, leading to race conditions in parallel tests. This pattern should be avoided in favor of dependency injection through struct fields or context.

Comment thread internal/cli/kube/file.go Outdated
Comment on lines +41 to +46
if err := f.Close(); err != nil {
return fmt.Errorf("write output file: %w", err)
}
if err := os.Chmod(absPath, 0o600); err != nil {
return fmt.Errorf("write output file: %w", err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using os.Chmod on a file path after closing it is less secure and less efficient than using f.Chmod on the open file descriptor. os.Chmod follows symbolic links and is subject to race conditions if the file is replaced between the close and chmod operations. Since you have an open file handle f, use f.Chmod(0o600) before closing it.

Suggested change
if err := f.Close(); err != nil {
return fmt.Errorf("write output file: %w", err)
}
if err := os.Chmod(absPath, 0o600); err != nil {
return fmt.Errorf("write output file: %w", err)
}
if err := f.Chmod(0o600); err != nil {
_ = f.Close()
return fmt.Errorf("write output file: %w", err)
}
if err := f.Close(); err != nil {
return fmt.Errorf("write output file: %w", err)
}

Comment thread internal/cli/cluster/manager.go Outdated
if dryRun {
core.Info(fmt.Sprintf("[dry-run] would write kind config and run: kind create cluster --name %s --config <tmp.yaml>", clusterName))
core.Info("[dry-run] kind config that would be written:")
fmt.Print(config)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using fmt.Print directly bypasses the centralized CLI printer and its configuration (e.g., quiet mode, output redirection). For consistency with other output in this package, use core.DefaultPrinter.Println(config).

Suggested change
fmt.Print(config)
core.DefaultPrinter.Println(config)

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec08cb1fac

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cmd/mcp-runtime/main.go Outdated
// Runtime errors should not trigger Cobra's usage/help dump; flag/arg
// validation errors still do (those happen before RunE). main() prints
// the error itself, so silence Cobra's own error print to avoid duplicates.
SilenceUsage: true,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep usage output enabled for CLI validation failures

Setting SilenceUsage: true on the root command suppresses usage text for all subcommands, including flag/arg validation failures (e.g., missing required flags), because Cobra checks the root command's SilenceUsage before printing cmd.UsageString(). This regresses CLI ergonomics compared to prior behavior and contradicts the comment above this field; users now get only Error: ... without command-specific guidance when they make common input mistakes.

Useful? React with 👍 / 👎.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

❌ Patch coverage is 48.81731% with 1017 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.16%. Comparing base (d7b3cbd) to head (b9cd29c).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
internal/cli/server/manager.go 33.05% 75 Missing and 6 partials ⚠️
internal/cli/registry/manager.go 61.76% 73 Missing and 5 partials ⚠️
internal/cli/certmanager/letsencrypt.go 1.44% 68 Missing ⚠️
internal/cli/cluster/manager.go 60.00% 46 Missing and 8 partials ⚠️
internal/cli/platformstatus/workloads.go 0.00% 54 Missing ⚠️
internal/cli/pipeline/deploy.go 42.85% 44 Missing and 4 partials ⚠️
internal/cli/kube/patch.go 22.03% 44 Missing and 2 partials ⚠️
internal/cli/kube/manifest.go 36.23% 35 Missing and 9 partials ⚠️
internal/cli/access/manager.go 17.30% 42 Missing and 1 partial ⚠️
internal/cli/certmanager/manager.go 73.61% 35 Missing and 3 partials ⚠️
... and 31 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #115      +/-   ##
==========================================
- Coverage   51.64%   49.16%   -2.48%     
==========================================
  Files          72       86      +14     
  Lines       10679    10998     +319     
==========================================
- Hits         5515     5407     -108     
- Misses       4580     5011     +431     
+ Partials      584      580       -4     
Flag Coverage Δ
pre-merge 49.16% <48.81%> (-2.48%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/cli/access/validation.go 100.00% <100.00%> (ø)
internal/cli/core/config.go 89.04% <ø> (ø)
internal/cli/core/errors.go 23.94% <ø> (ø)
internal/cli/core/printer.go 77.30% <ø> (ø)
internal/cli/kubeerr/kubeerr.go 100.00% <100.00%> (ø)
internal/cli/platformapi/baseurl.go 100.00% <100.00%> (ø)
internal/cli/registry/ref/ref.go 100.00% <100.00%> (ø)
internal/cli/root/commands.go 100.00% <100.00%> (ø)
internal/cli/server/validation.go 100.00% <100.00%> (ø)
internal/cli/setup/assetpath/paths.go 59.45% <100.00%> (ø)
... and 44 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Agent-Hellboy Agent-Hellboy merged commit 2fc409a into main May 1, 2026
13 checks passed
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.

1 participant