diff --git a/go.mod b/go.mod index 33e0776..fbd6cf5 100644 --- a/go.mod +++ b/go.mod @@ -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 +) diff --git a/go.sum b/go.sum index 20b3a1f..4063ec4 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/main.go b/main.go index a87e95d..066b58e 100644 --- a/main.go +++ b/main.go @@ -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), @@ -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