Allow choosing server to upload built plugin to

This commit is contained in:
Tulir Asokan 2018-12-17 21:07:34 +02:00
parent 7cd5b04dbc
commit bddb881945

View File

@ -27,7 +27,7 @@ import click
from ...loader import PluginMeta from ...loader import PluginMeta
from ..cliq.validators import PathValidator from ..cliq.validators import PathValidator
from ..base import app from ..base import app
from ..config import get_default_server from ..config import get_default_server, get_token
from .upload import upload_file from .upload import upload_file
yaml = YAML() yaml = YAML()
@ -97,8 +97,11 @@ def write_plugin(meta: PluginMeta, output: Union[str, IO]) -> None:
zip.write(file) zip.write(file)
def upload_plugin(output: Union[str, IO]) -> None: def upload_plugin(output: Union[str, IO], server: str) -> None:
server, token = get_default_server() if not server:
server, token = get_default_server()
else:
token = get_token(server)
if not token: if not token:
return return
if isinstance(output, str): if isinstance(output, str):
@ -114,9 +117,10 @@ def upload_plugin(output: Union[str, IO]) -> None:
@click.argument("path", default=os.getcwd()) @click.argument("path", default=os.getcwd())
@click.option("-o", "--output", help="Path to output built plugin to", @click.option("-o", "--output", help="Path to output built plugin to",
type=PathValidator.click_type) type=PathValidator.click_type)
@click.option("-u", "--upload", help="Upload plugin to main server after building", is_flag=True, @click.option("-u", "--upload", help="Upload plugin to server after building", is_flag=True,
default=False) default=False)
def build(path: str, output: str, upload: bool) -> None: @click.option("-s", "--server", help="Server to upload built plugin to")
def build(path: str, output: str, upload: bool, server: str) -> None:
meta = read_meta(path) meta = read_meta(path)
if output or not upload: if output or not upload:
output = read_output_path(output, meta) output = read_output_path(output, meta)
@ -131,4 +135,4 @@ def build(path: str, output: str, upload: bool) -> None:
else: else:
output.seek(0) output.seek(0)
if upload: if upload:
upload_plugin(output) upload_plugin(output, server)