Skip to content
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

Hard-code Use field in root cobra command #1186

Closed

Conversation

kblcuk
Copy link

@kblcuk kblcuk commented Dec 31, 2024

...so generated completions are for the end result built, not the
current binary that we run. While the latter might make sense in some
cases (maybe?), I'd think the end goal with completions is to produce
them for the final result (so exercism command), not the intermediate
binary that we're building. Judging by Cobra's docs [0] that's the
intended usage here.
Also the current approach produces unusable completions for fish shell,
where function names can't have / in them. This can be observed by
making a test build and trying to source the completion result in fish
shell:

go build -o testercism ./exercism/main.go

./testercism completion fish | source
- (line 3): function: __./testercism_debug: invalid function name
...

This also makes autogenerated completions usable in nix, where
generation process would pass an absolute path to built binary when
calling completions script [1].

As this repo auto-suggests, I also created a forum thread regarding this
[2], but figured I might as well create a PR with possible solution.

[0] https://pkg.go.dev/github.com/spf13/cobra#Command
[1] NixOS/nixpkgs#369128
[2] https://forum.exercism.org/t/fish-shell-completion-generation-doesnt-always-work/14299

...so generated completions are for the end result built, not the
current binary that we run. While the latter might make sense in some
cases (maybe?), I'd think the end goal with completions is to produce
them for the final result (so `exercism` command), not the intermediate
binary that we're building. Judging by Cobra's docs [0] that's the
intended usage here.
Also the current approach produces unusable completions for fish shell,
where function names can't have `/` in them. This can be observed by
making a test build and trying to source the completion result in fish
shell:

```fish
go build -o testercism ./exercism/main.go

./testercism completion fish | source
- (line 3): function: __./testercism_debug: invalid function name
...

This also makes autogenerated completions usable in nix, where
generation process would pass an absolute path to built binary when
calling completions script [1].

As this repo auto-suggests, I also created a forum thread regarding this
[2], but figured I might as well create a PR with possible solution.

[0] https://pkg.go.dev/github.com/spf13/cobra#Command
[1] NixOS/nixpkgs#369128
[2] https://forum.exercism.org/t/fish-shell-completion-generation-doesnt-always-work/14299
Copy link

Hello. Thanks for opening a PR on Exercism 🙂

We ask that all changes to Exercism are discussed on our Community Forum before being opened on GitHub. To enforce this, we automatically close all PRs that are submitted. That doesn't mean your PR is rejected but that we want the initial discussion about it to happen on our forum where a wide range of key contributors across the Exercism ecosystem can weigh in.

You can use this link to copy this into a new topic on the forum. If we decide the PR is appropriate, we'll reopen it and continue with it, so please don't delete your local branch.

If you're interested in learning more about this auto-responder, please read this blog post.


Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it.

@github-actions github-actions bot closed this Dec 31, 2024
@kblcuk
Copy link
Author

kblcuk commented Dec 31, 2024

Hopefully the forum post is still visible to contributors, since it got flagged by system as "spam" because it clearly doesn't like too many links -- so much for me trying to provide as much context as possible in the initial post 😬

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