Skip to content

Commit

Permalink
addressing concerns
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
  • Loading branch information
AlexsJones committed Aug 17, 2022
1 parent f8cd08a commit 093744f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
IMG ?= flagd:latest
PHONY: .docker-build .build .run .mockgen
PREFIX=/usr/local
VERSION=0.0.8

guard-%:
@ if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi
docker-build:
docker buildx build --build-arg=VERSION=$(VERSION) --build-arg=COMMIT=$(git rev-parse --short HEAD) --build-arg DATE="$(date +%Y%m%d)" --platform="linux/ppc64le,linux/s390x,linux/amd64,linux/arm64" -t ${IMG} .
docker buildx build --build-arg=VERSION="$$(git describe --tags --abbrev=0)" --build-arg=COMMIT="$$(git rev-parse --short HEAD)" --build-arg DATE="$$(date +%Y%m%d)" --platform="linux/ppc64le,linux/s390x,linux/amd64,linux/arm64" -t ${IMG} . --load
docker-push:
docker buildx build --push --build-arg=VERSION=$(VERSION) --build-arg=COMMIT=$(git rev-parse --short HEAD) --build-arg DATE="$(date +%Y%m%d)" --platform="linux/ppc64le,linux/s390x,linux/amd64,linux/arm64" -t ${IMG} .
docker buildx build --push --build-arg=VERSION="$$(git describe --tags --abbrev=0)" --build-arg=COMMIT="$$(git rev-parse --short HEAD)" --build-arg DATE="$$(date +%Y%m%d)" --platform="linux/ppc64le,linux/s390x,linux/amd64,linux/arm64" -t ${IMG} .
build:
go build -o flagd
go build -ldflags "-X main.version=dev -X main.commit=$$(git rev-parse --short HEAD) -X main.date=$$(date +%Y%m%d)" -o flagd
test:
go test -cover ./...
run:
Expand Down
12 changes: 10 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import (
"github.com/spf13/viper"
)

var cfgFile string
var (
cfgFile string
Version string
Commit string
Date string
)

var rootCmd = &cobra.Command{
Use: "flagd",
Expand All @@ -22,7 +27,10 @@ var rootCmd = &cobra.Command{

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
func Execute(version string, commit string, date string) {
Version = version
Commit = commit
Date = date
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
Expand Down
26 changes: 26 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of FlagD",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("flagd %s (%s) built at %s\n", Version, Commit, Date)
},
}

func init() {
rootCmd.AddCommand(versionCmd)

}
13 changes: 1 addition & 12 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/open-feature/flagd/cmd"
)

Expand All @@ -15,12 +11,5 @@ var (
)

func main() {
showVersion := flag.Bool("version", false, "show version")
flag.Parse()
if *showVersion {
fmt.Printf("flagd %s (%s) built at %s\n", version, commit, date)
os.Exit(0)
} else {
cmd.Execute()
}
cmd.Execute(version, commit, date)
}

0 comments on commit 093744f

Please sign in to comment.