[New-bugs-announce] [issue13214] Cmd: list available completions from the cmd.Cmd subclass and filter out EOF handler(s)

Garrett Cooper report at bugs.python.org
Tue Oct 18 21:16:06 CEST 2011

New submission from Garrett Cooper <yanegomi at gmail.com>:

1. The current code in cmd.get_names does a dir on the derived class for
   cmd.Cmd object instead, which means that if I do something similar to
   the following:

class CLI(cmd.Cmd):
   def register_subcommand(self, cmd, cli_class):
       def call_cli(self):
           cli = cli_class()
       setattr(self, 'do_%s' % (cmd, ), call_cli)

   it won't register the command in the completion list or help list.

2. Registering a do_EOF handler is a bit of a hack to work around
   the fact that entering in ^D on the command line prints out:

   (Cmd) *** Unknown syntax: EOF

   I can't speak to the fact that my desired behavior should be 
   enforced (basically trickle up the EOFError like so):

   def do_EOF(self, arg):
       raise EOFError

   so what I'm proposing instead is that it be filtered out by default.

Given that there's some value in allowing developers to build custom filter rules for the completions (example: certain commands can be undocumented, hidden to lower privilege users, etc), I figured it would be wise to create a custom mechanism for filtering out commands.

This could be cleaned up to use better python idioms like a generator, cache the data and have a refresh method, etc, but this is a good first start.

components: Library (Lib)
files: python-cmd-better-filtering.patch
keywords: patch
messages: 145856
nosy: yaneurabeya
priority: normal
severity: normal
status: open
title: Cmd: list available completions from the cmd.Cmd subclass and filter out EOF handler(s)
type: feature request
versions: Python 2.7, Python 3.4
Added file: http://bugs.python.org/file23449/python-cmd-better-filtering.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list