@@ -77,7 +77,8 @@ def run_command(cf, method, command, params=None, content=None, files=None):
7777 else :
7878 raise Exception ("/%s/%s :NOT CODED YET" % ('/' .join (cmd ), element ))
7979 except Exception as e :
80- sys .exit ('cli4: /%s - %s' % (command , e ))
80+ sys .stderr .write ('cli4: /%s - %s\n ' % (command , e ))
81+ raise e
8182 cmd .append (':' + identifier1 )
8283 elif identifier2 is None :
8384 if len (element ) in [32 , 40 , 48 ] and hex_only .match (element ):
@@ -95,7 +96,8 @@ def run_command(cf, method, command, params=None, content=None, files=None):
9596 else :
9697 raise Exception ("/%s/%s :NOT CODED YET" % ('/' .join (cmd ), element ))
9798 except Exception as e :
98- sys .exit ('cli4: /%s - %s' % (command , e ))
99+ sys .stderr .write ('cli4: /%s - %s\n ' % (command , e ))
100+ raise e
99101 # identifier2 may be an array - this needs to be dealt with later
100102 if isinstance (identifier2 , list ):
101103 cmd .append (':' + '[' + ',' .join (identifier2 ) + ']' )
@@ -109,20 +111,23 @@ def run_command(cf, method, command, params=None, content=None, files=None):
109111 elif waf_rules .match (element ):
110112 identifier3 = element
111113 else :
112- sys .exit ("/%s/%s :NOT CODED YET 3" % ('/' .join (cmd ), element ))
114+ sys .stderr .write ('/%s/%s :NOT CODED YET 3\n ' % ('/' .join (cmd ), element ))
115+ raise e
113116 else :
114117 try :
115118 m = getattr (m , element )
116119 cmd .append (element )
117120 except AttributeError :
118121 # the verb/element was not found
119122 if len (cmd ) == 0 :
120- sys .exit ('cli4: /%s - not found' % (element ))
123+ sys .stderr . write ('cli4: /%s - not found\n ' % (element ))
121124 else :
122- sys .exit ('cli4: /%s/%s - not found' % ('/' .join (cmd ), element ))
125+ sys .stderr .write ('cli4: /%s/%s - not found\n ' % ('/' .join (cmd ), element ))
126+ raise e
123127
124128 if content and params :
125- sys .exit ('cli4: /%s - content and params not allowed together' % (command ))
129+ sys .stderr .write ('cli4: /%s - content and params not allowed together\n ' % (command ))
130+ raise Exception
126131 if content :
127132 params = content
128133
@@ -163,11 +168,14 @@ def run_command(cf, method, command, params=None, content=None, files=None):
163168 # more than one error returned by the API
164169 for x in e :
165170 sys .stderr .write ('cli4: /%s - %d %s\n ' % (command , x , x ))
166- sys .exit ('cli4: /%s - %d %s' % (command , e , e ))
171+ sys .stderr .write ('cli4: /%s - %d %s\n ' % (command , e , e ))
172+ raise e
167173 except CloudFlare .exceptions .CloudFlareInternalError as e :
168- sys .exit ('cli4: InternalError: /%s - %d %s' % (command , e , e ))
174+ sys .stderr .write ('cli4: InternalError: /%s - %d %s\n ' % (command , e , e ))
175+ raise e
169176 except Exception as e :
170- sys .exit ('cli4: /%s - %s - api error' % (command , e ))
177+ sys .stderr .write ('cli4: /%s - %s - api error\n ' % (command , e ))
178+ raise e
171179
172180 results .append (r )
173181 return results
@@ -379,16 +387,22 @@ def do_it(args):
379387 (tag_string , value_string ))
380388
381389 # what's left is the command itself
382- if len (args ) != 1 :
390+ if len (args ) < 1 :
383391 sys .exit (usage )
384- command = args [ 0 ]
392+ commands = args
385393
386394 try :
387395 cf = CloudFlare .CloudFlare (debug = verbose , raw = raw , profile = profile )
388396 except Exception as e :
389397 sys .exit (e )
390- results = run_command (cf , method , command , params , content , files )
391- write_results (results , output )
398+
399+ for command in commands :
400+ try :
401+ results = run_command (cf , method , command , params , content , files )
402+ write_results (results , output )
403+ except Exception as e :
404+ if len (commands ) > 1 :
405+ continue
392406
393407def cli4 (args ):
394408 """Cloudflare API via command line"""
0 commit comments