-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (52 loc) · 1.07 KB
/
main.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
package main
import (
"fmt"
"os"
"runtime/debug"
"github.com/fatih/color"
"github.com/firehydrant/signals-migrator/cmd"
"github.com/urfave/cli/v2"
)
func main() {
app := cli.NewApp()
app.Name = "signals-migrator"
app.Usage = "Easily migrate from legacy alerting providers to Signals by FireHydrant"
app.Version = revision()
app.Commands = []*cli.Command{
cmd.ImportCommand,
{
Name: "version",
Usage: "Print the version",
Action: func(c *cli.Context) error {
fmt.Printf("signals-migrator version %s\n" + revision()) //nolint:forbidigo,govet
return nil
},
},
}
if err := app.Run(os.Args); err != nil {
color.HiRed("Error: %v\n", err.Error())
os.Exit(1)
}
}
var version = "dev"
func revision() string {
bi, ok := debug.ReadBuildInfo()
if !ok {
return version
}
if v := bi.Main.Version; v != "(devel)" {
// Installed via `go install`.
version = v
}
rev := ""
for _, i := range bi.Settings {
if i.Key == "vcs.revision" {
rev = i.Value
break
}
}
if rev != "" {
return fmt.Sprintf("%s-%s", version, rev)
}
return version
}