Skip to content

Commit

Permalink
Implement sub-command "version"
Browse files Browse the repository at this point in the history
  • Loading branch information
guessi committed Feb 16, 2024
1 parent b94f7e2 commit e16cd4c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.PHONY: staticcheck dependency clean build release all

PKGS := $(shell go list ./...)
REPO := github.com/guessi/cloudtrail-cli
BUILDTIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GITVERSION := $(shell git describe --tags --abbrev=8)
LDFLAGS := -s -w
GOVERSION := $(shell go version | cut -d' ' -f3)
LDFLAGS := -s -w -X "$(REPO)/pkg/constants.GitVersion=$(GITVERSION)" -X "$(REPO)/pkg/constants.GoVersion=$(GOVERSION)" -X "$(REPO)/pkg/constants.BuildTime=$(BUILDTIME)"

default: build

Expand Down
24 changes: 23 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
package main

import (
"fmt"
"os"
"regexp"

"github.com/guessi/cloudtrail-cli/cmd"
"github.com/guessi/cloudtrail-cli/pkg/constants"
"github.com/urfave/cli/v2"
)

func showVersion() {
r, _ := regexp.Compile(`v[0-9]\.[0-9]+\.[0-9]+`)
versionInfo := r.FindString(constants.GitVersion)
fmt.Println("cloudtrail-cli", versionInfo)
fmt.Println(" Git Commit:", constants.GitVersion)
fmt.Println(" Build with:", constants.GoVersion)
fmt.Println(" Build time:", constants.BuildTime)
}

func main() {
app := &cli.App{
Name: constants.NAME,
Usage: constants.USAGE,
Version: constants.VERSION,
Version: constants.GitVersion,
Flags: cmd.Flags,
Action: func(c *cli.Context) error {
cmd.Wrapper(c)
return nil
},
Commands: []*cli.Command{
{
Name: "version",
Aliases: []string{"v"},
Usage: "Print version number",
Action: func(cCtx *cli.Context) error {
showVersion()
return nil
},
},
},
}

err := app.Run(os.Args)
Expand Down
11 changes: 8 additions & 3 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package constants

const (
NAME string = "cloudtrail-cli"
USAGE string = "Blazing fast single purpose cli for CloudTrail log filtering"
VERSION string = "1.0.9"
NAME string = "cloudtrail-cli"
USAGE string = "Blazing fast single purpose cli for CloudTrail log filtering"
)

var (
GitVersion string
GoVersion string
BuildTime string
)

0 comments on commit e16cd4c

Please sign in to comment.