Skip to content

Commit

Permalink
Merge pull request #35 from ramil600/version-command
Browse files Browse the repository at this point in the history
added --version flag:
  • Loading branch information
ahrtr authored Nov 20, 2022
2 parents a845375 + 2c63c8c commit dc004b5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ test:
fmt:
gofmt -w -l -s $(SRCS)

gofail: $(SRCS)
go build -v
gofail:
GO_BUILD_FLAGS="-v" ./build.sh
./gofail --version
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound")

# Set GO_LDFLAGS="-s" for building without symbols for debugging.
GO_LDFLAGS=("-X 'main.GitSHA=${GIT_SHA}'")
go build $GO_BUILD_FLAGS -ldflags="$GO_LDFLAGS" -o gofail
Empty file added go.sum
Empty file.
28 changes: 26 additions & 2 deletions gofail.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,29 @@ import (
"os"
"path"
"path/filepath"
"runtime"
"strings"

"go.etcd.io/gofail/code"
)

var (
// Git SHA Value will be set during build
GitSHA = "Not provided (use ./build.sh instead of go build)"

Version = "0.1.0"
)

var usageLine = `Usage:
gofail enable [list of files or directories]
Enable the failpoints
gofail disable [list of files or directories]
Disable the checkpoints
gofail --version
Show the version of gofail`

type xfrmFunc func(io.Writer, io.Reader) ([]*code.Failpoint, error)

func xfrmFile(xfrm xfrmFunc, path string) ([]*code.Failpoint, error) {
Expand Down Expand Up @@ -152,7 +170,7 @@ func writeBinding(file string, fps []*code.Failpoint) {

func main() {
if len(os.Args) < 2 {
fmt.Println("not enough arguments")
fmt.Println(usageLine)
os.Exit(1)
}

Expand All @@ -164,8 +182,14 @@ func main() {
enable = true
case "disable":
xfrm = code.ToComments
case "--version":
fmt.Println("Git SHA: ", GitSHA)
fmt.Println("Go Version: ", runtime.Version())
fmt.Println("gofail Version: ", Version)
fmt.Printf("Go OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
os.Exit(1)
default:
fmt.Println("expected enable or disable")
fmt.Println(usageLine)
os.Exit(1)
}

Expand Down

0 comments on commit dc004b5

Please sign in to comment.