0

I'm using the cmd.Cmd library for a command line tool that I'm building and am mildly annoyed that using tab to auto-complete a command, the command line is left at the end of the command instead of appending a space to easily facilitate adding arguments.

do_function(self, line):
    print(line)

and

(Cmd)func[TAB] 

gives the user;

"(Cmd)function"

whereas I'd like to see;

"(Cmd)function "

with the space so I can more easily add a value to (in this case) print.

Is there any way to force an appended space after a tab completion? I assume there's an argument I can set in the cmd.Cmd class to force/allow this... but I can't find any documentation on it.

Thanks in advance.

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
Amperand
  • 3
  • 2
  • I don't know a thing about the cmd module, but the documentation says that the `Cmd` class's stdout will default to `sys.stdout` if not specified. I would try manually calling `sys.stdout.write(' ')` after the auto-complete – Nelson Jul 17 '17 at 22:53
  • I suppose that would work if I edited the cmd.Cmd class in that library to append a space, but then I'd change all other instances of cmd.Cmd I have on this machine. It would also require making that modification on any *other* machines I want to use this on... Thanks for the comment, but I don't think it'll work for my needs. – Amperand Jul 17 '17 at 23:46
  • If you cannot find another answer, all I can suggest is you make a copy of the main `Cmd` class, and keep it in the same directory of you app. Import that edited class from the file instead of the module. – Nelson Jul 17 '17 at 23:55
  • You might want to try cmd2, that behaves already like that out of the box. – Leo Mar 29 '18 at 17:30

0 Answers0