Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python cmd completedefault() method not called

Consider the following Python 2.7 script:

#!/usr/bin/python

import cmd

class T(cmd.Cmd):
    def completedefault(self, *a):
        print 'completedefault called'
        return []

t=T()
t.cmdloop()

When I expect:

I type a character into the shell, then hit tab, I expect to see "completedfault called" printed.

What actually happens:

I type a character into the shell, then hit tab, and nothing happens.

Tested with Python 2.7.3.

like image 470
markrages Avatar asked Mar 15 '26 17:03

markrages


1 Answers

completedefault is called to complete a input line after you entered a command for which no complete_<commandname>-method is available.

Try this:

#!/usr/bin/python

import cmd

class T(cmd.Cmd):
    def completedefault(self, *a):
        print 'completedefault called'
        return []

    def test(self, *args):
        print "test args: ", args

t=T()
t.cmdloop()

now enter test [space] and press tab, completedefault should be executed now.

If you want to control completion for command names, you can use completenames to do so, not completedefault.

like image 163
mata Avatar answered Mar 18 '26 05:03

mata



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!