Skip to content

Instantly share code, notes, and snippets.

@renegarcia
Last active August 31, 2023 20:45
Show Gist options
  • Save renegarcia/598f5d8dac1c4c462d60abe07c785463 to your computer and use it in GitHub Desktop.
Save renegarcia/598f5d8dac1c4c462d60abe07c785463 to your computer and use it in GitHub Desktop.
A lightweight tool to clone git repositories.
#!/usr/bin/env python3
from subprocess import run
from os.path import split
from cleo import Command, Application
import os
ROOT = {'github': 'git@github.com',
'bitbucket': 'git@bitbucket.org'}
def gitUrl(username, repository, location='github'):
urlTemplate = '{location}:{username}/{repository}.git'
location = ROOT[location]
return urlTemplate.format(
location=location,
username=username,
repository=repository)
def clone(username, repository, location='github'):
url = gitUrl(username, repository, location=location)
completedProcess = run(['git', 'clone', url])
return completedProcess.returncode
class CloneCommand(Command):
'''
Clone a github repository
clone
{username : Username}
{repository : Repository}
{--l|loc=github : Possible options are github or bitbucket. Default is github}
'''
def handle(self):
username = self.argument('username')
repository = self.argument('repository')
location = self.option('loc')
if not location:
location = 'github'
return clone(username, repository, location=location)
application = Application()
application.add(CloneCommand())
if __name__ == '__main__':
application.run()
import setuptools
setuptools.setup(
name='github.py',
version='0.0.1',
license='MIT',
author='Rene Garcia',
author_email='garciamx@gmail.com',
description='Cloning git repos tool',
scripts=['src/github.py'],
install_requires = [
'cleo >= 0.8.1'])
@renegarcia
Copy link
Author

A lightweight tool to clone git repositories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment