From 02119dfb1758cb6044d2619961670d2c6e255c5b Mon Sep 17 00:00:00 2001 From: zuisong <19145952+zuisong@users.noreply.github.com> Date: Tue, 22 Oct 2024 21:07:27 +0800 Subject: [PATCH] fix: shell completion use exec's actual name (#4015) --- internal/command/root/root.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/command/root/root.go b/internal/command/root/root.go index b840110c03..dd0880c128 100644 --- a/internal/command/root/root.go +++ b/internal/command/root/root.go @@ -3,6 +3,9 @@ package root import ( "context" + "log" + "os" + "path/filepath" "github.com/kr/text" "github.com/olekukonko/tablewriter" @@ -77,7 +80,16 @@ func New() *cobra.Command { short = "The Fly.io command line interface" ) - root := command.New("fly", short, long, run) + exePath, err := os.Executable() + var exe string + if err != nil { + log.Printf("WARN: failed to find executable, error=%q", err) + exe = "fly" + } else { + exe = filepath.Base(exePath) + } + + root := command.New(exe, short, long, run) root.PersistentPreRun = func(cmd *cobra.Command, args []string) { cmd.SilenceUsage = true cmd.SilenceErrors = true