Skip to content

Commit 378dede

Browse files
committed
cleaned up string response for /zones/:id/dns_records/export API call
1 parent a25a4a9 commit 378dede

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ $
714714
The following is documented within the **Advanced** option of the DNS page within the Cloudflare portal.
715715

716716
```
717-
$ python -m cli4 /zones/:example.com/dns_records/export | jq -r . | egrep -v '^;;|^$'
717+
$ python -m cli4 /zones/:example.com/dns_records/export | egrep -v '^;;|^$'
718718
$ORIGIN .
719719
@ 3600 IN SOA example.com. root.example.com. (
720720
2025552311 ; serial
@@ -730,7 +730,7 @@ record2.example.com. 300 IN AAAA 2001:d8b::2
730730
$
731731
```
732732

733-
The **jq -r** option is used to convert newlines and tabs within the JSON response data. The egrep is used for documentation brevity.
733+
The egrep is used for documentation brevity.
734734

735735
This can also be done via Python code with the following example.
736736
```

README.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ page within the Cloudflare portal.
789789

790790
::
791791

792-
$ python -m cli4 /zones/:example.com/dns_records/export | jq -r . | egrep -v '^;;|^$'
792+
$ python -m cli4 /zones/:example.com/dns_records/export | egrep -v '^;;|^$'
793793
$ORIGIN .
794794
@ 3600 IN SOA example.com. root.example.com. (
795795
2025552311 ; serial
@@ -804,8 +804,7 @@ page within the Cloudflare portal.
804804
record2.example.com. 300 IN AAAA 2001:d8b::2
805805
$
806806

807-
The **jq -r** option is used to convert newlines and tabs within the
808-
JSON response data. The egrep is used for documentation brevity.
807+
The egrep is used for documentation brevity.
809808

810809
This can also be done via Python code with the following example.
811810

@@ -1035,7 +1034,7 @@ and/or
10351034
Python 2.x vs 3.x support
10361035
-------------------------
10371036

1038-
As of May/June 2016 the code is now tested againt pylint. This was
1037+
As of May/June 2016 the code is now tested against pylint. This was
10391038
required in order to move the codebase into Python 3.x. The motivation
10401039
for this came from `Danielle Madeley
10411040
(danni) <https://github.com/danni>`__.

cli4/cli4.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,16 @@ def cli4(args):
281281
if len(results) == 1:
282282
results = results[0]
283283

284-
if output == 'json':
285-
sys.stdout.write(json.dumps(results, indent=4, sort_keys=True) + '\n')
286-
# json.dumps(results, sys.stdout, indent=4, sort_keys=True)
287-
# sys.stdout.write('\n')
288-
if output == 'yaml':
289-
sys.stdout.write(yaml.safe_dump(results))
284+
if isinstance(results, str):
285+
# if the results are a simple string, then it should be dumped directly
286+
# this is only used for /zones/:id/dns_records/export presently
287+
sys.stdout.write(results)
288+
else:
289+
# anything more complex (dict, list, etc) should be dumped as JSON/YAML
290+
if output == 'json':
291+
sys.stdout.write(json.dumps(results, indent=4, sort_keys=True) + '\n')
292+
# json.dumps(results, sys.stdout, indent=4, sort_keys=True)
293+
# sys.stdout.write('\n')
294+
if output == 'yaml':
295+
sys.stdout.write(yaml.safe_dump(results))
290296

0 commit comments

Comments
 (0)