class documentation

class twisted.python.usage.Completions: (source)

View In Hierarchy

Extra metadata for the shell tab-completion system.

Instance Variable descriptions ex. {"foo" : "use this description for foo instead"} A dict mapping long option names to alternate descriptions. When this variable is defined, the descriptions contained here will override those descriptions provided in the optFlags and optParameters variables.
Instance Variable multiUse ex. ["foo", "bar"] An iterable containing those long option names which may appear on the command line more than once. By default, options will only be completed one time.
Instance Variable mutuallyExclusive ex. [("foo", "bar"), ("bar", "baz")] A sequence of sequences, with each sub-sequence containing those long option names that are mutually exclusive. That is, those options that cannot appear on the command line together.
Instance Variable optActions A dict mapping long option names to shell "actions". These actions define what may be completed as the argument to the given option. By default, all files/dirs will be completed if no action is given. For example:
    {"foo"    : CompleteFiles("*.py", descr="python files"),
     "bar"    : CompleteList(["one", "two", "three"]),
     "colors" : CompleteMultiList(["red", "green", "blue"])}

Callables may instead be given for the values in this dict. The callable should accept no arguments, and return a Completer instance used as the action in the same way as the literal actions in the example above.

As you can see in the example above. The "foo" option will have files that end in .py completed when the user presses Tab. The "bar" option will have either of the strings "one", "two", or "three" completed when the user presses Tab.

"colors" will allow multiple arguments to be completed, separated by commas. The possible arguments are red, green, and blue. Examples:

    my_command --foo some-file.foo --colors=red,green
    my_command --colors=green
    my_command --colors=green,blue

Descriptions for the actions may be given with the optional descr keyword argument. This is separate from the description of the option itself.

Normally Zsh does not show these descriptions unless you have "verbose" completion turned on. Turn on verbosity with this in your ~/.zshrc:

    zstyle ':completion:*' verbose yes
    zstyle ':completion:*:descriptions' format '%B%d%b'
Instance Variable extraActions Extra arguments are those arguments typically appearing at the end of the command-line, which are not associated with any particular named option. That is, the arguments that are given to the parseArgs() method of your usage.Options subclass. For example:
    [CompleteFiles(descr="file to read from"),
     Completer(descr="book title")]

In the example above, the 1st non-option argument will be described as "file to read from" and all file/dir names will be completed (*). The 2nd non-option argument will be described as "book title", but no actual completion matches will be produced.

See the various Completer subclasses for other types of things which may be tab-completed (users, groups, network interfaces, etc).

Also note the repeat=True flag which may be passed to any of the Completer classes. This is set to allow the Completer instance to be re-used for subsequent command-line words. See the Completer docstring for details.

Method __init__ Undocumented
descriptions = (source)
ex. {"foo" : "use this description for foo instead"} A dict mapping long option names to alternate descriptions. When this variable is defined, the descriptions contained here will override those descriptions provided in the optFlags and optParameters variables.
(type: dict)
multiUse = (source)
ex. ["foo", "bar"] An iterable containing those long option names which may appear on the command line more than once. By default, options will only be completed one time.
(type: list)
mutuallyExclusive = (source)
ex. [("foo", "bar"), ("bar", "baz")] A sequence of sequences, with each sub-sequence containing those long option names that are mutually exclusive. That is, those options that cannot appear on the command line together.
(type: list of tuple)
optActions = (source)
A dict mapping long option names to shell "actions". These actions define what may be completed as the argument to the given option. By default, all files/dirs will be completed if no action is given. For example:
    {"foo"    : CompleteFiles("*.py", descr="python files"),
     "bar"    : CompleteList(["one", "two", "three"]),
     "colors" : CompleteMultiList(["red", "green", "blue"])}

Callables may instead be given for the values in this dict. The callable should accept no arguments, and return a Completer instance used as the action in the same way as the literal actions in the example above.

As you can see in the example above. The "foo" option will have files that end in .py completed when the user presses Tab. The "bar" option will have either of the strings "one", "two", or "three" completed when the user presses Tab.

"colors" will allow multiple arguments to be completed, separated by commas. The possible arguments are red, green, and blue. Examples:

    my_command --foo some-file.foo --colors=red,green
    my_command --colors=green
    my_command --colors=green,blue

Descriptions for the actions may be given with the optional descr keyword argument. This is separate from the description of the option itself.

Normally Zsh does not show these descriptions unless you have "verbose" completion turned on. Turn on verbosity with this in your ~/.zshrc:

    zstyle ':completion:*' verbose yes
    zstyle ':completion:*:descriptions' format '%B%d%b'
(type: dict)
extraActions = (source)
Extra arguments are those arguments typically appearing at the end of the command-line, which are not associated with any particular named option. That is, the arguments that are given to the parseArgs() method of your usage.Options subclass. For example:
    [CompleteFiles(descr="file to read from"),
     Completer(descr="book title")]

In the example above, the 1st non-option argument will be described as "file to read from" and all file/dir names will be completed (*). The 2nd non-option argument will be described as "book title", but no actual completion matches will be produced.

See the various Completer subclasses for other types of things which may be tab-completed (users, groups, network interfaces, etc).

Also note the repeat=True flag which may be passed to any of the Completer classes. This is set to allow the Completer instance to be re-used for subsequent command-line words. See the Completer docstring for details.

(type: list)
def __init__(self, descriptions={}, multiUse=[], mutuallyExclusive=[], optActions={}, extraActions=[]): (source)

Undocumented

API Documentation for Twisted, generated by pydoctor 20.12.1 at 2021-02-28 19:53:36.