Ejemplo n.º 1
0
    def match_develop(self, text, line_words):
        if len(line_words) == 1:
            return self.top_cmd(text)
        elif len(line_words) == 2:
            # 二级指令
            matches = None
            if not line_words[1].startswith('-'):
                matches = self.sub_cmd(command.Develop.sub_cmd_list, text)

            if not matches:
                # 没有匹配上二级指令
                line_words.insert(1, 'checkout')
                return self.match_develop(text, line_words)

            return matches
        else:
            if line_words[1].startswith('-'):
                line_words.insert(1, 'checkout')

            # 分支或其他
            top_cmd = icommand.real_cmd(line_words[0], raise_err=False)
            sub_cmd = icommand.real_cmd(line_words[1],
                                        raise_err=False,
                                        top_cmd=top_cmd)

            if not sub_cmd:
                return None

            if top_cmd == iconfig.read_config('system',
                                              'branch')['feature_prefix']:
                branch_prefix = top_cmd + '/' + iglobal.SPRINT + '/'
            else:
                branch_prefix = top_cmd

            if text.startswith('-'):
                return self.match_parameter(sub_cmd,
                                            command.Develop.parameters, text)

            if sub_cmd == 'create':
                # 创建分支时,提示远程存在而本地不存在的分支
                return self.match_remoteonly_branch(branch_prefix, text)
            elif sub_cmd == 'product':
                # 此时可能是项目或分支名
                return self.match_project_branch(branch_prefix, text)
            elif sub_cmd == 'checkout':
                iglobal.SILENCE = True
                include_remote = '-r' in line_words or '--remote' in line_words
                match = self.match_branch(branch_prefix, text, include_remote)
                iglobal.SILENCE = False
                return match
            else:
                # 提示分支名
                return self.match_branch(branch_prefix, text)
Ejemplo n.º 2
0
    def help(args):
        cmd = args[0] if args else None
        cmd = cmd and icommand.real_cmd(cmd)

        import readme

        helps = readme.help
        if cmd:
            the_one = helps[cmd] if cmd in helps else None
            if not the_one:
                return
            if isinstance(the_one, str) and the_one in helps:
                the_one = helps[the_one]

            if isinstance(the_one, dict):
                helps = {cmd: the_one}

        for key, info in helps.items():
            if isinstance(info, str):
                continue
            iprint.yellow(info['title'], True)
            if 'desc' in info:
                iprint.sky_blue(info['desc'], True)
            iprint.info(info['content'])
            print
Ejemplo n.º 3
0
    def execute(self):
        # 如果没有提供二级指令,默认为checkout
        if not self.args:
            self.args.insert(0, 'checkout')

        sub_cmd = icommand.real_cmd(self.args[0],
                                    raise_err=False,
                                    top_cmd=self.cmd)

        if not sub_cmd or sub_cmd not in self.sub_cmd_list:
            self.args.insert(0, 'checkout')
            sub_cmd = 'checkout'

        # 调用相应的二级指令处理方法
        eval('self.' + sub_cmd)(self.args[1:])
Ejemplo n.º 4
0
    def match_git(self, text, line_words):
        top_cmd = icommand.real_cmd(line_words[0], raise_err=False)

        if top_cmd in ['delete', 'commit'] and text.startswith('-'):
            return self.match_parameter(top_cmd, command.Git.parameters, text)
        elif top_cmd in ['delete', 'rename']:
            return self.match_branch(None, text)
        elif top_cmd == 'git':
            if not text:
                return None
            elif len(line_words) > 2:
                return self.match_branch(None, text)
            else:
                return [ele + ' ' for ele in iconfig.read_config('system', 'git_common_cmds') if ele.startswith(text)] \
                or [ele + ' ' for ele in igit.sub_cmd_list() if ele.startswith(text)]

        return None
Ejemplo n.º 5
0
    def match(self, text):
        """
        一级指令 二级指令 参数1 参数2 ...
        :type text: str
        :return:
        """
        line = re.compile('\s+').sub(' ', readline.get_line_buffer())
        line_words = line.split(' ')

        if len(line_words) == 1:
            return self.top_cmd(text)
        else:
            cls = iconfig.read_config('system', 'cmd_cls')
            cmd = icommand.real_cmd(line_words[0], raise_err=False)

            if not cmd:
                return None

            return eval('self.match_%s' % str(cls[cmd]).lower())(text,
                                                                 line_words)
Ejemplo n.º 6
0
    def match_extra(self, text=None, line_words=None):
        if len(line_words) == 1:
            return self.top_cmd(text)

        top_cmd = icommand.real_cmd(line_words[0], raise_err=False)

        if not top_cmd:
            return None

        if top_cmd == 'cd':
            projects = ihelper.projects()
            if not text:
                return projects
            else:
                return filter(lambda x: x.startswith(text), projects)
        elif top_cmd == 'help':
            return [ele for ele in self.top_cmd(text) if ele != 'help']
        elif top_cmd == 'sprint':
            return [isprint.next_sprint()]
        else:
            return None
Ejemplo n.º 7
0
        try:
            ihelper.headline()
            # 必须项是否正确(此处为条件检查,因此种检查比较耗时可能)
            if not checked_ok:
                try:
                    ihelper.required_check()
                    checked_ok = True
                except Exception, e:
                    ihelper.warn(unicode(str(e), 'utf-8'))

            # 检查工作区状态是否健康
            if iglobal.PROJECT != 'global' and igit.dir_is_repository():
                igit.check_workspace_health()

            args = raw_input('$ ').strip().lower().decode(
                iglobal.FROM_ENCODING).encode('utf-8')
            args = [ele for ele in args.split(' ') if ele.strip()]

            if args:
                # 执行具体的指令
                try:
                    main_cmd = icommand.real_cmd(args.pop(0))
                    eval('command.' + cfg['cmd_cls'][main_cmd])(
                        main_cmd, args).execute()
                except Exception, e:
                    error(unicode(str(e), 'utf-8'))
        except KeyboardInterrupt:
            print
        except Exception, e:
            print e