Skip to content

Commit

Permalink
Fixes #17
Browse files Browse the repository at this point in the history
Allows users to prin ingress-perf version

Signed-off-by: Krishna Harsha Voora <[email protected]>
  • Loading branch information
krishvoor committed Jul 20, 2023
1 parent fe336dd commit 0a412d0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
run Run benchmark
help Print the version

Flags:
-h, --help help for this command
Expand Down
44 changes: 43 additions & 1 deletion cmd/ingress-perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
package main

import (
"bytes"
"fmt"
"os/exec"
"strings"

"github.com/cloud-bulldozer/go-commons/indexers"
"github.com/cloud-bulldozer/ingress-perf/pkg/config"
Expand Down Expand Up @@ -86,8 +89,47 @@ func run() *cobra.Command {
return cmd
}

func getGitInfo() (string, string) {

// Get the last released tag info
cmdTag := exec.Command("git", "describe", "--tags", "--abbrev=0")
var outTag bytes.Buffer
cmdTag.Stdout = &outTag
errTag := cmdTag.Run()
gitTag := "Unknown"
if errTag == nil {
gitTag = strings.TrimSpace(outTag.String())
}

// Get the last Commit Hash
cmdCommit := exec.Command("git", "rev-parse", "--short", "HEAD")
var outCommit bytes.Buffer
cmdCommit.Stdout = &outCommit
errCommit := cmdCommit.Run()
gitCommitHash := "Unknown"
if errCommit == nil {
gitCommitHash = strings.TrimSpace(outCommit.String())
}

return gitTag, gitCommitHash
}

func version() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Print the version number ",
SilenceErrors: true,
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
gitTag, gitCommitHash := getGitInfo()
fmt.Printf("😎 Ingress-perf version is %s@%s \n", gitTag, gitCommitHash)
},
}
return cmd
}

func main() {
cmd.AddCommand(run())
cmd.AddCommand(run(), version())
if err := cmd.Execute(); err != nil {
log.Fatal(err.Error())
}
Expand Down

0 comments on commit 0a412d0

Please sign in to comment.