From 7cd5b04dbcc01afeaaa45c0386cc3689c387ec8c Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 17 Dec 2018 20:55:29 +0200 Subject: [PATCH 1/2] Fix building plugins to file --- maubot/cli/commands/build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maubot/cli/commands/build.py b/maubot/cli/commands/build.py index 0f3201c..ce26d5f 100644 --- a/maubot/cli/commands/build.py +++ b/maubot/cli/commands/build.py @@ -126,8 +126,9 @@ def build(path: str, output: str, upload: bool) -> None: output = BytesIO() os.chdir(path) write_plugin(meta, output) - output.seek(0) if isinstance(output, str): print(f"{Fore.GREEN}Plugin built to {Fore.CYAN}{path}{Fore.GREEN}.{Fore.RESET}") + else: + output.seek(0) if upload: upload_plugin(output) From bddb881945253ac57745b038af0301b7c054c694 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 17 Dec 2018 21:07:34 +0200 Subject: [PATCH 2/2] Allow choosing server to upload built plugin to --- maubot/cli/commands/build.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/maubot/cli/commands/build.py b/maubot/cli/commands/build.py index ce26d5f..699e36f 100644 --- a/maubot/cli/commands/build.py +++ b/maubot/cli/commands/build.py @@ -27,7 +27,7 @@ import click from ...loader import PluginMeta from ..cliq.validators import PathValidator from ..base import app -from ..config import get_default_server +from ..config import get_default_server, get_token from .upload import upload_file yaml = YAML() @@ -97,8 +97,11 @@ def write_plugin(meta: PluginMeta, output: Union[str, IO]) -> None: zip.write(file) -def upload_plugin(output: Union[str, IO]) -> None: - server, token = get_default_server() +def upload_plugin(output: Union[str, IO], server: str) -> None: + if not server: + server, token = get_default_server() + else: + token = get_token(server) if not token: return if isinstance(output, str): @@ -114,9 +117,10 @@ def upload_plugin(output: Union[str, IO]) -> None: @click.argument("path", default=os.getcwd()) @click.option("-o", "--output", help="Path to output built plugin to", 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) -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) if output or not upload: output = read_output_path(output, meta) @@ -131,4 +135,4 @@ def build(path: str, output: str, upload: bool) -> None: else: output.seek(0) if upload: - upload_plugin(output) + upload_plugin(output, server)