mirror of
https://github.com/Dasharo/sbctl.git
synced 2026-03-06 15:04:14 -08:00
sbctl: implement a hidden version command
Signed-off-by: Morten Linderud <morten@linderud.pw>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ releases/*
|
||||
/sbctl
|
||||
docs/*.8
|
||||
rootfs*
|
||||
VERSION
|
||||
|
||||
9
Makefile
9
Makefile
@@ -11,6 +11,10 @@ GOFLAGS ?= -buildmode=pie -trimpath
|
||||
|
||||
TAG = $(shell git describe --abbrev=0 --tags)
|
||||
|
||||
GIT_DESCRIBE = $(shell git describe | sed 's/-/./g;s/^v//;')
|
||||
|
||||
VERSION = $(shell if test -f VERSION; then cat VERSION; else echo -n $(GIT_DESCRIBE) ; fi)
|
||||
|
||||
all: man build
|
||||
build: sbctl
|
||||
man: $(MANS)
|
||||
@@ -21,7 +25,7 @@ docs/sbctl.%: docs/sbctl.%.txt docs/asciidoc.conf
|
||||
|
||||
.PHONY: sbctl
|
||||
sbctl:
|
||||
go build -o $@ ./cmd/$@
|
||||
go build -ldflags="-X github.com/foxboron/sbctl.Version=$(VERSION)" -o $@ ./cmd/$@
|
||||
|
||||
.PHONY: completions
|
||||
completions: sbctl
|
||||
@@ -42,8 +46,9 @@ install: sbctl completions man
|
||||
|
||||
.PHONY: release
|
||||
release:
|
||||
echo -n "$(GIT_DESCRIBE)" > VERSION
|
||||
mkdir -p releases
|
||||
git archive --prefix=${PROGNM}-${TAG}/ -o releases/${PROGNM}-${TAG}.tar.gz ${TAG};
|
||||
git archive --prefix=${PROGNM}-${TAG}/ --add-file=VERSION -o releases/${PROGNM}-${TAG}.tar.gz ${TAG};
|
||||
gpg --detach-sign -o releases/${PROGNM}-${TAG}.tar.gz.sig releases/${PROGNM}-${TAG}.tar.gz
|
||||
gh release upload ${TAG} releases/${PROGNM}-${TAG}.tar.gz.sig releases/${PROGNM}-${TAG}.tar.gz ${TAG}
|
||||
|
||||
|
||||
25
cmd/sbctl/version.go
Normal file
25
cmd/sbctl/version.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/foxboron/sbctl"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print sbctl version",
|
||||
Hidden: true,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println(sbctl.Version)
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
CliCommands = append(CliCommands, cliCommand{
|
||||
Cmd: versionCmd,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user