File tree Expand file tree Collapse file tree 3 files changed +17
-12
lines changed
Expand file tree Collapse file tree 3 files changed +17
-12
lines changed Original file line number Diff line number Diff line change 714714The 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
735735This can also be done via Python code with the following example.
736736```
Original file line number Diff line number Diff 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
810809This can also be done via Python code with the following example.
811810
@@ -1035,7 +1034,7 @@ and/or
10351034Python 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
10391038required in order to move the codebase into Python 3.x. The motivation
10401039for this came from `Danielle Madeley
10411040(danni) <https://github.com/danni> `__.
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments