support printing records to stdout
This commit is contained in:
parent
0a0c8474b8
commit
c2fc6d587d
16
main.go
16
main.go
@ -112,7 +112,7 @@ func main() {
|
|||||||
flag.StringVar(&token, "a", token, "Cloudflare API Token. env var: CF_TOKEN")
|
flag.StringVar(&token, "a", token, "Cloudflare API Token. env var: CF_TOKEN")
|
||||||
flag.TextVar(&ip, "i", ip, "IP address")
|
flag.TextVar(&ip, "i", ip, "IP address")
|
||||||
flag.StringVar(&cname, "c", cname, "CNAME target")
|
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(&del, "x", del, "Delete records of subdomain")
|
||||||
flag.BoolVar(&mx, "m", mx, "Set mx record with cname value")
|
flag.BoolVar(&mx, "m", mx, "Set mx record with cname value")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -169,14 +169,20 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
data, err := json.Marshal(recs)
|
|
||||||
|
|
||||||
|
data, err := json.Marshal(recs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
err = os.WriteFile(path, data, 0644)
|
|
||||||
if err != nil {
|
if path == "-" {
|
||||||
log.Panicln(err)
|
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