Skip to content

Commit

Permalink
Add output to file option in export
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoqalves committed Feb 15, 2018
1 parent c3615c8 commit e400d60
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ coverage.txt
coverage/

/dist/

# GoLand
.idea
4 changes: 2 additions & 2 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ func UnexpandSelfAliases(records []dns.RR, zone *route53.HostedZone, full bool)
}
}

func exportBind(name string, full bool) {
func exportBind(name string, full bool, writer io.Writer) {
zone := lookupZone(name)
ExportBindToWriter(r53, zone, full, os.Stdout)
ExportBindToWriter(r53, zone, full, writer)
}

type exportSorter struct {
Expand Down
17 changes: 16 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/urfave/cli"
"os"
)

var r53 *route53.Route53
Expand Down Expand Up @@ -256,6 +257,10 @@ func Main(args []string) int {
Name: "full, f",
Usage: "export prefixes as full names",
},
cli.StringFlag{
Name: "output",
Usage: "Write to an output file instead of STDOUT",
},
),
Action: func(c *cli.Context) (err error) {
r53, err = getService(c)
Expand All @@ -266,7 +271,17 @@ func Main(args []string) int {
cli.ShowCommandHelp(c, "export")
return cli.NewExitError("Expected exactly 1 parameter", 1)
}
exportBind(c.Args().First(), c.Bool("full"))

outputFileName := c.String("output")
writer := os.Stdout
if len(outputFileName) > 0 {
writer, err = os.Create(outputFileName)
defer writer.Close()
if err != nil {
return err
}
}
exportBind(c.Args().First(), c.Bool("full"), writer)
return nil
},
},
Expand Down

0 comments on commit e400d60

Please sign in to comment.