Fix version command

This commit is contained in:
Finn 2021-01-30 22:21:18 -08:00
parent a44db53f64
commit ddac6f183d
4 changed files with 52 additions and 4 deletions

View file

@ -1,5 +1,5 @@
signaldctl: signald/client-protocol signaldctl: signald/client-protocol
go build -o signaldctl ./cmd/signaldctl go build -ldflags '-X gitlab.com/signald/signald-go/cmd/signaldctl/common.Version=$(shell git describe) -X gitlab.com/signald/signald-go/cmd/signaldctl/common.Branch=$(shell git rev-parse --abbrev-ref HEAD) -X gitlab.com/signald/signald-go/cmd/signaldctl/common.Commit=$(shell git rev-parse HEAD)' -o signaldctl ./cmd/signaldctl
protocol.json: protocol.json:
signald --dump-protocol | jq . > protocol.json signald --dump-protocol | jq . > protocol.json

View file

@ -20,7 +20,9 @@ import (
"log" "log"
"os" "os"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"gitlab.com/signald/signald-go/cmd/signaldctl/common" "gitlab.com/signald/signald-go/cmd/signaldctl/common"
"gitlab.com/signald/signald-go/signald/client-protocol/v1" "gitlab.com/signald/signald-go/signald/client-protocol/v1"
@ -38,9 +40,39 @@ var versionCmd = &cobra.Command{
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
err = json.NewEncoder(os.Stdout).Encode(response)
output := []v1.JsonVersionMessage{
response,
{
Name: common.Name,
Branch: common.Branch,
Commit: common.Commit,
Version: common.Version,
},
}
switch common.OutputFormat {
case "json":
err := json.NewEncoder(os.Stdout).Encode(output)
if err != nil { if err != nil {
log.Fatal("error encoding output ", err) log.Fatal(err, "error encoding response to stdout")
}
break
case "yaml":
err := yaml.NewEncoder(os.Stdout).Encode(output)
if err != nil {
log.Fatal(err, "error encoding response to stdout")
}
break
case "table":
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"Name", "Version", "Branch", "Commit"})
t.AppendRow(table.Row{common.Name, common.Version, common.Branch, common.Commit})
t.AppendRow(table.Row{response.Name, response.Version, response.Branch, response.Commit})
t.Render()
break
default:
log.Fatal("Unsupported output format")
} }
}, },
} }

View file

@ -0,0 +1,8 @@
package common
var (
Name = "signaldctl"
Branch string
Commit string
Version string
)

8
debian/rules vendored
View file

@ -2,8 +2,16 @@
export DH_GOLANG_EXCLUDES := tools/ export DH_GOLANG_EXCLUDES := tools/
PKG := gitlab.com/signald/signald-go
GO_LDFLAGS += -X $(PKG)/cmd/signaldctl/common.Version=$(DEB_VERSION)
GO_LDFLAGS += -X $(PKG)/cmd/signaldctl/common.Branch=$(shell git rev-parse HEAD)
GO_LDFLAGS += -X $(PKG)/cmd/signaldctl/common.Commit=$(CI_BUILD_REF)
override_dh_auto_install: override_dh_auto_install:
dh_auto_install -- --no-source dh_auto_install -- --no-source
%: %:
dh $@ --buildsystem=golang --with=golang dh $@ --buildsystem=golang --with=golang
override_dh_auto_build:
dh_auto_build -- -ldflags '$(GO_LDFLAGS)'