Skip to content

Commit

Permalink
Add -version flag to dicomutil
Browse files Browse the repository at this point in the history
The version string will be injected at release step with the output of `git describe --tags --always`.
  • Loading branch information
favadi committed Dec 8, 2020
1 parent ea26fb8 commit ebc315d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
/build/
7 changes: 4 additions & 3 deletions Makefile
@@ -1,4 +1,5 @@
BINARY = dicomutil
VERSION != git describe --tags --always

.PHONY: build
build:
Expand All @@ -23,9 +24,9 @@ run:
release:
go mod download
$(MAKE) test
GOOS=linux GOARCH=amd64 go build -o build/${BINARY}-linux-amd64 ./cmd/dicomutil;
GOOS=darwin GOARCH=amd64 go build -o build/${BINARY}-darwin-amd64 ./cmd/dicomutil;
GOOS=windows GOARCH=amd64 go build -o build/${BINARY}-windows-amd64.exe ./cmd/dicomutil;
GOOS=linux GOARCH=amd64 go build -ldflags="-X 'main.Version=${VERSION}'" -o build/${BINARY}-linux-amd64 ./cmd/dicomutil;
GOOS=darwin GOARCH=amd64 go build -ldflags="-X 'main.Version=${VERSION}'" -o build/${BINARY}-darwin-amd64 ./cmd/dicomutil;
GOOS=windows GOARCH=amd64 go build -ldflags="-X 'main.Version=${VERSION}'" -o build/${BINARY}-windows-amd64.exe ./cmd/dicomutil;
cd build; \
tar -zcvf ${BINARY}-linux-amd64.tar.gz ${BINARY}-linux-amd64; \
tar -zcvf ${BINARY}-darwin-amd64.tar.gz ${BINARY}-darwin-amd64; \
Expand Down
10 changes: 10 additions & 0 deletions cmd/dicomutil/main.go
Expand Up @@ -17,7 +17,11 @@ import (
"github.com/suyashkumar/dicom/pkg/tag"
)

// GitVersion is the current version of dicomutil, will be replaced in release step with current git commit hash or tag.
var GitVersion = "unknown"

var (
version = flag.Bool("version", false, "print current version and exit")
filepath = flag.String("path", "", "path")
extractImagesStream = flag.Bool("extract-images-stream", false, "Extract images using frame streaming capability")
printJSON = flag.Bool("json", false, "Print dataset as JSON")
Expand All @@ -28,6 +32,12 @@ const FrameBufferSize = 100

func main() {
flag.Parse()

if *version {
fmt.Printf("dicomutil: %s\n", GitVersion)
os.Exit(0)
}

if len(*filepath) > 0 {

f, err := os.Open(*filepath)
Expand Down

0 comments on commit ebc315d

Please sign in to comment.