Skip to content

Commit

Permalink
Merge pull request #21 from github/version
Browse files Browse the repository at this point in the history
Version argument
  • Loading branch information
mastahyeti authored Sep 12, 2018
2 parents 5d1ce27 + c633639 commit df6b0ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ before_build:
build_script:
- git describe --tags > version
- set /p GIT_VERSION= < version
- go build -o smimesign-%GOARCH%.exe -ldflags "-w -extldflags \"-static\" -extld=%EXTLD%" -i .
- go build -o smimesign-%GOARCH%.exe -ldflags "-X main.versionString=%GIT_VERSION% -w -extldflags \"-static\" -extld=%EXTLD%" -i .
- 7z a smimesign-%GIT_VERSION%-windows-%GOARCH%.zip smimesign-%GOARCH%.exe

test_script:
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ install: ''

script:
- GIT_VERSION=$(git describe --tags)
- go build -o smimesign .
- go build -o smimesign -ldflags "-X main.versionString=$GIT_VERSION" .
- tar czf smimesign-$GIT_VERSION-macos.tgz smimesign
- go test -v ./...

Expand Down
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ import (
)

var (
// This can be set at build time by running
// go build -ldflags "-X main.versionString=$(git describe --tags)"
versionString = "undefined"

// default timestamp authority URL. This can be set at build time by running
// go build -ldflags "-X main.defaultTSA=${https://whatever}"
defaultTSA = ""

// Action flags
helpFlag = getopt.BoolLong("help", 'h', "print this help message")
versionFlag = getopt.BoolLong("version", 'v', "print the version number")
signFlag = getopt.BoolLong("sign", 's', "make a signature")
verifyFlag = getopt.BoolLong("verify", 0, "verify a signature")
listKeysFlag = getopt.BoolLong("list-keys", 0, "show keys")
Expand Down Expand Up @@ -60,6 +65,11 @@ func runCommand() error {
return nil
}

if *versionFlag {
fmt.Println(versionString)
return nil
}

// Open certificate store
store, err := certstore.Open()
if err != nil {
Expand All @@ -77,7 +87,7 @@ func runCommand() error {
}

if *signFlag {
if *helpFlag || *verifyFlag || *listKeysFlag {
if *verifyFlag || *listKeysFlag {
return errors.New("specify --help, --sign, --verify, or --list-keys")
} else if len(*localUserOpt) == 0 {
return errors.New("specify a USER-ID to sign with")
Expand All @@ -87,7 +97,7 @@ func runCommand() error {
}

if *verifyFlag {
if *helpFlag || *signFlag || *listKeysFlag {
if *signFlag || *listKeysFlag {
return errors.New("specify --help, --sign, --verify, or --list-keys")
} else if len(*localUserOpt) > 0 {
return errors.New("local-user cannot be specified for verification")
Expand All @@ -101,7 +111,7 @@ func runCommand() error {
}

if *listKeysFlag {
if *helpFlag || *signFlag || *verifyFlag {
if *signFlag || *verifyFlag {
return errors.New("specify --help, --sign, --verify, or --list-keys")
} else if len(*localUserOpt) > 0 {
return errors.New("local-user cannot be specified for list-keys")
Expand Down

0 comments on commit df6b0ff

Please sign in to comment.