Skip to content

Commit

Permalink
Add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Schneider authored Feb 16, 2021
2 parents 36fcf6b + a2df219 commit 292c21f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ENV GOFLAGS="-mod=vendor" \

RUN go generate && \
CGO_ENABLED=0 go build -v \
-ldflags "-X ${VERSION_PACKAGE}.VersionName=`git describe --tags --abbrev=0 --exact-match || git symbolic-ref -q --short HEAD` -X ${VERSION_PACKAGE}.BuildName=`git rev-parse --short HEAD`" \
-ldflags "-X ${VERSION_PACKAGE}.VersionName=`git describe --tags --abbrev=0 --exact-match || git symbolic-ref -q --short HEAD` -X ${VERSION_PACKAGE}.BuildName=`git rev-parse --short HEAD` -X ${VERSION_PACKAGE}.BuildDate=`date +'%F'`" \
-o /couper main.go && \
ls -lh /couper

Expand Down
2 changes: 2 additions & 0 deletions command/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func NewCommand(cmd string) Cmd {
switch strings.ToLower(cmd) {
case "run":
return NewRun(ContextWithSignal(context.Background()))
case "version":
return NewVersion()
default:
return nil
}
Expand Down
25 changes: 25 additions & 0 deletions command/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package command

import (
"github.com/sirupsen/logrus"

"github.com/avenga/couper/config"
"github.com/avenga/couper/config/runtime"
)

var _ Cmd = &Version{}

type Version struct{}

func NewVersion() *Version {
return &Version{}
}

func (v Version) Execute(_ Args, _ *config.CouperFile, _ *logrus.Entry) error {
println(runtime.VersionName + " " + runtime.BuildDate + " " + runtime.BuildName)
return nil
}

func (v Version) Usage() string {
return "couper version"
}
3 changes: 3 additions & 0 deletions config/runtime/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package runtime

import "time"

var (
BuildDate = time.Now().Format("2006-01-02")
BuildName = "dev"
VersionName = "0"
)
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func realmain(arguments []string) int {
cmd := args[0]
args = args[1:]

if cmd == "version" { // global options are not required, fast exit.
_ = command.NewCommand(cmd).Execute(args, nil, nil)
return 0
}

var filePath, logFormat string
set := flag.NewFlagSet("global", flag.ContinueOnError)
set.StringVar(&filePath, "f", config.DefaultFileName, "-f ./couper.hcl")
Expand Down

0 comments on commit 292c21f

Please sign in to comment.