Add version command and flag

This commit is contained in:
Zach Wasserman
2021-03-10 19:21:00 -08:00
parent be596e0949
commit be6a282315
3 changed files with 33 additions and 11 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
source = ["./dist/macos_darwin_amd64/orbit"]
source = ["./dist/orbit_darwin_amd64/orbit"]
bundle_id = "com.fleetdm.orbit"
apple_id {
+3 -10
View File
@@ -8,18 +8,11 @@ builds:
goos:
- linux
- windows
goarch:
- amd64
dir: ./cmd/orbit/
binary: orbit
- id: macos
env:
- CGO_ENABLED=0
goos:
- darwin
goarch:
- amd64
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser
dir: ./cmd/orbit/
binary: orbit
@@ -32,7 +25,7 @@ archives:
signs:
- signature: "${artifact}_macos.dmg"
ids:
- macos
- orbit
cmd: gon
args:
- .gon.hcl
+29
View File
@@ -30,6 +30,13 @@ const (
defaultRootDir = "/var/lib/orbit"
)
var (
// Flags set by goreleaser during build
version = ""
commit = ""
date = ""
)
func main() {
log.Logger = log.Output(
zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339Nano},
@@ -40,6 +47,7 @@ func main() {
app.Name = "Orbit osquery"
app.Usage = "A powered-up, (near) drop-in replacement for osquery"
app.Commands = []*cli.Command{
versionCommand,
shellCommand,
}
app.Flags = []cli.Flag{
@@ -97,8 +105,17 @@ func main() {
Usage: "Enable debug logging",
EnvVars: []string{"ORBIT_DEBUG"},
},
&cli.BoolFlag{
Name: "version",
Usage: "Get Orbit version",
},
}
app.Action = func(c *cli.Context) error {
if c.Bool("version") {
fmt.Println("orbit " + version)
return nil
}
if c.Bool("debug") {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
@@ -308,3 +325,15 @@ func main() {
log.Error().Err(err).Msg("")
}
}
var versionCommand = &cli.Command{
Name: "version",
Usage: "Get the orbit version",
Flags: []cli.Flag{},
Action: func(c *cli.Context) error {
fmt.Println("orbit " + version)
fmt.Println("commit - " + commit)
fmt.Println("date - " + date)
return nil
},
}