Skip to content

Commit 7520c7a

Browse files
committed
Hard-code Use field in root cobra command
...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
1 parent 7580d02 commit 7520c7a

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

cmd/root.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// RootCmd represents the base command when called without any subcommands.
1616
var RootCmd = &cobra.Command{
17-
Use: getCommandName(),
17+
Use: "exercism [command]",
1818
Short: "A friendly command-line interface to Exercism.",
1919
Long: `A command-line interface for Exercism.
2020
@@ -41,12 +41,8 @@ func Execute() {
4141
}
4242
}
4343

44-
func getCommandName() string {
45-
return os.Args[0]
46-
}
47-
4844
func init() {
49-
BinaryName = getCommandName()
45+
BinaryName = os.Args[0]
5046
config.SetDefaultDirName(BinaryName)
5147
Out = os.Stdout
5248
Err = os.Stderr

0 commit comments

Comments
 (0)