Skip to content

feat: Add app-level fields - #11

Merged
taran-p merged 2 commits into
minio:masterfrom
taran-p:feat/globals
Aug 18, 2026
Merged

feat: Add app-level fields#11
taran-p merged 2 commits into
minio:masterfrom
taran-p:feat/globals

Conversation

@taran-p

@taran-p taran-p commented Jul 23, 2026

Copy link
Copy Markdown

In mc we have many places with boilerplate that could be fixed by app-level defaults. This PR adds customizable app level default and globals:

  • Default Before and After functions - run before/after each command invocation unless the Before/After is set by the command. In mc, Before is the same for all commands.
  • Default OnUsageError - runs on any command when an invalid flag is used unless set by commands. In mc, OnUsageError is the same for all commands
  • Default Action - runs on any command with nil error, useful for running the same command for all parent commands
  • Global HideHelp/HideHelpCommand - hides help flag/help subcommand across app. In mc, HideHelpCommand is true for all relevant commands.
  • GlobalFlags - A set of flags that can be used by any command. In mc, we have globalFlags that must be manually added or appended to the command flags.

This PR is a breaking change as it changes Action to an ActionFunc, which has been pending since 2016.

The net effect of this PR can be seen here https://github.com/miniohq/ec/pull/597 - removal of 1400 lines of boilerplate and alignment of several commands to the project standard

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@taran-p, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 39 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 938e9abf-bbe9-4288-89b9-02d52cf1f289

📥 Commits

Reviewing files that changed from the base of the PR and between ff2a793 and d9a13b8.

📒 Files selected for processing (3)
  • .github/workflows/go.yml
  • command.go
  • go.mod
📝 Walkthrough

Walkthrough

The change replaces untyped action dispatch with ActionFunc, centralizes app and command resolution for actions, hooks, help visibility, and flags, and adds filtered global-flag data to help templates. Tests now invoke typed actions directly and verify global-flag visibility.

Changes

Typed action and resolution pipeline

Layer / File(s) Summary
App action and default resolution
app.go, app_test.go, .gitignore
App execution uses typed actions and centralized default hooks/help visibility; legacy HandleAction validation tests are removed, and IDE directories are ignored.
Command execution and nested app wiring
command.go
Commands resolve actions, hooks, flags, and help visibility before wiring nested app execution, and expose filtered global flags.
Global-flag help rendering and validation
help.go, help_test.go
Help templates receive permitted global flags, with tests covering hidden and excluded flags and direct typed action invocation.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Command
  participant App
  participant HelpTemplate
  User->>Command: execute command
  Command->>App: pass resolved action, hooks, and flags
  App->>App: run before hook and action
  App-->>Command: return result or error
  Command->>HelpTemplate: provide visible local and global flags
  HelpTemplate-->>User: render command help
Loading

Poem

I’m a rabbit with a typed little track,
Hooks and actions all hop in a stack.
Global flags peek through help’s bright door,
Hidden ones vanish from view evermore.
ActionFunc goes thump-thump—
Clean paths make this bunny jump!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main theme of the PR: adding app-level fields and defaults.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app.go`:
- Line 235: Update the fmt.Fprintf call in the error-reporting path to
explicitly discard its returned values, satisfying errcheck while preserving the
existing output and control flow.

In `@command.go`:
- Around line 405-417: Update VisibleFlags to copy c.Flags into a new slice
before appending c.globalFlags and HelpFlag, preventing mutation of the caller’s
backing array; follow the existing resolveFlags approach. Also verify whether
the c.HideHelp check should account for GlobalHideHelp despite the lack of ctx,
preserving the intended built-in help visibility behavior.
- Around line 398-403: Update resolveFlags and VisibleFlags to copy the
command's existing flags into a new slice before appending global flags.
Preserve the current NoGlobalFlags behavior and returned flag ordering while
ensuring neither method can mutate the caller's Command.Flags backing array.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: bca1a944-02a0-409d-b13e-40f0d64c10db

📥 Commits

Reviewing files that changed from the base of the PR and between bc9585b and ff2a793.

📒 Files selected for processing (6)
  • .gitignore
  • app.go
  • app_test.go
  • command.go
  • help.go
  • help_test.go

Comment thread app.go
Comment thread command.go
Comment thread command.go
@taran-p

taran-p commented Jul 27, 2026

Copy link
Copy Markdown
Author

@harshavardhana When you get a chance can you take a look? Some alignment work for mc

@taran-p
taran-p merged commit d065061 into minio:master Aug 18, 2026
2 checks passed
@taran-p
taran-p deleted the feat/globals branch August 18, 2026 16:18
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