Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16522

Passing along cmd.Cmd completion to contained class

Date 2011-12-01 22:02 -0600
From Tim Chase <python.list@tim.thechases.com>
Subject Passing along cmd.Cmd completion to contained class
Newsgroups comp.lang.python
Message-ID <mailman.3214.1322798548.27778.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Passing along cmd.Cmd completion to contained class Tim Chase <python.list@tim.thechases.com> - 2011-12-01 22:02 -0600
  Re: Passing along cmd.Cmd completion to contained class Miki Tebeka <miki.tebeka@gmail.com> - 2011-12-02 07:01 -0800
  Re: Passing along cmd.Cmd completion to contained class Miki Tebeka <miki.tebeka@gmail.com> - 2011-12-02 07:01 -0800

csiph-web