本文整理汇总了Python中horizons.command.Command.get_all_commands方法的典型用法代码示例。如果您正苦于以下问题:Python Command.get_all_commands方法的具体用法?Python Command.get_all_commands怎么用?Python Command.get_all_commands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.command.Command
的用法示例。
在下文中一共展示了Command.get_all_commands方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from horizons.command import Command [as 别名]
# 或者: from horizons.command.Command import get_all_commands [as 别名]
def execute(cmd_name, *args, **kwargs):
"""Execute any available command in the session.
The name of the command is case-insensitive, and you can leave off any occurence of
'Command' in the name. If an error occurs creating a command, the constructor will
be printed.
Examples:
cmd('Pause')
cmd('pAuse')
cmd('PauseCommand')
cmd('CreateUnit', player.worldid, UNITS.FRIGATE_CLASS, 10, 13)
"""
import horizons.main
simplify_cmd_name = lambda x: x.replace('Command', '').lower()
global commands
if not commands:
commands = dict([(simplify_cmd_name(cmd.__name__), cmd) for cmd in Command.get_all_commands()])
try:
cmd_class = commands[simplify_cmd_name(cmd_name)]
except KeyError:
print "Unknown command '%s'" % cmd_name
return
try:
cmd = cmd_class(*args, **kwargs)
except TypeError:
# in case of an error, print out the class constructor
# help the caller figure out the needed arguments for this command
shell.inspector.pdef(cmd_class)
return
return cmd.execute(horizons.main._modules.session)