Hard-code Use
field in root cobra command
#1186
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
...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 intermediatebinary 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 bymaking a test build and trying to source the completion result in fish
shell:
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