-
Notifications
You must be signed in to change notification settings - Fork 1
/
version.go
38 lines (31 loc) · 877 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package cmd
import (
"fmt"
"os"
"github.com/axllent/ghru"
"github.com/spf13/cobra"
)
var (
// Version is the default application version, updated on release
Version = "dev"
// Repo on Github for updater
Repo = "axllent/bwlog"
// RepoBinaryName on Github for updater
RepoBinaryName = "bwlog"
)
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Display the app version & update information",
Long: `Display the app version & update information.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(fmt.Sprintf("Version: %s", Version))
latest, _, _, err := ghru.Latest(Repo, RepoBinaryName)
if err == nil && ghru.GreaterThan(latest, Version) {
fmt.Printf("Update available: %s\nRun `%s update` to update.\n", latest, os.Args[0])
}
},
}
func init() {
rootCmd.AddCommand(versionCmd)
}