@@ -111,28 +111,51 @@ def convert_virtual_dns_to_identifier(cf, virtual_dns_name):
111111
112112 exit ('cli4: %s - no virtual_dns found' % (virtual_dns_name ))
113113
114+ def walk (m , s ):
115+ """recursive walk of the tree"""
116+ for n in sorted (dir (m )):
117+ if n [0 ] == '_' :
118+ # internal
119+ continue
120+ if n in ['delete' , 'get' , 'patch' , 'post' , 'put' ]:
121+ # gone too far
122+ continue
123+ a = getattr (m , n )
124+ d = dir (a )
125+ if 'delete' in d or 'get' in d or 'patch' in d or 'post' in d or 'put' in d :
126+ # it's a known api call - lets print it and continue down the tree
127+ print s + '/' + n
128+ walk (a , s + '/' + n )
129+
130+ def dump_commands (cf ):
131+ """dump a tree of all the known API commands"""
132+ walk (cf , '' )
133+
114134def cli4 (args ):
115135 """Cloudflare API via command line"""
116136
117137 verbose = False
118138 output = 'json'
119139 raw = False
140+ dump = False
120141 method = 'GET'
121142
122143 usage = ('usage: cli4 '
123144 + '[-V|--version] [-h|--help] [-v|--verbose] [-q|--quiet] [-j|--json] [-y|--yaml] '
124145 + '[-r|--raw] '
146+ + '[-d|--dump] '
125147 + '[--get|--patch|--post|-put|--delete] '
126148 + '[item=value ...] '
127149 + '/command...' )
128150
129151 try :
130152 opts , args = getopt .getopt (args ,
131- 'VhvqjyrGPOUD ' ,
153+ 'VhvqjyrdGPOUD ' ,
132154 [
133155 'version' ,
134156 'help' , 'verbose' , 'quiet' , 'json' , 'yaml' ,
135157 'raw' ,
158+ 'dump' ,
136159 'get' , 'patch' , 'post' , 'put' , 'delete'
137160 ])
138161 except getopt .GetoptError :
@@ -152,6 +175,8 @@ def cli4(args):
152175 output = 'yaml'
153176 elif opt in ('-r' , '--raw' ):
154177 raw = True
178+ elif opt in ('-d' , '--dump' ):
179+ dump = True
155180 elif opt in ('-G' , '--get' ):
156181 method = 'GET'
157182 elif opt in ('-P' , '--patch' ):
@@ -189,6 +214,11 @@ def cli4(args):
189214 tag = tag_string
190215 params [tag ] = value
191216
217+ if dump :
218+ cf = CloudFlare .CloudFlare ()
219+ dump_commands (cf )
220+ exit (0 )
221+
192222 # what's left is the command itself
193223 if len (args ) != 1 :
194224 exit (usage )
0 commit comments