Package starcluster :: Module optcomplete
[hide private]
[frames] | no frames]

Module optcomplete

source code

Automatic completion for optparse module.

This module provide automatic bash completion support for programs that use the optparse module. The premise is that the optparse options parser specifies enough information (and more) for us to be able to generate completion strings esily. Another advantage of this over traditional completion schemes where the completion strings are hard-coded in a separate bash source file, is that the same code that parses the options is used to generate the completions, so the completions is always up-to-date with the program itself.

In addition, we allow you specify a list of regular expressions or code that define what kinds of files should be proposed as completions to this file if needed. If you want to implement more complex behaviour, you can instead specify a function, which will be called with the current directory as an argument.

You need to activate bash completion using the shell script function that comes with optcomplete (see http://furius.ca/optcomplete for more details).


Version: $Revision$

Author: Martin Blais <blais@furius.ca>

Classes [hide private]
  AllCompleter
Completes by listing all possible files in current directory.
  NoneCompleter
Generates empty completion list.
  DirCompleter
Completes by listing subdirectories only.
  RegexCompleter
Completes by filtering all possible files with the given list of regexps.
  ListCompleter
Completes by filtering using a fixed list of strings.
  CmdComplete
Simple default base class implementation for a subcommand that supports command completion.
Functions [hide private]
 
extract_word(line, point)
Return a prefix and suffix of the enclosing word.
source code
 
autocomplete(parser, arg_completer=None, opt_completer=None, subcmd_completer=None, subcommands=None)
Automatically detect if we are requested completing and if so generate completion automatically from given parser.
source code
 
error_override(self, msg)
Hack to keep OptionParser from writing to sys.stderr when calling self.exit from self.error
source code
 
guess_first_nonoption(gparser, subcmds_map)
Given a global options parser, try to guess the first non-option without generating an exception.
source code
 
test() source code
Variables [hide private]
  debugfn = '/home/jtriley/.starcluster/logs/completion-debug.log'
  __package__ = 'starcluster'
Function Details [hide private]

extract_word(line, point)

source code 

Return a prefix and suffix of the enclosing word. The character under the cursor is the first character of the suffix.

autocomplete(parser, arg_completer=None, opt_completer=None, subcmd_completer=None, subcommands=None)

source code 

Automatically detect if we are requested completing and if so generate completion automatically from given parser.

'parser' is the options parser to use.

'arg_completer' is a callable object that gets invoked to produce a list of completions for arguments completion (oftentimes files).

'opt_completer' is the default completer to the options that require a value. 'subcmd_completer' is the default completer for the subcommand arguments.

If 'subcommands' is specified, the script expects it to be a map of command-name to an object of any kind. We are assuming that this object is a map from command name to a pair of (options parser, completer) for the command. If the value is not such a tuple, the method 'autocomplete(completer)' is invoked on the resulting object.

This will attempt to match the first non-option argument into a subcommand name and if so will use the local parser in the corresponding map entry's value. This is used to implement completion for subcommand syntax and will not be needed in most cases.

guess_first_nonoption(gparser, subcmds_map)

source code 

Given a global options parser, try to guess the first non-option without generating an exception. This is used for scripts that implement a subcommand syntax, so that we can generate the appropriate completions for the subcommand.