Skip to content

Commit

Permalink
Fixed exceptions. Added -V for version.
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Jun 17, 2016
1 parent 0004a42 commit 2c357a8
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions cli4/cli4.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@

sys.path.insert(0, os.path.abspath('..'))
import CloudFlare
import CloudFlare.exceptions

def convert_zones_to_identifier(cf, zone_name):
"""zone names to numbers"""
params = {'name':zone_name, 'per_page':1}
try:
zones = cf.zones.get(params=params)
except CloudFlare.CloudFlareAPIError as e:
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('cli4: %s - %d %s' % (zone_name, e, e))
except Exception as e:
exit('cli4: %s - %s' % (zone_name, e))
Expand All @@ -36,7 +37,7 @@ def convert_dns_record_to_identifier(cf, zone_id, dns_name):
params = {'name':dns_name}
try:
dns_records = cf.zones.dns_records.get(zone_id, params=params)
except CloudFlare.CloudFlareAPIError as e:
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('cli4: %s - %d %s' % (dns_name, e, e))
except Exception as e:
exit('cli4: %s - %s' % (dns_name, e))
Expand All @@ -54,7 +55,7 @@ def convert_certificates_to_identifier(cf, certificate_name):
"""certificate names to numbers"""
try:
certificates = cf.certificates.get()
except CloudFlare.CloudFlareAPIError as e:
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('cli4: %s - %d %s' % (certificate_name, e, e))
except Exception as e:
exit('cli4: %s - %s' % (certificate_name, e))
Expand All @@ -69,7 +70,7 @@ def convert_organizations_to_identifier(cf, organization_name):
"""organizations names to numbers"""
try:
organizations = cf.user.organizations.get()
except CloudFlare.CloudFlareAPIError as e:
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('cli4: %s - %d %s' % (organization_name, e, e))
except Exception as e:
exit('cli4: %s - %s' % (organization_name, e))
Expand All @@ -84,7 +85,7 @@ def convert_invites_to_identifier(cf, invite_name):
"""invite names to numbers"""
try:
invites = cf.user.invites.get()
except CloudFlare.CloudFlareAPIError as e:
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('cli4: %s - %d %s' % (invite_name, e, e))
except Exception as e:
exit('cli4: %s - %s' % (invite_name, e))
Expand All @@ -99,7 +100,7 @@ def convert_virtual_dns_to_identifier(cf, virtual_dns_name):
"""virtual dns names to numbers"""
try:
virtual_dnss = cf.user.virtual_dns.get()
except CloudFlare.CloudFlareAPIError as e:
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('cli4: %s - %d %s\n' % (virtual_dns_name, e, e))
except Exception as e:
exit('cli4: %s - %s\n' % (virtual_dns_name, e))
Expand All @@ -117,21 +118,24 @@ def cli4(args):
output = 'json'
method = 'GET'

usage = ('usage: cli4 [-h|--help] [-v|--verbose] [-q|--quiet] [-j|--json] [-y|--yaml]'
usage = ('usage: cli4 '
+ '[-V|--version] [-h|--help] [-v|--verbose] [-q|--quiet] [-j|--json] [-y|--yaml]'
+ '[--get|--patch|--post|-put|--delete]'
+ '[item=value ...]'
+ '/command...')

try:
opts, args = getopt.getopt(args,
'hvqjyGPOUD',
'VhvqjyGPOUD',
[
'help', 'verbose', 'quiet', 'json', 'yaml',
'help', 'version' 'verbose', 'quiet', 'json', 'yaml',
'get', 'patch', 'post', 'put', 'delete'
])
except getopt.GetoptError:
exit(usage)
for opt, arg in opts:
if opt in ('-V', '--version'):
exit('CloudFlare library version: %s' % (CloudFlare.__version__))
if opt in ('-h', '--help'):
exit(usage)
elif opt in ('-v', '--verbose'):
Expand Down Expand Up @@ -267,7 +271,7 @@ def cli4(args):
r = m.delete(identifier1=identifier1, identifier2=i2, data=params)
else:
pass
except CloudFlare.CloudFlareAPIError as e:
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('cli4: /%s - %d %s' % (command, e, e))
except Exception as e:
exit('cli4: /%s - %s - api error' % (command, e))
Expand Down

0 comments on commit 2c357a8

Please sign in to comment.