1313
1414sys .path .insert (0 , os .path .abspath ('..' ))
1515import CloudFlare
16+ import CloudFlare .exceptions
1617
1718def convert_zones_to_identifier (cf , zone_name ):
1819 """zone names to numbers"""
1920 params = {'name' :zone_name , 'per_page' :1 }
2021 try :
2122 zones = cf .zones .get (params = params )
22- except CloudFlare .CloudFlareAPIError as e :
23+ except CloudFlare .exceptions . CloudFlareAPIError as e :
2324 exit ('cli4: %s - %d %s' % (zone_name , e , e ))
2425 except Exception as e :
2526 exit ('cli4: %s - %s' % (zone_name , e ))
@@ -36,7 +37,7 @@ def convert_dns_record_to_identifier(cf, zone_id, dns_name):
3637 params = {'name' :dns_name }
3738 try :
3839 dns_records = cf .zones .dns_records .get (zone_id , params = params )
39- except CloudFlare .CloudFlareAPIError as e :
40+ except CloudFlare .exceptions . CloudFlareAPIError as e :
4041 exit ('cli4: %s - %d %s' % (dns_name , e , e ))
4142 except Exception as e :
4243 exit ('cli4: %s - %s' % (dns_name , e ))
@@ -54,7 +55,7 @@ def convert_certificates_to_identifier(cf, certificate_name):
5455 """certificate names to numbers"""
5556 try :
5657 certificates = cf .certificates .get ()
57- except CloudFlare .CloudFlareAPIError as e :
58+ except CloudFlare .exceptions . CloudFlareAPIError as e :
5859 exit ('cli4: %s - %d %s' % (certificate_name , e , e ))
5960 except Exception as e :
6061 exit ('cli4: %s - %s' % (certificate_name , e ))
@@ -69,7 +70,7 @@ def convert_organizations_to_identifier(cf, organization_name):
6970 """organizations names to numbers"""
7071 try :
7172 organizations = cf .user .organizations .get ()
72- except CloudFlare .CloudFlareAPIError as e :
73+ except CloudFlare .exceptions . CloudFlareAPIError as e :
7374 exit ('cli4: %s - %d %s' % (organization_name , e , e ))
7475 except Exception as e :
7576 exit ('cli4: %s - %s' % (organization_name , e ))
@@ -84,7 +85,7 @@ def convert_invites_to_identifier(cf, invite_name):
8485 """invite names to numbers"""
8586 try :
8687 invites = cf .user .invites .get ()
87- except CloudFlare .CloudFlareAPIError as e :
88+ except CloudFlare .exceptions . CloudFlareAPIError as e :
8889 exit ('cli4: %s - %d %s' % (invite_name , e , e ))
8990 except Exception as e :
9091 exit ('cli4: %s - %s' % (invite_name , e ))
@@ -99,7 +100,7 @@ def convert_virtual_dns_to_identifier(cf, virtual_dns_name):
99100 """virtual dns names to numbers"""
100101 try :
101102 virtual_dnss = cf .user .virtual_dns .get ()
102- except CloudFlare .CloudFlareAPIError as e :
103+ except CloudFlare .exceptions . CloudFlareAPIError as e :
103104 exit ('cli4: %s - %d %s\n ' % (virtual_dns_name , e , e ))
104105 except Exception as e :
105106 exit ('cli4: %s - %s\n ' % (virtual_dns_name , e ))
@@ -117,21 +118,24 @@ def cli4(args):
117118 output = 'json'
118119 method = 'GET'
119120
120- usage = ('usage: cli4 [-h|--help] [-v|--verbose] [-q|--quiet] [-j|--json] [-y|--yaml]'
121+ usage = ('usage: cli4 '
122+ + '[-V|--version] [-h|--help] [-v|--verbose] [-q|--quiet] [-j|--json] [-y|--yaml]'
121123 + '[--get|--patch|--post|-put|--delete]'
122124 + '[item=value ...]'
123125 + '/command...' )
124126
125127 try :
126128 opts , args = getopt .getopt (args ,
127- 'hvqjyGPOUD ' ,
129+ 'VhvqjyGPOUD ' ,
128130 [
129- 'help' , 'verbose' , 'quiet' , 'json' , 'yaml' ,
131+ 'help' , 'version' ' verbose' , 'quiet' , 'json' , 'yaml' ,
130132 'get' , 'patch' , 'post' , 'put' , 'delete'
131133 ])
132134 except getopt .GetoptError :
133135 exit (usage )
134136 for opt , arg in opts :
137+ if opt in ('-V' , '--version' ):
138+ exit ('CloudFlare library version: %s' % (CloudFlare .__version__ ))
135139 if opt in ('-h' , '--help' ):
136140 exit (usage )
137141 elif opt in ('-v' , '--verbose' ):
@@ -267,7 +271,7 @@ def cli4(args):
267271 r = m .delete (identifier1 = identifier1 , identifier2 = i2 , data = params )
268272 else :
269273 pass
270- except CloudFlare .CloudFlareAPIError as e :
274+ except CloudFlare .exceptions . CloudFlareAPIError as e :
271275 exit ('cli4: /%s - %d %s' % (command , e , e ))
272276 except Exception as e :
273277 exit ('cli4: /%s - %s - api error' % (command , e ))
0 commit comments