diff --git a/src/cli/main.cpp b/src/cli/main.cpp index ea2b453..9604d77 100644 --- a/src/cli/main.cpp +++ b/src/cli/main.cpp @@ -120,21 +120,26 @@ Arguments parse_args(int argc, char** argv) { } void print_usage() { - std::cout << "openbmh_cli --data [--seed ] [--text|--json] [--log ]\n" - "openbmh_cli --replay [--data ] [--text|--json]\n" - "openbmh_cli --console --data [--saves ] [--seed ] [--text|--json] [--echo]\n" - " [--log|--replay [--keep-going]] [--serve | --listen ] [--seats N]\n" - " --listen: the console on 127.0.0.1:, 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" - " --seats N: one mailbox /seat per manager; a request \"WaitTurn\" waits for k's turn.\n" - " --resume : with --seats, first play an earlier session log again, then go on.\n" - "openbmh_cli --send [--timeout ] (the block on stdin)\n" - " --serve: the session answers blocks dropped into (request-N.txt -> response-N.txt);\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" - " 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" - "Text: new [strength], load/save , kickoff, status, desk, quit\n"; + std::cout + << "openbmh_cli --mod [--seed ] [--text|--json] [--log ]\n" + "openbmh_cli --replay [--mod ] [--text|--json]\n" + "openbmh_cli --console --mod [--saves ] [--seed ] [--text|--json] [--echo]\n" + " [--log|--replay [--keep-going]] [--serve | --listen ] [--seats " + "N]\n" + " --listen: the console on 127.0.0.1:, 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" + " --seats N: one mailbox /seat per manager; a request \"WaitTurn\" waits for k's turn.\n" + " --resume : with --seats, first play an earlier session log again, then go on.\n" + "openbmh_cli --send [--timeout ] (the block on stdin)\n" + " --serve: the session answers blocks dropped into (request-N.txt -> response-N.txt);\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" + " 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" + "Text: new [strength], load/save , kickoff, status, desk, " + "quit\n"; } std::string command_line_response(const Json& response) { @@ -714,6 +719,28 @@ int main(int argc, char** argv) { Arguments args = parse_args(argc, argv); if (args.help) { print_usage(); return 0; } 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 contents; std::unique_ptr mount; if (!args.data.empty()) {