Add a qmk clone command

This commit is contained in:
skullY
2019-06-30 22:54:02 -07:00
parent 680c786cd8
commit b0b746664f
2 changed files with 43 additions and 0 deletions
+3
View File
@@ -102,3 +102,6 @@ venv.bak/
# mypy
.mypy_cache/
# QMK
qmk_firmware
+40
View File
@@ -0,0 +1,40 @@
"""Clone a qmk_firmware fork.
"""
import os
import subprocess
from pathlib import Path
from qmk_cli.milc import cli
default_repo = 'qmk_firmware'
default_fork = 'qmk/' + default_repo
default_branch = 'master'
@cli.argument('--baseurl', default='https://github.com', help='The URL all git operations start from.')
@cli.argument('-b', '--branch', default=default_branch, help='The branch to clone.')
@cli.argument('destination', default=os.environ['QMK_HOME'], nargs='?', help='The directory to clone to.')
@cli.argument('fork', default=default_fork, nargs='?', help='The qmk_firmware fork to clone')
@cli.entrypoint('Clone a qmk_firmware fork.')
def main(cli):
qmk_firmware = Path(cli.args.destination)
git_clone = [
'git',
'clone',
'--recurse-submodules',
'--branch=' + cli.config.general.branch,
'/'.join((cli.config.general.baseurl, cli.args.fork)),
cli.args.destination,
]
if qmk_firmware.exists():
cli.log.error('Destination already exists: %s', cli.args.destination)
exit(1)
with subprocess.Popen(git_clone, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p:
for line in p.stdout:
print(line, end='')
if p.returncode != 0:
cli.log.error('git clone exited %d', p.returncode)
else:
cli.log.info('Successfully cloned %s to %s!', cli.args.fork, cli.args.destination)