Passing along cmd.Cmd completion to contained class

Tim Chase python.list at tim.thechases.com
Thu Dec 1 23:02:18 EST 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





More information about the Python-list mailing list