Skip to content

Allow ModifyCobra to modify subcommands#5

Merged
stefanvanburen merged 1 commit intomainfrom
modify-cobra
Mar 19, 2026
Merged

Allow ModifyCobra to modify subcommands#5
stefanvanburen merged 1 commit intomainfrom
modify-cobra

Conversation

@stefanvanburen
Copy link
Member

As written, ModifyCobra will only apply to the root command. This fixes this so that a subcommand with a ModifyCobra field will have it applied.

I realize this is a break-glass feature, but currently it's the only way for a command to modify its completions, which I'm looking to modify upstream for things like bufbuild/buf#2044.

It also uses the builtin max as a cleanup; if we end up landing this, I plan to come back here to upgrade this repository.

As written, ModifyCobra will only apply to the root command. This fixes
this so that a subcommand with a ModifyCobra field will have it applied.

I realize this is a break-glass feature, but currently it's the only way
for a command to modify its completions, which I'm looking to modify
upstream for things like bufbuild/buf#2044.

It also uses the builtin `max` as a cleanup; if we end up landing this,
I plan to come back here to upgrade this repository.
stefanvanburen added a commit to bufbuild/buf that referenced this pull request Mar 19, 2026
First mentioned in #2044, which is long something I've wanted. This adds
support for completing URLs based on the available RPCs, which either
comes from the existing `--schema` flag or gRPC reflection.

The completion itself works somewhat similar to LSP completion, in that
it attempts to complete as far as it can before giving the user an
option between the remaining values to disambiguate. It will complete up
to the entire service URL, and then provide completions for RPCs within
the service (if there are multiple).

This requires one fix upstream in app-go so that subcommands that define
`ModifyCobra` actually run: bufbuild/app-go#5. We'll want to land
upstream to `main` before landing this.

Open to suggestions on the completion UX. It feels fairly natural to me
currently, but I'm sure there are edge cases.

Future work here could include better completions for `--schema` values,
either using local directories or BSR modules, and completions for
`--data` values (if we know the schema and the specific RPC targeted by
the URL, we know the shape of the JSON for the `--data` flag). Also,
following this pattern of using ModifyCobra, other commands could be
made to have better contextual completion.

Also fixes the buf curl help examples to have consistent indentation.

Resolves #2044.
@stefanvanburen stefanvanburen marked this pull request as ready for review March 19, 2026 16:56
@stefanvanburen
Copy link
Member Author

Regardless if bufbuild/buf#4402 is merged or not, I'd argue that this is a bug fix (since all subcommands can define a ModifyCobra field, but it only currently runs on the root), so going to land this. Happy to revert if we feel this is the wrong direction.

@stefanvanburen stefanvanburen merged commit 1a2734d into main Mar 19, 2026
2 checks passed
@stefanvanburen stefanvanburen deleted the modify-cobra branch March 19, 2026 17:28
stefanvanburen added a commit that referenced this pull request Mar 19, 2026
Follow up to #5. This upgrades:

* `buf` to latest
* `golangci-lint` to match buf's version, up to v2
  * Fixes some minor lints
* go.mod version to 1.25.0 (n-1)
* Add 2026 to copyright years
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