fix: 用户可见的操作提示统一为 uv run 前缀
项目由 uv 管理,依赖装在 .venv。此前各处的提示语仍写作 `python main.py ...`,用户若在未激活虚拟环境时照抄,会因缺少 fastapi 而失败——这是正确性问题,不只是措辞。 涉及:main.py(12 行,含 prog 与各条 hint)、ai_player.py(5 行)、farm/client.py、farm/server/__main__.py(3 行,含 prog)、farm/server/__init__.py、farm/server/daemon.py、README(4 处示例与目录树注释)。 刻意保留 main.py:26 与 README:49 的「没装 uv?」兜底说明,那里 `python main.py` 是正确写法。 验收:ruff 全通过 / format 26 文件无改动 / pyright 0 错误 / 97 项测试通过。
This commit is contained in:
1 parent
d7a7107b0a
commit
c414db4217
7 files changed
+27
-27
No files matched your search
@@ -88,7 +88,7 @@ def die(message: str, hint: str = "", code: int = 1) -> int:
|
||||
# ---------------------------------------------------------------------- 参数
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="python main.py",
|
||||
prog="uv run main.py",
|
||||
description="SimpleFarm:终端农场游戏 + 小型多人游戏服务器(HTTP/WebSocket 供 AI 调用)",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog=BANNER,
|
||||
@@ -222,8 +222,8 @@ def make_client(args, realtime: bool = False):
|
||||
except GameError as exc:
|
||||
hint = (
|
||||
f"服务器地址:{args.url}\n"
|
||||
"先启动服务器:python main.py serve --daemon\n"
|
||||
"再确认地址端口:python main.py status"
|
||||
"先启动服务器:uv run main.py serve --daemon\n"
|
||||
"再确认地址端口:uv run main.py status"
|
||||
)
|
||||
raise SystemExit(die(f"无法连接服务器:{exc.message}", hint)) from None
|
||||
|
||||
@@ -286,7 +286,7 @@ def cmd_status(args) -> int:
|
||||
|
||||
if not info["running"]:
|
||||
print(warn("• 服务器未运行"))
|
||||
print(dim(" 启动:python main.py serve --daemon"))
|
||||
print(dim(" 启动:uv run main.py serve --daemon"))
|
||||
print(dim(f" 地址:http://{args.host}:{args.port}/"))
|
||||
return 1
|
||||
|
||||
@@ -336,7 +336,7 @@ def cmd_play(args) -> int:
|
||||
if not (sys.stdin is not None and sys.stdin.isatty()):
|
||||
return die(
|
||||
"当前终端不是交互式终端,无法启动界面。",
|
||||
"在真实终端里运行,或用命令行模式:python main.py actions / do / watch",
|
||||
"在真实终端里运行,或用命令行模式:uv run main.py actions / do / watch",
|
||||
)
|
||||
client = make_client(args, realtime=not args.no_realtime)
|
||||
label = f"{client.farm} @ {client.host}"
|
||||
@@ -392,7 +392,7 @@ def cmd_do(args) -> int:
|
||||
except json.JSONDecodeError as exc:
|
||||
return die(
|
||||
f"参数不是合法 JSON:{exc}",
|
||||
'例子:python main.py do plant \'{"plot":1,"crop":"wheat"}\'',
|
||||
'例子:uv run main.py do plant \'{"plot":1,"crop":"wheat"}\'',
|
||||
)
|
||||
if not isinstance(params, dict):
|
||||
return die("参数必须是 JSON 对象")
|
||||
@@ -403,7 +403,7 @@ def cmd_do(args) -> int:
|
||||
except GameError as exc:
|
||||
return die(
|
||||
f"{args.action} 失败({exc.code}):{exc.message}",
|
||||
"看看现在能做什么:python main.py actions",
|
||||
"看看现在能做什么:uv run main.py actions",
|
||||
)
|
||||
|
||||
print(ok("✓ ") + str(result.get("message", "完成")) + dim(f" ({time.time() - started:.2f}s)"))
|
||||
@@ -432,7 +432,7 @@ def cmd_batch(args) -> int:
|
||||
except json.JSONDecodeError as exc:
|
||||
return die(
|
||||
f"actions 不是合法 JSON:{exc}",
|
||||
"例子:python main.py batch "
|
||||
"例子:uv run main.py batch "
|
||||
'\'[{"action":"harvest_all"},{"action":"buy_feed","params":{"quantity":5}}]\'',
|
||||
)
|
||||
if not isinstance(items, list):
|
||||
@@ -458,7 +458,7 @@ def cmd_actions(args) -> int:
|
||||
)
|
||||
if not items:
|
||||
print(warn("• 当前没有可执行的动作"))
|
||||
print(dim(" 试试:python main.py do sleep (推进一天)"))
|
||||
print(dim(" 试试:uv run main.py do sleep (推进一天)"))
|
||||
return 0
|
||||
print(f"共 {len(items)} 个候选动作:\n")
|
||||
for index, item in enumerate(items, start=1):
|
||||
@@ -467,7 +467,7 @@ def cmd_actions(args) -> int:
|
||||
params_text = json.dumps(item["params"], ensure_ascii=False)
|
||||
print(f" [{index:>2}] {item['action']:<12} {params_text:<42} ({cost_text})")
|
||||
print(dim(f" {item.get('reason', '')}"))
|
||||
print(dim("\n执行方式:python main.py do <动作名> '<参数JSON>'"))
|
||||
print(dim("\n执行方式:uv run main.py do <动作名> '<参数JSON>'"))
|
||||
return 0
|
||||
|
||||
|
||||
@@ -561,7 +561,7 @@ def cmd_bot(args) -> int:
|
||||
print("\n已中断。")
|
||||
summary = {"actions": bot.actions_executed, "failures": bot.failures}
|
||||
print(json.dumps(summary, ensure_ascii=False))
|
||||
print(dim("提示:机器人和你调的是同一套接口,随时可以用 python main.py actions 接手。"))
|
||||
print(dim("提示:机器人和你调的是同一套接口,随时可以用 uv run main.py actions 接手。"))
|
||||
return 0
|
||||
|
||||
|
||||
@@ -670,7 +670,7 @@ def main(argv=None) -> int:
|
||||
|
||||
handler = handlers.get(args.command)
|
||||
if handler is None:
|
||||
return die(f"未知命令 {args.command}", "python main.py --help 查看全部命令")
|
||||
return die(f"未知命令 {args.command}", "uv run main.py --help 查看全部命令")
|
||||
try:
|
||||
return handler(args)
|
||||
except SystemExit as exc: # make_client 里的友好退出
|
||||
|
||||
Reference in new issue
Block a user