Feb-05-2017, 10:25 PM
Hello Everyone!
I am new here, and fairly new to python, and I must say I've been missing out for so long.
System: Python 2.7, Cmd Module, OSX.
Issue:
I am using the Cmd module to create a little helper script @ work. It is a CLI Application that works with a REST API.
I have a simple interactive shell component of it, and I am using the CMD module to achieve this, I am able to setup tab completion for specific actions by using the complete_command method, for example:
But, I want to use something similar to:
From what I've searched out there answers to what I could find expect some form of comprehension of readline, etc.. to which I have none.
I am more than happy to do research, but a basic code example would be most helpful, but if possible some form of description as to how it works so I can learn from this.
Any help would be great
I am new here, and fairly new to python, and I must say I've been missing out for so long.
System: Python 2.7, Cmd Module, OSX.
Issue:
I am using the Cmd module to create a little helper script @ work. It is a CLI Application that works with a REST API.
I have a simple interactive shell component of it, and I am using the CMD module to achieve this, I am able to setup tab completion for specific actions by using the complete_command method, for example:
_AVAILABLE_KEYS = ('python','php','ruby') def complete_add(self, text, line, begidx, endidx): return [i for i in self._AVAILABLE_KEYS if i.startswith(text)] def do_example(self,args): if args == 'python': print 'yay!' else: print 'booooooo!'This works great in the case above, when using things like 'example py<tab>'.
But, I want to use something similar to:
_AVAILABLE_KEYS = ('python','php','ruby') def complete_add(self, text, line, begidx, endidx): return [i for i in self._AVAILABLE_KEYS if i.startswith(text)] def do_example(self,args): if len(args) > 1: language = args else: language = raw_input('What is the language of choice?: ') if language == 'python': print 'yay!' else: print 'booooooo!'And of course.. have the user able to use tab complete on the answer.
From what I've searched out there answers to what I could find expect some form of comprehension of readline, etc.. to which I have none.
I am more than happy to do research, but a basic code example would be most helpful, but if possible some form of description as to how it works so I can learn from this.
Any help would be great