def invoke(self, entry, modifier, command, args, argstr=None): self.ensure() cmd = completion.single_command([command], 0) if not cmd: raise exceptions.Execute('Could not find command: ' + command) if argstr == None: argstr = ' '.join(args) ret = cmd.execute(argstr, args, entry, modifier) if type(ret) == types.GeneratorType: raise exceptions.Execute('Cannot invoke commands that yield (yet)') else: return ret
def execute(self, argstr, words, entry, modifier, kk={}): fp = self.func_props() kwargs = { 'argstr': argstr, 'args': words, 'entry': entry, 'view': entry.view(), 'modifier': modifier, 'window': entry.view().get_toplevel() } oargs = list(fp.args) args = [] idx = 0 if fp.defaults: numdef = len(fp.defaults) else: numdef = 0 for k in fp.args: if k in kwargs: args.append(kwargs[k]) oargs.remove(k) del kwargs[k] elif idx >= len(words): if numdef < len(oargs): raise exceptions.Execute( 'Invalid number of arguments (need %s)' % (oargs[0], )) else: args.append(words[idx]) oargs.remove(k) idx += 1 # Append the rest if it can handle varargs if fp.varargs and idx < len(words): args.extend(words[idx:]) if not fp.keywords: kwargs = {} for k in kk: kwargs[k] = kk[k] return self.method(*args, **kwargs)
def execute(self, state, argstr, words, wordsstr, entry, modifier): self.ensure() if state: return self._run_generator(state, [argstr, words, modifier]) cmd = completion.single_command(wordsstr, 0) if not cmd: raise exceptions.Execute('Could not find command: ' + wordsstr[0]) if len(words) > 1: argstr = argstr[words[1].start(0):] else: argstr = '' # Execute command return self.run(state, cmd.execute(argstr, wordsstr[1:], entry, modifier))