@@ -246,13 +246,13 @@ def default(self, args):
246246 map (lambda x : x .strip (),
247247 args_dict .pop ('filter' ).split (',' )))
248248
249- missing_args = []
249+ missing = []
250250 if verb in self .apicache and subject in self .apicache [verb ]:
251- missing_args = filter (lambda x : x not in args_dict .keys (),
252- self .apicache [verb ][subject ]['requiredparams' ])
251+ missing = filter (lambda x : x not in args_dict .keys (),
252+ self .apicache [verb ][subject ]['requiredparams' ])
253253
254- if len (missing_args ) > 0 :
255- self .monkeyprint ("Missing arguments: " , ' ' .join (missing_args ))
254+ if len (missing ) > 0 :
255+ self .monkeyprint ("Missing arguments: " , ' ' .join (missing ))
256256 return
257257
258258 isasync = False
@@ -293,12 +293,33 @@ def completedefault(self, text, line, begidx, endidx):
293293 map (lambda x : x ['name' ],
294294 self .apicache [verb ][subject ]['params' ]))
295295 search_string = text
296+ if self .paramcompletion == 'true' :
297+ param = line .split (" " )[- 1 ]
298+ idx = param .find ("=" )
299+ value = param [idx + 1 :]
300+ param = param [:idx ]
301+ if len (value ) < 36 and idx != - 1 :
302+ params = self .apicache [verb ][subject ]['params' ]
303+ related = filter (lambda x : x ['name' ] == param ,
304+ params )[0 ]['related' ]
305+ api = min (filter (lambda x : 'list' in x , related ), key = len )
306+ response = self .make_request (api , args = {'listall' : 'true' })
307+ responsekey = filter (lambda x : 'response' in x ,
308+ response .keys ())[0 ]
309+ result = response [responsekey ]
310+ uuids = []
311+ for key in result .keys ():
312+ if isinstance (result [key ], list ):
313+ for element in result [key ]:
314+ if 'id' in element .keys ():
315+ uuids .append (element ['id' ])
316+ autocompletions = uuids
317+ search_string = value
296318
297319 if self .tabularize == "true" and subject != "" :
298320 autocompletions .append ("filter=" )
299321 return [s for s in autocompletions if s .startswith (search_string )]
300322
301-
302323 def do_sync (self , args ):
303324 """
304325 Asks cloudmonkey to discovery and sync apis available on user specified
@@ -396,7 +417,8 @@ def do_help(self, args):
396417 helpdoc += "\n Required params are %s" % ' ' .join (required )
397418 helpdoc += "\n Parameters\n " + "=" * 10
398419 for param in api ['params' ]:
399- helpdoc += "\n %s = (%s) %s" % (param ['name' ], param ['type' ], param ['description' ])
420+ helpdoc += "\n %s = (%s) %s" % (param ['name' ],
421+ param ['type' ], param ['description' ])
400422 self .monkeyprint (helpdoc )
401423 else :
402424 self .monkeyprint ("Error: no such api (%s) on %s" %
0 commit comments