def install_command(theme, branch, name):
if re.fullmatch('[_\-A-Z0-9a-z]+', theme):
theme_name = name or theme
theme_path = os.path.join(get_themes_dir(), theme_name)
cmd = 'git clone --branch {} https://github.com/veripress/themes.git {}'.format(theme, theme_path)
else:
m = re.fullmatch('([_\-A-Z0-9a-z]+)/([_\-A-Z0-9a-z]+)', theme)
if not m:
raise click.BadArgumentUsage('The theme should be like "default" (branch of veripress/themes) '
'or "someone/the-theme" (third-party theme on GitHub)')
user = m.group(1)
repo = m.group(2)
theme_name = name or repo
theme_path = os.path.join(get_themes_dir(), theme_name)
cmd = 'git clone --branch {} https://github.com/{}/{}.git {}'.format(branch, user, repo, theme_path)
exit_code = os.system(cmd)
if exit_code == 0:
click.echo('\n"{}" theme has been installed successfully.'.format(theme_name))
else:
click.echo('\nSomething went wrong. Do you forget to install git? '
'Or is there another theme with same name existing?')
评论列表
文章目录