]>
jfr.im git - irc/rizon/acid.git/blob - pyva/src/main/python/moo/cmd_manager.py
1 class CommandManager(object):
3 self
.prefix
= self
.get_prefix()
4 #self.invalid = self.get_invalid()
5 self
.commands
= self
.get_commands()
8 def get_command(self
, command
):
9 command
= command
.lower()
11 if not command
.startswith(self
.prefix
):
14 command
= command
[len(self
.prefix
):]
16 if not command
in self
.commands
:
19 command
= self
.commands
[command
]
21 if not isinstance(command
, basestring
):
24 command
= command
.lower()
26 if not command
in self
.commands
:
29 return self
.commands
[command
]
31 def get_commands(self
):
34 def generate_help(self
):
37 # self.help.append('@bCommands@b (type @b%shelp command name@b for detailed information):' % self.prefix)
38 # self.help.append(' ')
44 for cmd
in self
.commands
:
45 if isinstance(self
.commands
[cmd
], basestring
):
46 orig
= self
.commands
[cmd
]
48 if orig
in alias_dict
:
49 alias_dict
[orig
].append(cmd
)
51 alias_dict
[orig
] = [cmd
]
53 if not cmd
in alias_dict
:
56 for key
in alias_dict
:
57 cur
= key
+ ('' if len(alias_dict
[key
]) == 0 else (' (' + ', '.join(alias_dict
[key
]) + ')'))
58 longest
= len(cur
) if len(cur
) > longest
else longest
59 commands
[cur
] = self
.commands
[key
][1]
61 for cmd
in sorted(commands
):
62 self
.help.append('@b%-*s@b %s' % (longest
+ 1, cmd
, commands
[cmd
]))