Fix version command
This commit is contained in:
parent
a44db53f64
commit
ddac6f183d
4 changed files with 52 additions and 4 deletions
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
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:
|
||||
signald --dump-protocol | jq . > protocol.json
|
||||
|
|
|
@ -20,7 +20,9 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"gitlab.com/signald/signald-go/cmd/signaldctl/common"
|
||||
"gitlab.com/signald/signald-go/signald/client-protocol/v1"
|
||||
|
@ -38,9 +40,39 @@ var versionCmd = &cobra.Command{
|
|||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = json.NewEncoder(os.Stdout).Encode(response)
|
||||
if err != nil {
|
||||
log.Fatal("error encoding output ", err)
|
||||
|
||||
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 {
|
||||
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")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
8
cmd/signaldctl/common/version.go
Normal file
8
cmd/signaldctl/common/version.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
package common
|
||||
|
||||
var (
|
||||
Name = "signaldctl"
|
||||
Branch string
|
||||
Commit string
|
||||
Version string
|
||||
)
|
8
debian/rules
vendored
8
debian/rules
vendored
|
@ -2,8 +2,16 @@
|
|||
|
||||
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:
|
||||
dh_auto_install -- --no-source
|
||||
|
||||
%:
|
||||
dh $@ --buildsystem=golang --with=golang
|
||||
|
||||
override_dh_auto_build:
|
||||
dh_auto_build -- -ldflags '$(GO_LDFLAGS)'
|
Loading…
Reference in a new issue