support printing records to stdout
This commit is contained in:
parent
0a0c8474b8
commit
c2fc6d587d
14
main.go
14
main.go
@ -112,7 +112,7 @@ func main() {
|
||||
flag.StringVar(&token, "a", token, "Cloudflare API Token. env var: CF_TOKEN")
|
||||
flag.TextVar(&ip, "i", ip, "IP address")
|
||||
flag.StringVar(&cname, "c", cname, "CNAME target")
|
||||
flag.StringVar(&path, "o", path, "Path to save all records as json, e.g. ./records.json")
|
||||
flag.StringVar(&path, "o", path, "Path to save all records as json, e.g. ./records.json, '-' for stdout")
|
||||
flag.BoolVar(&del, "x", del, "Delete records of subdomain")
|
||||
flag.BoolVar(&mx, "m", mx, "Set mx record with cname value")
|
||||
flag.Parse()
|
||||
@ -169,15 +169,21 @@ func main() {
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
data, err := json.Marshal(recs)
|
||||
|
||||
data, err := json.Marshal(recs)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
err = os.WriteFile(path, data, 0644)
|
||||
if err != nil {
|
||||
|
||||
if path == "-" {
|
||||
if _, err = os.Stdout.Write(data); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
} else {
|
||||
if err = os.WriteFile(path, data, 0644); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user