Skip to content

Commit

Permalink
Added exportfile prompt and check
Browse files Browse the repository at this point in the history
  • Loading branch information
codepope committed Aug 10, 2020
1 parent eb05d95 commit 6656824
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cmd/dns.go
Expand Up @@ -269,7 +269,29 @@ func runRecordsExport(ctx *cmdctx.CmdContext) error {
return err
}

fmt.Println(records)
if len(ctx.Args) == 2 {
fmt.Println(records)
} else {
var filename string

validateFile := func(val interface{}) error {
_, err := os.Stat(val.(string))
if err == nil {
return fmt.Errorf("File %s already exists", val.(string))
}
return nil
}

err := survey.AskOne(&survey.Input{Message: "Export filename:"}, &filename, survey.WithValidator(validateFile))

if err != nil {
return err
}

ioutil.WriteFile(filename, []byte(records), 0644)

fmt.Printf("Zones exported to %s\n", filename)
}

return nil
}
Expand Down

0 comments on commit 6656824

Please sign in to comment.