Plan document file saves in app core

This commit is contained in:
2026-06-02 22:42:51 +02:00
parent c8d769c02c
commit 5841878df9
9 changed files with 199 additions and 25 deletions

View File

@@ -96,6 +96,12 @@ struct ClassifyOpenArgs {
std::string path;
};
struct PlanDocumentFileArgs {
std::string work_directory;
std::string name;
bool target_exists = false;
};
struct SimulateAppSessionArgs {
bool has_canvas = true;
bool new_document = false;
@@ -313,6 +319,18 @@ const char* document_workflow_decision_name(pp::app::DocumentWorkflowDecision de
return "unavailable";
}
const char* document_file_write_decision_name(pp::app::DocumentFileWriteDecision decision) noexcept
{
switch (decision) {
case pp::app::DocumentFileWriteDecision::save_now:
return "save-now";
case pp::app::DocumentFileWriteDecision::prompt_overwrite:
return "prompt-overwrite";
}
return "save-now";
}
pp::foundation::Result<float> parse_float_arg(std::string_view text)
{
float value = 0.0F;
@@ -343,6 +361,7 @@ void print_help()
<< " import-image --path FILE [--document-width N] [--document-height N] [--face N] [--x N] [--y N]\n"
<< " inspect-project --path FILE\n"
<< " classify-open --path FILE\n"
<< " plan-document-file --work-dir DIR --name NAME [--target-exists]\n"
<< " load-project --path FILE\n"
<< " parse-layout --path FILE\n"
<< " record-render [--width N] [--height N] [--exercise-clear]\n"
@@ -1184,6 +1203,64 @@ int classify_open(int argc, char** argv)
return 0;
}
pp::foundation::Status parse_plan_document_file_args(
int argc,
char** argv,
PlanDocumentFileArgs& args)
{
for (int i = 2; i < argc; ++i) {
const std::string_view key(argv[i]);
if (key == "--work-dir") {
if (i + 1 >= argc) {
return pp::foundation::Status::invalid_argument("missing value for option");
}
args.work_directory = argv[++i];
} else if (key == "--name") {
if (i + 1 >= argc) {
return pp::foundation::Status::invalid_argument("missing value for option");
}
args.name = argv[++i];
} else if (key == "--target-exists") {
args.target_exists = true;
} else {
return pp::foundation::Status::invalid_argument("unknown option");
}
}
if (args.work_directory.empty()) {
return pp::foundation::Status::invalid_argument("work directory must not be empty");
}
return pp::foundation::Status::success();
}
int plan_document_file(int argc, char** argv)
{
PlanDocumentFileArgs args;
const auto status = parse_plan_document_file_args(argc, argv, args);
if (!status.ok()) {
print_error("plan-document-file", status.message);
return 2;
}
const auto target = pp::app::make_document_file_target(args.work_directory, args.name);
if (!target) {
print_error("plan-document-file", target.status().message);
return 2;
}
const auto write_decision = pp::app::plan_document_file_write(args.target_exists);
std::cout << "{\"ok\":true,\"command\":\"plan-document-file\""
<< ",\"target\":{\"name\":\"" << json_escape(target.value().name)
<< "\",\"directory\":\"" << json_escape(target.value().directory)
<< "\",\"path\":\"" << json_escape(target.value().path)
<< "\",\"exists\":" << json_bool(args.target_exists)
<< "},\"decision\":\""
<< document_file_write_decision_name(write_decision)
<< "\"}\n";
return 0;
}
pp::foundation::Status parse_simulate_app_session_args(
int argc,
char** argv,
@@ -3162,6 +3239,10 @@ int main(int argc, char** argv)
return classify_open(argc, argv);
}
if (command == "plan-document-file") {
return plan_document_file(argc, argv);
}
if (command == "load-project") {
return load_project(argc, argv);
}