示例#1
0
def main():
    parser = argparse.ArgumentParser(description=(
        'Gitless: a version control system built on top of Git.\nMore info, '
        'downloads and documentation at {0}'.format(URL)),
                                     formatter_class=argparse.
                                     RawDescriptionHelpFormatter)
    parser.add_argument(
        '--version',
        action='version',
        version=
        ('GL Version: {0}\nYou can check if there\'s a new version of Gitless '
         'available at {1}'.format(__version__, URL)))
    subparsers = parser.add_subparsers(title='subcommands', dest='subcmd_name')
    subparsers.required = True

    sub_cmds = [
        gl_track, gl_untrack, gl_status, gl_diff, gl_commit, gl_branch, gl_tag,
        gl_checkout, gl_merge, gl_resolve, gl_fuse, gl_remote, gl_publish,
        gl_switch, gl_init, gl_history
    ]
    for sub_cmd in sub_cmds:
        sub_cmd.parser(subparsers, repo)

    if len(sys.argv) == 1:
        print_help(parser)
        return SUCCESS

    args = parser.parse_args()
    try:
        if args.subcmd_name != 'init' and not repo:
            raise core.NotInRepoError('You are not in a Gitless\'s repository')

        return SUCCESS if args.func(args, repo) else ERRORS_FOUND
    except KeyboardInterrupt:
        pprint.puts('\n')
        pprint.msg('Keyboard interrupt detected, operation aborted')
        return SUCCESS
    except core.NotInRepoError as e:
        pprint.err(e)
        pprint.err_exp(
            'do gl init to turn this directory into an empty repository')
        pprint.err_exp(
            'do gl init remote_repo to clone an existing repository')
        return NOT_IN_GL_REPO
    except (ValueError, pygit2.GitError, core.GlError) as e:
        pprint.err(e)
        return ERRORS_FOUND
    except ErrorReturnCode as e:
        pprint.err(e.stderr)
        return ERRORS_FOUND
    except:
        pprint.err('Some internal error occurred')
        pprint.err_exp(
            'If you want to help, see {0} for info on how to report bugs and '
            'include the following information:\n\n{1}\n\n{2}'.format(
                URL, __version__, traceback.format_exc()))
        return INTERNAL_ERROR
示例#2
0
文件: gl.py 项目: chenrui333/gitless
def main():
    sub_cmds = [
        gl_track, gl_untrack, gl_status, gl_diff, gl_commit, gl_branch, gl_tag,
        gl_checkout, gl_merge, gl_resolve, gl_fuse, gl_remote, gl_publish,
        gl_switch, gl_init, gl_history
    ]

    parser = build_parser(sub_cmds, repo)
    argcomplete.autocomplete(parser)
    if len(sys.argv) == 1:
        print_help(parser)
        return SUCCESS

    args = parser.parse_args()
    try:
        if args.subcmd_name != 'init' and not repo:
            raise core.NotInRepoError('You are not in a Gitless\'s repository')

        setup_windows_console()
        return SUCCESS if args.func(args, repo) else ERRORS_FOUND
    except KeyboardInterrupt:
        pprint.puts('\n')
        pprint.msg('Keyboard interrupt detected, operation aborted')
        return SUCCESS
    except core.NotInRepoError as e:
        pprint.err(e)
        pprint.err_exp(
            'do gl init to turn this directory into an empty repository')
        pprint.err_exp(
            'do gl init remote_repo to clone an existing repository')
        return NOT_IN_GL_REPO
    except (ValueError, pygit2.GitError, core.GlError) as e:
        pprint.err(e)
        return ERRORS_FOUND
    except CalledProcessError as e:
        pprint.err(e.stderr)
        return ERRORS_FOUND
    except:
        pprint.err('Some internal error occurred')
        pprint.err_exp(
            'If you want to help, see {0} for info on how to report bugs and '
            'include the following information:\n\n{1}\n\n{2}'.format(
                URL, __version__, traceback.format_exc()))
        return INTERNAL_ERROR