Skip to content

Commit

Permalink
fix: Add version info
Browse files Browse the repository at this point in the history
  • Loading branch information
NoUseFreak committed Dec 12, 2023
1 parent 8a12005 commit c79da91
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
32 changes: 32 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"runtime/debug"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var (
Version = "dev"
Commit = "none"
Date = "unknown"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number",
Run: func(cmd *cobra.Command, args []string) {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
Version = info.Main.Version
Commit = info.Main.Sum
}
logrus.Infof("version: \t %s", Version)
logrus.Infof("commit: \t %s", Commit)
logrus.Infof("date: \t %s", Date)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package main

import (
"github.com/nousefreak/warpdir/cmd"
"github.com/nousefreak/warpdir/cmd"
)

var (
version = "dev"
commit = "none"
date = "unknown"
)

func main() {
cmd.Execute()
cmd.Version = version
cmd.Commit = commit
cmd.Date = date

cmd.Execute()
}

0 comments on commit c79da91

Please sign in to comment.