mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
feat(cli): add cow update
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
import click
|
import click
|
||||||
from cli import __version__
|
from cli import __version__
|
||||||
from cli.commands.skill import skill
|
from cli.commands.skill import skill
|
||||||
from cli.commands.process import start, stop, restart, status, logs
|
from cli.commands.process import start, stop, restart, update, status, logs
|
||||||
from cli.commands.context import context
|
from cli.commands.context import context
|
||||||
|
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ Commands:
|
|||||||
start Start CowAgent.
|
start Start CowAgent.
|
||||||
stop Stop CowAgent.
|
stop Stop CowAgent.
|
||||||
restart Restart CowAgent.
|
restart Restart CowAgent.
|
||||||
|
update Update CowAgent and restart.
|
||||||
status Show CowAgent running status.
|
status Show CowAgent running status.
|
||||||
logs View CowAgent logs.
|
logs View CowAgent logs.
|
||||||
skill Manage CowAgent skills.
|
skill Manage CowAgent skills.
|
||||||
@@ -62,6 +63,7 @@ main.add_command(skill)
|
|||||||
main.add_command(start)
|
main.add_command(start)
|
||||||
main.add_command(stop)
|
main.add_command(stop)
|
||||||
main.add_command(restart)
|
main.add_command(restart)
|
||||||
|
main.add_command(update)
|
||||||
main.add_command(status)
|
main.add_command(status)
|
||||||
main.add_command(logs)
|
main.add_command(logs)
|
||||||
main.add_command(context)
|
main.add_command(context)
|
||||||
|
|||||||
@@ -172,6 +172,46 @@ def restart(ctx, no_logs):
|
|||||||
ctx.invoke(start, no_logs=no_logs)
|
ctx.invoke(start, no_logs=no_logs)
|
||||||
|
|
||||||
|
|
||||||
|
@click.command()
|
||||||
|
@click.pass_context
|
||||||
|
def update(ctx):
|
||||||
|
"""Update CowAgent and restart."""
|
||||||
|
root = get_project_root()
|
||||||
|
|
||||||
|
# 1. Git pull while service is still running
|
||||||
|
if os.path.isdir(os.path.join(root, ".git")):
|
||||||
|
click.echo("Pulling latest code...")
|
||||||
|
ret = subprocess.call(["git", "pull"], cwd=root)
|
||||||
|
if ret != 0:
|
||||||
|
click.echo("Error: git pull failed.", err=True)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
click.echo("Not a git repository, skipping code update.")
|
||||||
|
|
||||||
|
# 2. Stop service
|
||||||
|
ctx.invoke(stop)
|
||||||
|
|
||||||
|
# 3. Install dependencies
|
||||||
|
python = sys.executable
|
||||||
|
req_file = os.path.join(root, "requirements.txt")
|
||||||
|
if os.path.exists(req_file):
|
||||||
|
click.echo("Installing dependencies...")
|
||||||
|
subprocess.call(
|
||||||
|
[python, "-m", "pip", "install", "-r", "requirements.txt", "-q"],
|
||||||
|
cwd=root,
|
||||||
|
)
|
||||||
|
click.echo("Reinstalling cow CLI...")
|
||||||
|
subprocess.call(
|
||||||
|
[python, "-m", "pip", "install", "-e", ".", "-q"],
|
||||||
|
cwd=root,
|
||||||
|
)
|
||||||
|
|
||||||
|
# 4. Start service
|
||||||
|
click.echo("")
|
||||||
|
time.sleep(1)
|
||||||
|
ctx.invoke(start, no_logs=True)
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
def status():
|
def status():
|
||||||
"""Show CowAgent running status."""
|
"""Show CowAgent running status."""
|
||||||
|
|||||||
Reference in New Issue
Block a user