Resolve native replay and resume paths before mounting content (by Codex)
This commit is contained in:
1 parent
0b2354c979
commit
00f522c1f3
1 file changed
+34
-7
+34
-7
@@ -120,12 +120,15 @@ Arguments parse_args(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void print_usage() {
|
void print_usage() {
|
||||||
std::cout << "openbmh_cli --data <BMH directory> [--seed <n>] [--text|--json] [--log <jsonl>]\n"
|
std::cout
|
||||||
"openbmh_cli --replay <jsonl> [--data <BMH directory>] [--text|--json]\n"
|
<< "openbmh_cli --mod <content.obw> [--seed <n>] [--text|--json] [--log <jsonl>]\n"
|
||||||
"openbmh_cli --console --data <BMH directory> [--saves <dir>] [--seed <n>] [--text|--json] [--echo]\n"
|
"openbmh_cli --replay <jsonl> [--mod <content.obw>] [--text|--json]\n"
|
||||||
" [--log|--replay <jsonl> [--keep-going]] [--serve <dir> | --listen <port>] [--seats N]\n"
|
"openbmh_cli --console --mod <content.obw> [--saves <dir>] [--seed <n>] [--text|--json] [--echo]\n"
|
||||||
|
" [--log|--replay <jsonl> [--keep-going]] [--serve <dir> | --listen <port>] [--seats "
|
||||||
|
"N]\n"
|
||||||
" --listen: the console on 127.0.0.1:<port>, line protocol (SEAT k with --seats; a block ends\n"
|
" --listen: the console on 127.0.0.1:<port>, line protocol (SEAT k with --seats; a block ends\n"
|
||||||
" with go., the answer with a line \".\"); --json gives structured lines, State(view) projections.\n"
|
" with go., the answer with a line \".\"); --json gives structured lines, State(view) "
|
||||||
|
"projections.\n"
|
||||||
" --seats N: one mailbox <dir>/seat<k> per manager; a request \"WaitTurn\" waits for k's turn.\n"
|
" --seats N: one mailbox <dir>/seat<k> per manager; a request \"WaitTurn\" waits for k's turn.\n"
|
||||||
" --resume <jsonl>: with --seats, first play an earlier session log again, then go on.\n"
|
" --resume <jsonl>: with --seats, first play an earlier session log again, then go on.\n"
|
||||||
"openbmh_cli --send <dir> [--timeout <seconds>] (the block on stdin)\n"
|
"openbmh_cli --send <dir> [--timeout <seconds>] (the block on stdin)\n"
|
||||||
@@ -133,8 +136,10 @@ void print_usage() {
|
|||||||
" --send hands one block to it and prints the answer - for agents that work in steps.\n"
|
" --send hands one block to it and prints the answer - for agents that work in steps.\n"
|
||||||
" console language (docs/CLI_CONCEPT): command lines, executed by a line \"go.\";\n"
|
" console language (docs/CLI_CONCEPT): command lines, executed by a line \"go.\";\n"
|
||||||
" ListOptions shows what is possible, Help the reference, Quit ends.\n"
|
" ListOptions shows what is possible, Help the reference, Quit ends.\n"
|
||||||
"Commands: help, new, load, save, status, desk, kickoff, camp.*, bank.*, stadium.*, toto.submit, quit\n"
|
"Commands: help, new, load, save, status, desk, kickoff, camp.*, bank.*, stadium.*, toto.submit, "
|
||||||
"Text: new <master_club> <manager_name> [strength], load/save <path>, kickoff, status, desk, quit\n";
|
"quit\n"
|
||||||
|
"Text: new <master_club> <manager_name> [strength], load/save <path>, kickoff, status, desk, "
|
||||||
|
"quit\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string command_line_response(const Json& response) {
|
std::string command_line_response(const Json& response) {
|
||||||
@@ -714,6 +719,28 @@ int main(int argc, char** argv) {
|
|||||||
Arguments args = parse_args(argc, argv);
|
Arguments args = parse_args(argc, argv);
|
||||||
if (args.help) { print_usage(); return 0; }
|
if (args.help) { print_usage(); return 0; }
|
||||||
if (!args.send.empty()) return run_send(args);
|
if (!args.send.empty()) return run_send(args);
|
||||||
|
// Replay and resumed sessions can supply their content/save paths in
|
||||||
|
// the log header. Resolve them before mounting or selecting defaults.
|
||||||
|
const auto &source_log = !args.replay.empty() ? args.replay : args.resume;
|
||||||
|
if (!source_log.empty()) {
|
||||||
|
std::ifstream input(source_log, std::ios::binary);
|
||||||
|
std::string line;
|
||||||
|
if (!input || !std::getline(input, line))
|
||||||
|
throw std::runtime_error("cannot_read_session_log_header");
|
||||||
|
const auto header = parse_json(line);
|
||||||
|
const auto *fields = header.object();
|
||||||
|
if (!fields || !fields->contains("type") || !fields->at("type").string() ||
|
||||||
|
*fields->at("type").string() != (args.console ? "openbmh_console_log" : "openbmh_cli_log"))
|
||||||
|
throw std::runtime_error("invalid_session_log_header");
|
||||||
|
if (args.data.empty()) {
|
||||||
|
if (!fields->contains("data") || !fields->at("data").string())
|
||||||
|
throw std::runtime_error("missing_session_content_path");
|
||||||
|
args.data = bmh::launch::path_from_utf8(*fields->at("data").string());
|
||||||
|
}
|
||||||
|
if (args.console && args.saves.empty() && fields->contains("saves") &&
|
||||||
|
fields->at("saves").string())
|
||||||
|
args.saves = bmh::launch::path_from_utf8(*fields->at("saves").string());
|
||||||
|
}
|
||||||
std::shared_ptr<const bmh::content::Classic> contents;
|
std::shared_ptr<const bmh::content::Classic> contents;
|
||||||
std::unique_ptr<bmh::content::Mount> mount;
|
std::unique_ptr<bmh::content::Mount> mount;
|
||||||
if (!args.data.empty()) {
|
if (!args.data.empty()) {
|
||||||
|
|||||||
Reference in new issue
Block a user