0

I am currently working on creating a command line interface using the Python's CMD module.This command line takes multiple arguments for various functions in the form:" command parametre1=value1 parametre2=value2 " and so on .I want to setup an TAB autocomplete feature for the parametre's names along with the command name. The commmand name Autocomplete is done but struggling with the Parametre's autcomplete. Help

1
  • It's not clear what parts of the problem are solved and which ones are unsolved, nor exactly where you have trouble. Commented Feb 29, 2016 at 5:37

1 Answer 1

1

I think this does what you want it to do:

import cmd


class MyCmd(cmd.Cmd):
    def do_command(self, line):
        'do_command: [parametre[1,2]=xxx]'

    def complete_command(self, text, line, begidx, endidx):
        return [i
                for i in ('parametre1=', 'parametre2=')
                if i.startswith(text)]

    def do_EOF(self, line):
        'exit the program. Use  Ctrl-D (Ctrl-Z in Windows) as a shortcut'
        return True

if __name__ == "__main__":
    myCmd = MyCmd()
    myCmd.cmdloop("Welcome! What is your command?")

Reference: https://wiki.python.org/moin/CmdModule#Completion

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.