Skip to content

Commit

Permalink
Add version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mercury2269 committed Feb 22, 2020
1 parent 51d4b5e commit c01b50e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ archives:
format_overrides:
- goos: windows
format: zip
brews:
- github:
owner: mercury2269
name: homebrew-tap
folder: Formula
homepage: https://github.com/mercury2269/sqsmover
description: AWS SQS Message mover.
test: |
system "#{bin}/sqsmover -v"
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
27 changes: 27 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,33 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)

// nolint: gochecknoglobals
var (
version = "dev"
commit = ""
date = ""
builtBy = ""
)

var (
sourceQueue = kingpin.Flag("source", "Source queue to move messages from").Short('s').Required().String()
destinationQueue = kingpin.Flag("destination", "Destination queue to move messages to").Short('d').Required().String()
region = kingpin.Flag("region", "AWS Region for source and destination queues").Short('r').Default("us-west-2").String()
profile = kingpin.Flag("profile", "Use a specific profile from your credential file.").Short('p').Default("").String()
)


func main() {
log.SetHandler(cli.Default)

fmt.Println()
defer fmt.Println()

kingpin.Version(buildVersion(version, commit, date, builtBy))
kingpin.UsageTemplate(kingpin.CompactUsageTemplate)
kingpin.CommandLine.VersionFlag.Short('v')
kingpin.CommandLine.HelpFlag.Short('h')

kingpin.Parse()

sess, err := session.NewSessionWithOptions(
Expand Down Expand Up @@ -231,3 +244,17 @@ func moveMessages(sourceQueueUrl string, destinationQueueUrl string, svc *sqs.SQ
render(b.String())
}
}

func buildVersion(version, commit, date, builtBy string) string {
var result = fmt.Sprintf("version: %s", version)
if commit != "" {
result = fmt.Sprintf("%s\ncommit: %s", result, commit)
}
if date != "" {
result = fmt.Sprintf("%s\nbuilt at: %s", result, date)
}
if builtBy != "" {
result = fmt.Sprintf("%s\nbuilt by: %s", result, builtBy)
}
return result
}

0 comments on commit c01b50e

Please sign in to comment.