feat(webpage): add push subcommand with -f flag
新增 `mytoolkit webpage push <name>` 用于推送项目源码仓库, 支持 `-f/--force` 选项(内部使用 --force-with-lease)。
This commit is contained in:
@@ -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) |
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user