mirror of
https://github.com/qmk/qmk_cli.git
synced 2026-07-25 16:42:55 -04:00
Fix relative paths if qmk_firmware exists elsewhere (#206)
This commit is contained in:
@@ -8,6 +8,16 @@ from pathlib import Path
|
||||
from milc import cli
|
||||
|
||||
|
||||
def AbsPath(arg):
|
||||
"""Resolve relative paths to the original working directory.
|
||||
"""
|
||||
arg = Path(arg)
|
||||
if not arg.is_absolute():
|
||||
return (Path(os.environ['ORIG_CWD']) / arg).absolute()
|
||||
|
||||
return arg
|
||||
|
||||
|
||||
def is_qmk_firmware(qmk_firmware):
|
||||
"""Returns True if the given Path() is a qmk_firmware clone.
|
||||
"""
|
||||
|
||||
@@ -5,6 +5,7 @@ from pathlib import Path
|
||||
|
||||
from milc import cli
|
||||
from qmk_cli.git import git_clone
|
||||
from qmk_cli.helpers import AbsPath
|
||||
|
||||
default_repo = 'qmk_firmware'
|
||||
default_fork = 'qmk/' + default_repo
|
||||
@@ -13,18 +14,14 @@ default_branch = 'master'
|
||||
|
||||
@cli.argument('--baseurl', arg_only=True, default='https://github.com', help='The URL all git operations start from (Default: https://github.com)')
|
||||
@cli.argument('-b', '--branch', arg_only=True, default=default_branch, help='The branch to clone. Default: %s' % default_branch)
|
||||
@cli.argument('destination', arg_only=True, default=None, nargs='?', help='The directory to clone to. Default: (current directory)')
|
||||
@cli.argument('destination', arg_only=True, default=Path(os.environ['ORIG_CWD']) / default_repo, type=AbsPath, nargs='?', help='The directory to clone to. Default: (current directory)')
|
||||
@cli.argument('fork', arg_only=True, default=default_fork, nargs='?', help='The qmk_firmware fork to clone. Default: %s' % default_fork)
|
||||
@cli.subcommand('Clone a qmk_firmware fork.')
|
||||
def clone(cli):
|
||||
if not cli.args.destination:
|
||||
cli.args.destination = os.path.join(os.environ['ORIG_CWD'], default_fork.split('/')[-1])
|
||||
|
||||
qmk_firmware = Path(cli.args.destination)
|
||||
git_url = '/'.join((cli.args.baseurl, cli.args.fork))
|
||||
|
||||
# Exists (but not an empty dir)
|
||||
if qmk_firmware.exists() and any(qmk_firmware.iterdir()):
|
||||
if cli.args.destination.exists() and any(cli.args.destination.iterdir()):
|
||||
cli.log.error('Destination already exists: %s', cli.args.destination)
|
||||
exit(1)
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from shutil import rmtree
|
||||
from milc import cli
|
||||
from milc.questions import choice, question, yesno
|
||||
from qmk_cli.git import git_clone
|
||||
from qmk_cli.helpers import is_qmk_firmware
|
||||
from qmk_cli.helpers import AbsPath, is_qmk_firmware
|
||||
|
||||
default_base = 'https://github.com'
|
||||
default_repo = 'qmk_firmware'
|
||||
@@ -59,7 +59,7 @@ def git_clone_fork(fork, branch, force=False):
|
||||
@cli.argument('-y', '--yes', arg_only=True, action='store_true', help='Answer yes to all questions')
|
||||
@cli.argument('--baseurl', arg_only=True, default=default_base, help='The URL all git operations start from. Default: %s' % default_base)
|
||||
@cli.argument('-b', '--branch', arg_only=True, default=default_branch, help='The branch to clone. Default: %s' % default_branch)
|
||||
@cli.argument('-H', '--home', arg_only=True, default=Path(os.environ['QMK_HOME']), type=Path, help='The location for QMK Firmware. Default: %s' % os.environ['QMK_HOME'])
|
||||
@cli.argument('-H', '--home', arg_only=True, default=Path(os.environ['QMK_HOME']), type=AbsPath, help='The location for QMK Firmware. Default: %s' % os.environ['QMK_HOME'])
|
||||
@cli.argument('fork', arg_only=True, default=default_fork, nargs='?', help='The qmk_firmware fork to clone. Default: %s' % default_fork)
|
||||
@cli.subcommand('Setup your computer for qmk_firmware.')
|
||||
def setup(cli):
|
||||
|
||||
Reference in New Issue
Block a user