From a49f97dab1928e5da447aa4034e6bea5567d66a8 Mon Sep 17 00:00:00 2001 From: Luther Wen Xu Date: Wed, 27 Nov 2019 20:35:38 +0800 Subject: [PATCH] modules/commands/version: Fix os.exec() call --- modules/commands/version.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/commands/version.go b/modules/commands/version.go index f4fc6e5..fe66d34 100644 --- a/modules/commands/version.go +++ b/modules/commands/version.go @@ -14,7 +14,7 @@ var versionString string func handleVersionCommand(s *discordgo.Session, args []string, m *discordgo.MessageCreate) error { if versionString == "" { - out, err := exec.Command("git describe --tags").Output() + out, err := exec.Command("git", "describe", "--tags").Output() if err != nil { log.Error( s, @@ -22,11 +22,18 @@ func handleVersionCommand(s *discordgo.Session, args []string, m *discordgo.Mess ) versionString = "Error while generating version string." } else { - info := strings.Split(string(out), " ") - versionString = fmt.Sprintf( - "**VERSION > **Current running version: __%s.%s__ (Internal ID: %s)", - info[0], info[1], info[2], - ) + info := strings.Split(strings.TrimSpace(string(out)), "-") + if len(info) == 1 { + versionString = fmt.Sprintf( + "**VERSION > **Current running version: __%s.0__ (Internal ID: unknown)", + info[0], + ) + } else { + versionString = fmt.Sprintf( + "**VERSION > **Current running version: __%s.%s__ (Internal ID: %s)", + info[0], info[1], info[2], + ) + } } } s.ChannelMessageSend(m.ChannelID, versionString)