Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Passing along cmd.Cmd completion to contained class

Reply
Thread Tools

Passing along cmd.Cmd completion to contained class

 
 
Tim Chase
Guest
Posts: n/a
 
      12-02-2011
I have sub-classes of cmd.Cmd in an arrangement somewhat like

class Config(cmd.Cmd):
def do_foo(self, line): print "Fooing %r" % line
def complete_foo(self, text, line, begidx, endidx):
...

class MyTUI(cmd.Cmd):
def __init__(self, configger=Config, *args, **kwargs):
cmd.Cmd.__init__(self, *args, **kwargs)
self.config = configger()
def complete_config(self, text, line, begidx, endidx):
magic_here(self.config, text, line, begidx, endidx)

I've been sparring with getting MyTUI.complete_config() to reach
into self.config for completions so I can type things like

(cmd) config <tab>
(cmd) config foo <tab>

and have it suggest from Config as if I had done something like

def do_config(self, line)
self.config.cmdloop()

and then asked for completions. That would mean that the first
one would act like Config.completenames() and the second one
would act like Config.complete_foo(...)

Is there a best way to get this pass-along behavior?

Thanks,

-tkc


 
Reply With Quote
 
 
 
 
Miki Tebeka
Guest
Posts: n/a
 
      12-02-2011
This is not tested, but maybe it'll work

def complete(self, text, state):
if text.startswith('config):
return self.config.complete(text, state)
return Cmd.complete(self, text, state)
 
Reply With Quote
 
 
 
 
Miki Tebeka
Guest
Posts: n/a
 
      12-02-2011
This is not tested, but maybe it'll work

def complete(self, text, state):
if text.startswith('config):
return self.config.complete(text, state)
return Cmd.complete(self, text, state)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem passing a modified string contained within a dataset over a web service eazilyled@yahoo.co.uk ASP .Net Web Services 0 03-12-2007 01:21 PM
Passing form data along with a redirect aomighty@gmail.com HTML 0 07-10-2006 08:29 PM
[PlainVoip] Termination Celebration --- JUST PASSING ALONG... Jonathan Roberts VOIP 0 06-10-2006 03:12 AM
Passing "Style" along to constituent controls Alex Maghen ASP .Net Web Controls 9 06-01-2006 05:47 AM
Spelling Completion or Code completion in ASP? ziggs ASP General 2 04-21-2004 02:02 PM



Advertisments