Skip to content

Commit

Permalink
include version in build
Browse files Browse the repository at this point in the history
implements --version

Signed-off-by: Alex Couture-Beil <[email protected]>
  • Loading branch information
alexcb committed Jun 14, 2021
1 parent b544f76 commit de957a2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ lint:

secretshare:
FROM +code
ARG RELEASE_TAG="dev"
ARG GOOS
ARG GO_EXTRA_LDFLAGS
ARG GOARCH
Expand All @@ -62,7 +63,7 @@ secretshare:
RUN --mount=type=cache,target=$GOCACHE \
go build \
-o build/secretshare \
-ldflags "$GO_EXTRA_LDFLAGS" \
-ldflags "-X main.Version=$RELEASE_TAG $GO_EXTRA_LDFLAGS" \
cmd/secretshare/main.go
SAVE ARTIFACT build/secretshare AS LOCAL "build/$GOOS/$GOARCH/secretshare"

Expand Down
Binary file modified build/darwin/amd64/secretshare
Binary file not shown.
Binary file modified build/linux/amd64/secretshare
Binary file not shown.
19 changes: 16 additions & 3 deletions cmd/secretshare/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"golang.org/x/crypto/ssh"
)

var Version = "development"

func marshalRSAPrivate(priv *rsa.PrivateKey) string {
return string(pem.EncodeToMemory(&pem.Block{
Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv),
Expand Down Expand Up @@ -294,6 +296,19 @@ func genOrLoadKeys() (string, string, error) {
}

func main() {
var arg string
if len(os.Args) == 2 {
arg = os.Args[1]
}
if len(os.Args) > 2 {
fmt.Fprintf(os.Stderr, "only a single arg is supported\n")
os.Exit(1)
}
if arg == "-v" || arg == "--version" {
fmt.Printf("secretshare version: %s\n", Version)
return
}

test()
pub, priv, err := genOrLoadKeys()
if err != nil {
Expand All @@ -313,15 +328,13 @@ func main() {
return
}

arg := os.Args[1]

data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintf(os.Stderr, "failed while reading from stdin: %s\n", err.Error())
os.Exit(1)
}

if arg == "decrypt" {
if arg == "decrypt" || arg == "--decrypt" || arg == "-d" || arg == "d" {
data2, err := decrypt(string(data), priv)
if err != nil {
fmt.Fprintf(os.Stderr, "failed while decrypting: %s\n", err.Error())
Expand Down

0 comments on commit de957a2

Please sign in to comment.