Skip to content

Commit

Permalink
add commit hash information + update dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
vigo committed Nov 23, 2022
1 parent c8c619c commit e294d9f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM golang:1.16-alpine AS builder
FROM golang:1.19-alpine AS builder
WORKDIR /go/src/github.com/vigo/statoo
COPY . .
RUN apk add --no-cache git=2.34.2-r0 \
ca-certificates=20211220-r0 \
RUN apk add --no-cache git=2.36.3-r0 \
ca-certificates=20220614-r0 \
&& CGO_ENABLED=0 \
GOOS=linux \
go build -a -installsuffix cgo -o statoo .
go build -ldflags="-X 'github.com/vigo/statoo/app/version.CommitHash=$(git rev-parse HEAD)'" -a -installsuffix cgo -o statoo .

FROM alpine:3.15
RUN apk --no-cache add
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ usage: ./statoo [-flags] URL
-f, -find find text in response body if -json is set, case sensitive
-a, -auth basic auth "username:password"
-s, -skip skip certificate check and hostname in that certificate (default: false)
-commithash displays current build/commit hash (%s)

examples:

Expand Down Expand Up @@ -155,8 +156,6 @@ Now you can pass multiple `-request-header` flags:
statoo -request-header "Key1: Value1" -request-header "Key2: Value2" "https://ugur.ozyilmazel.com"
```
**New**
You can query/search for response headers. You can pass multiple values, all
**case sensitive**!. Let’s lookup for `Server` and `Foo` response header values.
`Server` value should be `GitHub.com` and `Foo` value should be `bar`:
Expand Down Expand Up @@ -194,6 +193,14 @@ Bash completions is available via;
eval "$(statoo bash-completion)"
```
**New**
You can check current build/commit hash via;
```bash
statoo -commithash
```
---
## Rake Tasks
Expand Down
34 changes: 24 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ var errInvalidTimeout = errors.New("invalid timeout value")

// variable declarations.
var (
ArgURL string
OptVersionInformation *bool
OptTimeout *int
OptVerboseOutput *bool
OptJSONOutput *bool
OptRequestHeaders flags.RequestHeadersFlag
OptResponseHeaders flags.ResponseHeadersFlag
OptFind *string
OptBasicAuth *string
OptInsecureSkipVerify *bool
ArgURL string
OptVersionInformation *bool
OptCommitHashInformation *bool
OptTimeout *int
OptVerboseOutput *bool
OptJSONOutput *bool
OptRequestHeaders flags.RequestHeadersFlag
OptResponseHeaders flags.ResponseHeadersFlag
OptFind *string
OptBasicAuth *string
OptInsecureSkipVerify *bool
)

// CLIApplication represents app structure.
Expand Down Expand Up @@ -87,6 +88,7 @@ func flagUsage(code int) func() {
defTimeout,
defTimeoutMin,
defTimeoutMax,
version.CommitHash,
)
if code > 0 {
os.Exit(code)
Expand All @@ -103,6 +105,13 @@ func NewCLIApplication() *CLIApplication {
false,
fmt.Sprintf("display version information (%s)", version.Version),
)

OptCommitHashInformation = flag.Bool(
"commithash",
false,
fmt.Sprintf("display build information (%s)", version.CommitHash),
)

OptVerboseOutput = flag.Bool("verbose", false, "verbose output")

helpJSON := "provides json output"
Expand Down Expand Up @@ -147,6 +156,11 @@ func (c *CLIApplication) Run() error {
return nil
}

if *OptCommitHashInformation {
fmt.Fprintln(c.Out, version.CommitHash)
return nil
}

if ArgURL == "bash-completion" {
fmt.Fprintln(c.Out, bashCompletion)
return nil
Expand Down
2 changes: 1 addition & 1 deletion app/bash_completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var bashCompletion = `__statoo_comp()
{
local cur next
cur="${COMP_WORDS[COMP_CWORD]}"
opts="-a -auth -f -find -header -h -help -j -json -t -timeout -s -skip -verbose -version"
opts="-a -auth -commithash -f -find -header -h -help -j -json -t -timeout -s -skip -verbose -version"
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
}
complete -F __statoo_comp statoo`
1 change: 1 addition & 0 deletions app/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ usage: %[1]s [-flags] URL
-f, -find find text in response body if -json is set, case sensitive
-a, -auth basic auth "username:password"
-s, -skip skip certificate check and hostname in that certificate (default: false)
-commithash displays current build/commit hash (%s)
examples:
Expand Down
3 changes: 3 additions & 0 deletions app/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ package version

// Version is the current version of statoo.
const Version string = "2.0.1"

// CommitHash represents current build/commit hash.
var CommitHash string

0 comments on commit e294d9f

Please sign in to comment.