'Generate the completion function and write it to the output file
@return: L{None}
@type genSubs: C{bool}
@param genSubs: Flag indicating whether or not completions for the list
of subcommand should be generated. Only has an effect
if the C{subCommands} attribute has been defined on the
L{twisted.python.usage.Options} instance.'

def write(self, genSubs=True):

    if (genSubs and (getattr(self.options, 'subCommands', None) is not None)):
        gen = ZshArgumentsGenerator(self.options, self.cmdName, self.file)
        gen.extraActions.insert(0, SubcommandAction())
        gen.write()
        self.file.write('local    _zsh_subcmds_array\n_zsh_subcmds_array=(\n')
        for (cmd, short, parser, desc) in self.options.subCommands:
            self.file.write((((('"' + cmd.encode('utf-8')) + ':') + desc.encode('utf-8')) + '"\n'))
        self.file.write(')\n\n')
        self.file.write('_describe    "sub-command"    _zsh_subcmds_array\n')
    else:
        gen = ZshArgumentsGenerator(self.options, self.cmdName, self.file)
        gen.write()
