

def shellComplete(config, cmdName, words, shellCompFile):
    '\n    Perform shell completion.\n\n    A completion function (shell script) is generated for the requested\n    shell and written to C{shellCompFile}, typically C{stdout}. The result\n    is then eval\'d by the shell to produce the desired completions.\n\n    @type config: L{twisted.python.usage.Options}\n    @param config: The L{twisted.python.usage.Options} instance to generate\n        completions for.\n\n    @type cmdName: C{str}\n    @param cmdName: The name of the command we\'re generating completions for.\n        In the case of zsh, this is used to print an appropriate\n        "#compdef $CMD" line at the top of the output. This is\n        not necessary for the functionality of the system, but it\n        helps in debugging, since the output we produce is properly\n        formed and may be saved in a file and used as a stand-alone\n        completion function.\n\n    @type words: C{list} of C{str}\n    @param words: The raw command-line words passed to use by the shell\n        stub function. argv[0] has already been stripped off.\n\n    @type shellCompFile: C{file}\n    @param shellCompFile: The file to write completion data to.\n    '
    (shellName, position) = words[(- 1)].split(':')
    position = int(position)
    position -= 2
    cWord = words[position]
    while (position >= 1):
        if words[(position - 1)].startswith('-'):
            position -= 1
        else:
            break
    words = words[:position]
    subCommands = getattr(config, 'subCommands', None)
    if subCommands:
        args = None
        try:
            (opts, args) = getopt.getopt(words, config.shortOpt, config.longOpt)
        except getopt.error:
            pass
        if args:
            for (cmd, short, parser, doc) in config.subCommands:
                if ((args[0] == cmd) or (args[0] == short)):
                    subOptions = parser()
                    subOptions.parent = config
                    gen = ZshSubcommandBuilder(subOptions, config, cmdName, shellCompFile)
                    gen.write()
                    return
        genSubs = True
        if cWord.startswith('-'):
            genSubs = False
        gen = ZshBuilder(config, cmdName, shellCompFile)
        gen.write(genSubs=genSubs)
    else:
        gen = ZshBuilder(config, cmdName, shellCompFile)
        gen.write()

dataset/ETHPy150Open nlloyd/SubliminalCollaborator/libs/twisted/python/_shellcomp.py shellComplete/original