Fix the alias plugin

This commit is contained in:
mathieui 2012-01-11 18:13:32 +01:00
parent b2d050a671
commit 92d96f3f36
2 changed files with 8 additions and 5 deletions

View file

@ -21,7 +21,7 @@ class Plugin(BasePlugin):
if alias in self.core.commands or alias in self.commands: if alias in self.core.commands or alias in self.commands:
self.core.information('Alias: command already exists', 'Error') self.core.information('Alias: command already exists', 'Error')
return return
self.commands[alias] = lambda args: self.get_command(command)(parse(common.shell_split(args), tmp_args)) self.commands[alias] = lambda arg: self.get_command(command)(parse(arg, tmp_args))
self.add_command(alias, self.commands[alias], 'This command is an alias for /%s %s' %( command, tmp_args)) self.add_command(alias, self.commands[alias], 'This command is an alias for /%s %s' %( command, tmp_args))
self.core.information('Alias /%s successfuly created' % alias, 'Info') self.core.information('Alias /%s successfuly created' % alias, 'Info')

View file

@ -235,13 +235,16 @@ def parse_secs_to_str(duration=0):
result += '%ss' % secs if secs else '' result += '%ss' % secs if secs else ''
return result return result
def parse_command_args_to_alias(args, strto): def parse_command_args_to_alias(arg, strto):
""" """
Parse command parameters. Parse command parameters.
Numbers can be from 0 to 9. Numbers can be from 0 to 9.
>>> parse_command_args_to_alias(['sdf', 'koin'], '%0 %1') >>> parse_command_args_to_alias('sdf koin', '%1 %0')
"sdf koin" "koin sdf"
""" """
if '%' not in strto:
return strto + arg
args = shell_split(arg)
l = len(args) l = len(args)
dest = '' dest = ''
var_num = False var_num = False
@ -250,7 +253,7 @@ def parse_command_args_to_alias(args, strto):
if not var_num: if not var_num:
dest += i dest += i
elif i in string.digits: elif i in string.digits:
if int(i) < l: if 0 <= int(i) < l:
dest += args[int(i)] dest += args[int(i)]
var_num = False var_num = False
elif i == '%': elif i == '%':