Skip to content

Bug: user defined commands not appearing in usage#16

Merged
8bitAlex merged 7 commits intomainfrom
more-beta-bug-fixes
Mar 16, 2026
Merged

Bug: user defined commands not appearing in usage#16
8bitAlex merged 7 commits intomainfrom
more-beta-bug-fixes

Conversation

@8bitAlex
Copy link
Copy Markdown
Owner

This pull request introduces a new mechanism for registering user-defined commands from the active profile into the CLI, along with comprehensive tests to ensure correct behavior. The main focus is on improving extensibility and reliability of command registration, especially for user commands and their visibility in help output.

User command registration improvements:

  • Added a new registerUserCommands function to src/cmd/raid.go that dynamically registers user-defined commands from the active profile to the root command, skipping reserved built-in names with a warning.
  • Modified the command initialization logic in src/cmd/raid.go to ensure user commands are registered regardless of command type (info or regular), improving consistency and visibility.

Testing enhancements:

  • Introduced multiple tests in src/cmd/raid_test.go to verify user command registration, including checks for empty profiles, reserved name handling, help output visibility, and regression tests for all invocation types.
  • Added utility functions to src/cmd/raid_test.go for test setup and help output capture, facilitating robust testing of command registration.

Testability improvements in core library:

  • Added GetContext and SetContext functions in src/internal/lib/lib.go to allow manipulation of the active context during tests, enabling more reliable and isolated test scenarios.

Copilot AI review requested due to automatic review settings March 16, 2026 21:09
Copy link
Copy Markdown
Contributor

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 aims to fix a CLI usability bug where user-defined profile commands were not being registered early enough to appear in raid help/usage output, by introducing centralized user-command registration and adding tests around that behavior.

Changes:

  • Adds registerUserCommands to dynamically attach profile-defined commands to the Cobra root command (skipping reserved built-in names with a warning).
  • Adjusts CLI initialization to register user commands for all invocation types (including info/help flows).
  • Adds tests for user command registration/help visibility and introduces lib.GetContext/lib.SetContext to simplify test setup.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/cmd/raid.go Registers user-defined commands on the root Cobra command before execution; changes initialization timing.
src/cmd/raid_test.go Adds unit tests/helpers for user command registration and help output assertions.
src/internal/lib/lib.go Exposes context getters/setters to support test isolation by swapping the active context.

Comment thread src/internal/lib/lib.go Outdated
Comment on lines +41 to +45
// GetContext returns the active context. Intended for use in tests.
func GetContext() *Context { return context }

// SetContext replaces the active context. Intended for use in tests.
func SetContext(c *Context) { context = c }
Comment thread src/cmd/raid.go
Comment on lines 84 to 86
applyConfigFlag(os.Args)
if !info {
raid.Initialize()
}
raid.Initialize()

Comment thread src/cmd/raid_test.go Outdated
Comment on lines +190 to +204
// Regression: user commands must appear in help output for every invocation
// type, including info commands (no args, --help, help) and unknown commands.
func TestRegisterUserCommands_visibleForAllInvocationTypes(t *testing.T) {
withCommands(t, []lib.Command{{Name: "build", Usage: "Build services"}})

invocations := []string{"(no args)", "--help", "help", "unknown-cmd"}
for _, inv := range invocations {
t.Run(inv, func(t *testing.T) {
root := newTestRoot()
registerUserCommands(root)
if !strings.Contains(helpOutput(root), "build") {
t.Errorf("'build' command missing from help output for invocation %q", inv)
}
})
}
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 12.00000% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.41%. Comparing base (c751ede) to head (63a384f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/cmd/raid.go 27.27% 8 Missing ⚠️
src/internal/lib/config.go 0.00% 6 Missing ⚠️
src/internal/lib/lib.go 0.00% 6 Missing ⚠️
src/raid/raid.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #16      +/-   ##
==========================================
- Coverage   72.78%   72.41%   -0.38%     
==========================================
  Files          27       27              
  Lines        1459     1479      +20     
==========================================
+ Hits         1062     1071       +9     
- Misses        358      368      +10     
- Partials       39       40       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@8bitAlex 8bitAlex merged commit 419e2e9 into main Mar 16, 2026
5 of 7 checks passed
@8bitAlex 8bitAlex deleted the more-beta-bug-fixes branch March 16, 2026 21:27
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.

2 participants