forked from sourcegraph/srclib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
version_cmd.go
61 lines (49 loc) · 1.12 KB
/
version_cmd.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package src
import (
"fmt"
"log"
"github.com/inconshreveable/go-update/check"
)
// Version of src.
//
// For releases, this is set using the -X flag to `go tool ld`. See
// http://stackoverflow.com/a/11355611.
var Version string
const develVersion = "devel"
func init() {
if Version == "" {
Version = develVersion
}
}
func init() {
_, err := CLI.AddCommand("version",
"show version",
"Show version.",
&versionCmd,
)
if err != nil {
log.Fatal(err)
}
}
type VersionCmd struct {
NoCheck bool `long:"no-check-update" description:"don't check for updates"`
}
var versionCmd VersionCmd
func (c *VersionCmd) Execute(args []string) error {
fmt.Printf("srclib %s\n", Version)
// Only check for an update if we're running a released version.
if Version != develVersion && !c.NoCheck {
r, err := checkForUpdate()
if err == check.NoUpdateAvailable {
log.Println("\nYou are on the latest version of src.")
return nil
} else if err != nil {
return err
}
if r != nil {
log.Printf("\nA newer version of src is available: %s.", r.Version)
log.Println("Run 'src selfupdate' to update.")
}
}
return nil
}