Skip to content

Commit

Permalink
Add -version command
Browse files Browse the repository at this point in the history
  • Loading branch information
JackBister committed Aug 27, 2020
1 parent a2ba79b commit 8c97e19
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
run: go generate -v ./cmd/logsuck/main.go

- name: Build
run: go build -v ./cmd/logsuck/main.go
run: go build -v -ldflags "-X main.versionString=snapshot-$GITHUB_SHA" ./cmd/logsuck/main.go

- name: Build Windows
run: GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -v ./cmd/logsuck/main.go
run: GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -v -ldflags "-X main.versionString=snapshot-$GITHUB_SHA" ./cmd/logsuck/main.go

- name: Test
run: go test -v ./...
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set VERSIONNAME
run: VERSIONNAME=$(echo ${GITHUB_REF##*/} | sed 's/\./_/g') && echo "::set-env name=VERSIONNAME::$VERSIONNAME"
run: VERSIONNAME_DOTS=${GITHUB_REF##*/} && echo "::set-env name=VERSIONNAME_DOTS::$VERSIONNAME_DOTS" && VERSIONNAME=$(echo $VERSIONNAME_DOTS | sed 's/\./_/g') && echo "::set-env name=VERSIONNAME::$VERSIONNAME"

- name: Setup
uses: actions/setup-go@v2
Expand All @@ -33,11 +33,11 @@ jobs:

- name: Build and zip Linux x64
id: build_linux_x64
run: LINUX_X64_ASSET_PATH="logsuck-$VERSIONNAME-x64-linux.zip" && go build -o 'logsuck' -v ./cmd/logsuck/main.go && zip $LINUX_X64_ASSET_PATH logsuck && echo "::set-output name=asset_path::$LINUX_X64_ASSET_PATH"
run: LINUX_X64_ASSET_PATH="logsuck-$VERSIONNAME-x64-linux.zip" && go build -o 'logsuck' -v -ldflags "-X main.versionString=$VERSIONNAME_DOTS" ./cmd/logsuck/main.go && zip $LINUX_X64_ASSET_PATH logsuck && echo "::set-output name=asset_path::$LINUX_X64_ASSET_PATH"

- name: Build and zip Windows x64
id: build_windows_x64
run: WINDOWS_X64_ASSET_PATH="logsuck-$VERSIONNAME-x64-windows.zip" && GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -o 'logsuck.exe' -v ./cmd/logsuck/main.go && zip $WINDOWS_X64_ASSET_PATH logsuck.exe && echo "::set-output name=asset_path::$WINDOWS_X64_ASSET_PATH"
run: WINDOWS_X64_ASSET_PATH="logsuck-$VERSIONNAME-x64-windows.zip" && GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -o 'logsuck.exe' -v -ldflags "-X main.versionString=$VERSIONNAME_DOTS" ./cmd/logsuck/main.go && zip $WINDOWS_X64_ASSET_PATH logsuck.exe && echo "::set-output name=asset_path::$WINDOWS_X64_ASSET_PATH"

- name: Test
run: go test -v ./...
Expand Down
13 changes: 13 additions & 0 deletions cmd/logsuck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ func (i *flagStringArray) Set(value string) error {
return nil
}

var versionString string // This must be set using -ldflags "-X main.versionString=<version>" when building for --version to work

var cfgFileFlag string
var databaseFileFlag string
var eventDelimiterFlag string
var fieldExtractorFlags flagStringArray
var printVersion bool
var timeLayoutFlag string
var webAddrFlag string

Expand All @@ -78,9 +81,19 @@ func main() {
"Multiple extractors can be specified by using the fieldextractor flag multiple times. "+
"(defaults \"(\\w+)=(\\w+)\" and \"(?P<_time>\\d\\d\\d\\d/\\d\\d/\\d\\d \\d\\d:\\d\\d:\\d\\d.\\d\\d\\d\\d\\d\\d)\")")
flag.StringVar(&timeLayoutFlag, "timelayout", "2006/01/02 15:04:05", "The layout of the timestamp which will be extracted in the _time field.")
flag.BoolVar(&printVersion, "version", false, "Print version info and quit.")
flag.StringVar(&webAddrFlag, "webaddr", ":8080", "The address on which the search GUI will be exposed.")
flag.Parse()

if printVersion {
if versionString == "" {
fmt.Println("(unknown version)")
return
}
fmt.Println(versionString)
return
}

cfgFile, err := os.Open(cfgFileFlag)
if err == nil {
newCfg, err := config.FromJSON(cfgFile)
Expand Down

0 comments on commit 8c97e19

Please sign in to comment.