Beispiel #1
0
 def test_double_quotes(self):
     my_config = self._get_config("[ALIASES]\n"
         "diff=diff -r -2..-1 --diff-options "
         "\"--strip-trailing-cr -wp\"\n")
     self.assertEqual([u'diff', u'-r', u'-2..-1', u'--diff-options',
                       u'--strip-trailing-cr -wp'],
                       commands.get_alias("diff", config=my_config))
Beispiel #2
0
    def default(self, line):
        args = shlex.split(line)
        alias_args = get_alias(args[0])
        if alias_args is not None:
            args[0] = alias_args.pop(0)

        commandname = args.pop(0)
        for char in ('|', '<', '>'):
            commandname = commandname.split(char)[0]
        if commandname[-1] in ('|', '<', '>'):
            commandname = commandname[:-1]
        try:
            if commandname in SHELL_BLACKLIST:
                raise BlackListedCommand(commandname)
            cmd_obj = get_cmd_object(commandname)
        except (BlackListedCommand, BzrError):
            return os.system(line)

        try:
            if too_complicated(line):
                return os.system("bzr "+line)
            else:
                return (cmd_obj.run_argv_aliases(args, alias_args) or 0)
        except BzrError, e:
            print e
Beispiel #3
0
    def default(self, line):
        args = shlex.split(line)
        alias_args = get_alias(args[0])
        if alias_args is not None:
            args[0] = alias_args.pop(0)

        commandname = args.pop(0)
        for char in ('|', '<', '>'):
            commandname = commandname.split(char)[0]
        if commandname[-1] in ('|', '<', '>'):
            commandname = commandname[:-1]
        try:
            if commandname in SHELL_BLACKLIST:
                raise BlackListedCommand(commandname)
            cmd_obj = get_cmd_object(commandname)
        except (BlackListedCommand, BzrError):
            return os.system(line)

        try:
            if too_complicated(line):
                return os.system("bzr " + line)
            else:
                return (cmd_obj.run_argv_aliases(args, alias_args) or 0)
        except BzrError, e:
            print e
Beispiel #4
0
    def complete_command(self):

        self.cmdname = self.args[0]

        alias_args = commands.get_alias(self.cmdname)
        if alias_args is not None:
            self.cmdname = alias_args.pop(0)

        try:
            self.cmdobj = commands.get_cmd_object(self.cmdname)
        except BzrCommandError:
            self.cmdobj = None

        if 0 < len(self.arglead):

            if '-' == self.arglead[0]:
                return self.complete_options()

            if '~' == self.arglead[0]:
                self.arglead = os.path.expanduser(self.arglead)

        olddir = os.getcwd()
        os.chdir(self.workdir)

        try:
            paths = glob.iglob(self.arglead + '*')
            paths = [ fix_path(path) for path in paths ]
        finally:
            os.chdir(olddir)

        return paths
Beispiel #5
0
 def test_double_quotes(self):
     my_config = self._get_config("[ALIASES]\n"
                                  "diff=diff -r -2..-1 --diff-options "
                                  "\"--strip-trailing-cr -wp\"\n")
     self.assertEqual([
         u'diff', u'-r', u'-2..-1', u'--diff-options',
         u'--strip-trailing-cr -wp'
     ], commands.get_alias("diff", config=my_config))
Beispiel #6
0
def help(topic=None, outfile=None):
    """Write the help for the specific topic to outfile"""
    if outfile is None:
        outfile = sys.stdout

    indices = HelpIndices()

    alias = _mod_commands.get_alias(topic)
    try:
        topics = indices.search(topic)
        shadowed_terms = []
        for index, topic in topics[1:]:
            shadowed_terms.append('%s%s' % (index.prefix,
                topic.get_help_topic()))
        outfile.write(topics[0][1].get_help_text(shadowed_terms))
    except errors.NoHelpTopic:
        if alias is None:
            raise

    if alias is not None:
        outfile.write("'bzr %s' is an alias for 'bzr %s'.\n" % (topic,
            " ".join(alias)))
Beispiel #7
0
def help(topic=None, outfile=None):
    """Write the help for the specific topic to outfile"""
    if outfile is None:
        outfile = sys.stdout

    indices = HelpIndices()

    alias = _mod_commands.get_alias(topic)
    try:
        topics = indices.search(topic)
        shadowed_terms = []
        for index, topic in topics[1:]:
            shadowed_terms.append('%s%s' %
                                  (index.prefix, topic.get_help_topic()))
        outfile.write(topics[0][1].get_help_text(shadowed_terms))
    except errors.NoHelpTopic:
        if alias is None:
            raise

    if alias is not None:
        outfile.write("'bzr %s' is an alias for 'bzr %s'.\n" %
                      (topic, " ".join(alias)))
Beispiel #8
0
def help(topic=None, outfile=None):
    """Write the help for the specific topic to outfile"""
    if outfile is None:
        outfile = ui.ui_factory.make_output_stream()

    indices = HelpIndices()

    alias = _mod_commands.get_alias(topic)
    try:
        topics = indices.search(topic)
        shadowed_terms = []
        for index, topic_obj in topics[1:]:
            shadowed_terms.append('%s%s' % (index.prefix,
                topic_obj.get_help_topic()))
        source = topics[0][1]
        outfile.write(source.get_help_text(shadowed_terms))
    except errors.NoHelpTopic:
        if alias is None:
            raise

    if alias is not None:
        outfile.write("'bzr %s' is an alias for 'bzr %s'.\n" % (topic,
            " ".join(alias)))
Beispiel #9
0
 def test_unicode(self):
     my_config = self._get_config("[ALIASES]\n"
         u"iam=whoami 'Erik B\u00e5gfors <*****@*****.**>'\n")
     self.assertEqual([u'whoami', u'Erik B\u00e5gfors <*****@*****.**>'],
                       commands.get_alias("iam", config=my_config))
Beispiel #10
0
 def test_simple(self):
     my_config = self._get_config("[ALIASES]\n"
         "diff=diff -r -2..-1\n")
     self.assertEqual([u'diff', u'-r', u'-2..-1'],
         commands.get_alias("diff", config=my_config))
Beispiel #11
0
 def test_unicode(self):
     my_config = self._get_config(
         "[ALIASES]\n"
         u"iam=whoami 'Erik B\u00e5gfors <*****@*****.**>'\n")
     self.assertEqual([u'whoami', u'Erik B\u00e5gfors <*****@*****.**>'],
                      commands.get_alias("iam", config=my_config))
Beispiel #12
0
 def test_simple(self):
     my_config = self._get_config("[ALIASES]\n" "diff=diff -r -2..-1\n")
     self.assertEqual([u'diff', u'-r', u'-2..-1'],
                      commands.get_alias("diff", config=my_config))
Beispiel #13
0
 def test_unicode(self):
     my_config = self._get_config("[ALIASES]\n" u'iam=whoami "Erik B\u00e5gfors <*****@*****.**>"\n')
     self.assertEqual(
         [u"whoami", u"Erik B\u00e5gfors <*****@*****.**>"], commands.get_alias("iam", config=my_config)
     )
Beispiel #14
0
 def test_double_quotes(self):
     my_config = self._get_config("[ALIASES]\n" "diff=diff -r -2..-1 --diff-options " '"--strip-trailing-cr -wp"\n')
     self.assertEqual(
         [u"diff", u"-r", u"-2..-1", u"--diff-options", u"--strip-trailing-cr -wp"],
         commands.get_alias("diff", config=my_config),
     )