From 1eb2a7ceffcd76d02647aa0a3c86a21ca9fe9ba5 Mon Sep 17 00:00:00 2001 From: Petre Mierlutiu Date: Fri, 27 Sep 2024 19:26:19 +0300 Subject: [PATCH] Fix BinaryName initialization from args Fixes an issue with `completion bash` where the command name is not present in the completion output. --- cmd/root.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 35d266356..d94d5c847 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -14,7 +14,7 @@ import ( // RootCmd represents the base command when called without any subcommands. var RootCmd = &cobra.Command{ - Use: BinaryName, + Use: getCommandName(), Short: "A friendly command-line interface to Exercism.", Long: `A command-line interface for Exercism. @@ -41,8 +41,12 @@ func Execute() { } } +func getCommandName() string { + return os.Args[0] +} + func init() { - BinaryName = os.Args[0] + BinaryName = getCommandName() config.SetDefaultDirName(BinaryName) Out = os.Stdout Err = os.Stderr