本文整理匯總了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)