+from stgit import argparse, run, utils
+from stgit.config import config
+
+class CommandAlias(object):
+ def __init__(self, name, command):
+ self.__command = command
+ self.__name__ = name
+ self.usage = ['<arguments>']
+ self.help = 'Alias for "%s <arguments>".' % self.__command
+ self.options = []
+
+ def func(self, args):
+ cmd = self.__command.split() + args
+ p = run.Run(*cmd)
+ p.discard_exitcode().run()
+ return p.exitcode
+
+def is_cmd_alias(cmd):
+ return isinstance(cmd, CommandAlias)
+
+def append_alias_commands(cmd_list):
+ for (name, command) in config.getstartswith('stgit.alias.'):
+ name = utils.strip_prefix('stgit.alias.', name)
+ cmd_list[name] = (CommandAlias(name, command),
+ 'Alias commands', command)