summaryrefslogtreecommitdiff
path: root/plugins/alias.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2018-08-15 13:13:17 +0200
committermathieui <mathieui@mathieui.net>2018-08-15 13:13:17 +0200
commit6e13b8b73572f9c0ac9b5c683b98a475afbeab38 (patch)
tree7dae86588339a8cf144b2d98c9280f28646341a9 /plugins/alias.py
parentd1b624753bb5371cf287cc9d86bb685593a99315 (diff)
downloadpoezio-6e13b8b73572f9c0ac9b5c683b98a475afbeab38.tar.gz
poezio-6e13b8b73572f9c0ac9b5c683b98a475afbeab38.tar.bz2
poezio-6e13b8b73572f9c0ac9b5c683b98a475afbeab38.tar.xz
poezio-6e13b8b73572f9c0ac9b5c683b98a475afbeab38.zip
yapf -rip on plugins
Diffstat (limited to 'plugins/alias.py')
-rw-r--r--plugins/alias.py51
1 files changed, 31 insertions, 20 deletions
diff --git a/plugins/alias.py b/plugins/alias.py
index 108fde54..a10beb7c 100644
--- a/plugins/alias.py
+++ b/plugins/alias.py
@@ -71,15 +71,19 @@ from poezio.core.structs import Completion
class Plugin(BasePlugin):
def init(self):
- self.api.add_command('alias', self.command_alias,
- usage='<alias> <command> [args]',
- short='Create an alias command',
- help='Create an alias for <command> with [args].')
- self.api.add_command('unalias', self.command_unalias,
- usage='<alias>',
- help='Remove a previously created alias',
- short='Remove an alias',
- completion=self.completion_unalias)
+ self.api.add_command(
+ 'alias',
+ self.command_alias,
+ usage='<alias> <command> [args]',
+ short='Create an alias command',
+ help='Create an alias for <command> with [args].')
+ self.api.add_command(
+ 'unalias',
+ self.command_unalias,
+ usage='<alias>',
+ help='Remove a previously created alias',
+ short='Remove an alias',
+ completion=self.completion_unalias)
self.commands = {}
self.load_conf()
@@ -114,18 +118,18 @@ class Plugin(BasePlugin):
self.config.set(alias, command + ' ' + args)
self.commands[alias] = command_wrapper(
- generic_command, lambda: self.get_command(command), args)
+ generic_command, lambda: self.get_command(command), args)
self.api.del_command(alias)
- self.api.add_command(alias, self.commands[alias],
- 'This command is an alias for /%s %s' %
- (alias, command))
+ self.api.add_command(
+ alias, self.commands[alias],
+ 'This command is an alias for /%s %s' % (alias, command))
if not silent:
if update:
self.api.information('Alias /%s updated' % alias, 'Info')
else:
self.api.information('Alias /%s successfuly created' % alias,
- 'Info')
+ 'Info')
def command_unalias(self, alias):
"""
@@ -135,19 +139,23 @@ class Plugin(BasePlugin):
del self.commands[alias]
self.api.del_command(alias)
self.config.remove(alias)
- self.api.information('Alias /%s successfuly deleted' % alias, 'Info')
+ self.api.information('Alias /%s successfuly deleted' % alias,
+ 'Info')
def completion_unalias(self, the_input):
"Completion for /unalias"
aliases = [alias for alias in self.commands]
aliases.sort()
- return Completion(the_input.auto_completion, aliases, '', quotify=False)
+ return Completion(
+ the_input.auto_completion, aliases, '', quotify=False)
def get_command(self, name):
"""Returns the function associated with a command"""
+
def dummy(args):
"""Dummy function called if the command doesn’t exist"""
pass
+
if name in self.commands:
return dummy
elif name in self.core.commands:
@@ -156,6 +164,7 @@ class Plugin(BasePlugin):
return self.api.current_tab().commands[name].func
return dummy
+
def split_args(line):
"""
Extract the relevant vars from the command line
@@ -165,16 +174,17 @@ def split_args(line):
return None
alias_pos = line.find(' ')
alias = line[:alias_pos]
- end = line[alias_pos+1:]
+ end = line[alias_pos + 1:]
args_pos = end.find(' ')
if args_pos == -1:
command = end
args = ''
else:
command = end[:args_pos]
- args = end[args_pos+1:]
+ args = end[args_pos + 1:]
return (alias, command, args)
+
def generic_command(command, extra_args, args):
"""
Function that will execute the command and set the relevant
@@ -187,10 +197,11 @@ def generic_command(command, extra_args, args):
new_extra_args += ' '.join(args)
return command()(new_extra_args)
+
def command_wrapper(func, command, extra_args):
"set the predefined arguments"
+
def wrapper(*args, **kwargs):
return func(command, extra_args, *args, **kwargs)
- return wrapper
-
+ return wrapper