Skip to content

Commit

Permalink
Better command args parsing and help
Browse files Browse the repository at this point in the history
  • Loading branch information
mercury2269 committed Nov 15, 2018
1 parent 5e146ca commit 3844f55
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module github.com/mercury2269/sqsmover

require github.com/aws/aws-sdk-go v1.15.76
require (
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/aws/aws-sdk-go v1.15.76
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/aws/aws-sdk-go v1.15.76 h1:AZB4clNWIk13YJaTm07kqyrHkj7gZYBQCgyTh/v4Sec=
github.com/aws/aws-sdk-go v1.15.76/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 h1:12VvqtR6Aowv3l/EQUlocDHW2Cp4G9WJVH7uyH8QFJE=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
27 changes: 14 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package main

import (
"flag"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sqs"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
// app = kingpin.New("sqsmover", "A command line application that moves messages between AWS SQS queues")
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()
)



func resolveQueueUrl(queueName string, svc *sqs.SQS) (error, string) {
params := &sqs.GetQueueUrlInput{
QueueName: aws.String(queueName),
Expand All @@ -25,27 +34,19 @@ func resolveQueueUrl(queueName string, svc *sqs.SQS) (error, string) {
}

func main() {
kingpin.UsageTemplate(kingpin.CompactUsageTemplate)

var (
sourceQueueName = flag.String("source", "", "Source queue name")
destQueueName = flag.String("dest", "", "Destination queue name")
region = flag.String("region", "us-west-2", "AWS region")
)

flag.Parse()
kingpin.Parse()

// Create an EC2 service object in the "us-west-2" region
// Note that you can also configure your region globally by
// exporting the AWS_REGION environment variable
svc := sqs.New(session.New(), aws.NewConfig().WithRegion(*region))

err, sourceUrl := resolveQueueUrl(*sourceQueueName, svc)
err, sourceUrl := resolveQueueUrl(*sourceQueue, svc)

if err != nil {
return
}

err, destUrl := resolveQueueUrl(*destQueueName, svc)
err, destUrl := resolveQueueUrl(*destinationQueue, svc)

if err != nil {
return
Expand Down

0 comments on commit 3844f55

Please sign in to comment.