From 92f8536604bb0fd771b6934a3424ae4a49128457 Mon Sep 17 00:00:00 2001 From: Zhengshou Lai Date: Tue, 5 May 2026 12:40:10 +0800 Subject: [PATCH] feat(webpage): add push subcommand with -f flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 `mytoolkit webpage push ` 用于推送项目源码仓库, 支持 `-f/--force` 选项(内部使用 --force-with-lease)。 --- README.md | 2 +- bin/commands/webpage.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 30b4f92..25f23f7 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ mytoolkit --help | `latex` | `compile` / `count` | | `bib` | `to-markdown` / `cv-update` | | `video` | `avi-to-mp4` | -| `webpage` | Docusaurus build/list/rebuild | +| `webpage` | Docusaurus build/list/rebuild/deploy/push | | `mail` | IMAP/SMTP client (read/draft/forward/reply, no auto-send) | | `templates` | Register and inspect external template root | | `env` | Manage stored vars (api keys, paths, feishu app credentials) | diff --git a/bin/commands/webpage.py b/bin/commands/webpage.py index 572cd2e..7c07929 100644 --- a/bin/commands/webpage.py +++ b/bin/commands/webpage.py @@ -107,6 +107,42 @@ def webpage_build_serve(name, serve, port): raise click.Abort() +@webpage_cmd.command("push") +@click.argument("name", type=click.Choice(_NAMES, case_sensitive=False)) +@click.option( + "-f", + "--force", + is_flag=True, + help="Force push via --force-with-lease (refuses if upstream moved unexpectedly).", +) +@click.argument("push_args", nargs=-1) +def webpage_push(name, force, push_args): + """Push the webpage project's source repo (`git push`). + + Default pushes the current branch to its tracked upstream. Extra + arguments are forwarded to `git push` (e.g. `origin main`). + """ + svc = get_service(name) + assert svc.project_dir is not None + + if not svc.project_dir.exists(): + click.secho(f"Project directory not found: {svc.project_dir}", fg="red") + raise click.Abort() + + cmd = ["git", "push"] + if force: + cmd.append("--force-with-lease") + if push_args: + cmd.extend(push_args) + + click.secho(f"Pushing {svc.name} ({svc.description}) ...", fg="cyan") + proc = subprocess.run(cmd, cwd=svc.project_dir, env=no_color_env()) + if proc.returncode != 0: + click.secho(f"Push failed for {svc.name} (exit {proc.returncode})", fg="red") + raise click.Abort() + click.secho(f"{svc.name} pushed.", fg="green") + + @webpage_cmd.command("deploy") @click.argument("name", type=click.Choice(_NAMES, case_sensitive=False)) @click.argument("deploy_args", nargs=-1)