Last active
September 13, 2015 15:51
-
-
Save reddec/8a8b7a47e6c49b4413d4 to your computer and use it in GitHub Desktop.
Clone private Golang repo to import path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
import argparse | |
import os | |
import shutil | |
from urlparse import urlparse | |
parser = argparse.ArgumentParser(description="Clone GIT repo as GO lang package") | |
parser.add_argument('repo', type=str, nargs=1, help='Repository URL') | |
parser.add_argument('--gopath', action='store', default=os.getenv('GOPATH'), | |
help='GO source dir') | |
args = parser.parse_args() | |
url = urlparse(args.repo[0]) | |
parts = url.path.split('/') | |
if parts[-1].endswith('.git'): | |
parts[-1] = parts[-1][:-4] | |
dirname = os.path.join(args.gopath, "src", url.hostname, *parts) | |
shutil.rmtree(dirname, True) | |
os.makedirs(dirname) | |
subprocess.call(['git', 'clone', args.repo[0], dirname]) | |
subprocess.call(['go', 'get', url.hostname + "/" + "/".join(parts)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: