source: publico/il.spdo/trunk/PasteScript-1.7.4.2-py2.6.egg/paste/script/help.py @ 5327

Última Alteração nesse arquivo desde 5327 foi 5327, incluída por fabianosantos, 8 anos atrás

Import inicial.

File size: 1.9 KB
Linha 
1# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
2# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
3from command import Command, get_commands
4from command import parser as base_parser
5
6class HelpCommand(Command):
7
8    summary = "Display help"
9    usage = '[COMMAND]'
10
11    max_args = 1
12
13    parser = Command.standard_parser()
14
15    def command(self):
16        if not self.args:
17            self.generic_help()
18            return
19
20        name = self.args[0]
21        commands = get_commands()
22        if name not in commands:
23            print 'No such command: %s' % name
24            self.generic_help()
25            return
26
27        command = commands[name].load()
28        runner = command(name)
29        runner.run(['-h'])
30       
31    def generic_help(self):
32        base_parser.print_help()
33        print
34        commands_grouped = {}
35        commands = get_commands()
36        longest = max([len(n) for n in commands.keys()])
37        for name, command in commands.items():
38            try:
39                command = command.load()
40            except Exception, e:
41                print 'Cannot load command %s: %s' % (name, e)
42                continue
43            if getattr(command, 'hidden', False):
44                continue
45            commands_grouped.setdefault(
46                command.group_name, []).append((name, command))
47        commands_grouped = commands_grouped.items()
48        commands_grouped.sort()
49        print 'Commands:'
50        for group, commands in commands_grouped:
51            if group:
52                print group + ':'
53            commands.sort()
54            for name, command in commands:
55                print '  %s  %s' % (self.pad(name, length=longest),
56                                    command.summary)
57                #if command.description:
58                #    print self.indent_block(command.description, 4)
59            print
60       
Note: Veja TracBrowser para ajuda no uso do navegador do trac.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.