Plan export start decisions in app core
This commit is contained in:
@@ -130,6 +130,12 @@ struct PlanExportTargetArgs {
|
||||
std::string suffix;
|
||||
};
|
||||
|
||||
struct PlanExportStartArgs {
|
||||
bool requires_license = false;
|
||||
bool license_valid = true;
|
||||
bool has_canvas = true;
|
||||
};
|
||||
|
||||
struct SimulateAppSessionArgs {
|
||||
bool has_canvas = true;
|
||||
bool new_document = false;
|
||||
@@ -375,6 +381,20 @@ const char* document_file_write_decision_name(pp::app::DocumentFileWriteDecision
|
||||
return "save-now";
|
||||
}
|
||||
|
||||
const char* document_export_start_decision_name(pp::app::DocumentExportStartDecision decision) noexcept
|
||||
{
|
||||
switch (decision) {
|
||||
case pp::app::DocumentExportStartDecision::start_now:
|
||||
return "start-now";
|
||||
case pp::app::DocumentExportStartDecision::show_license_disabled:
|
||||
return "show-license-disabled";
|
||||
case pp::app::DocumentExportStartDecision::unavailable_no_canvas:
|
||||
return "unavailable-no-canvas";
|
||||
}
|
||||
|
||||
return "unavailable-no-canvas";
|
||||
}
|
||||
|
||||
pp::foundation::Result<float> parse_float_arg(std::string_view text)
|
||||
{
|
||||
float value = 0.0F;
|
||||
@@ -409,6 +429,7 @@ void print_help()
|
||||
<< " plan-new-document --work-dir DIR --name NAME [--resolution-index N] [--target-exists]\n"
|
||||
<< " plan-document-file --work-dir DIR --name NAME [--target-exists]\n"
|
||||
<< " plan-document-version --directory DIR --doc-name NAME [--existing-path FILE]\n"
|
||||
<< " plan-export-start [--requires-license] [--demo] [--no-canvas]\n"
|
||||
<< " plan-export-target --kind file|collection|stem|name --doc-name NAME [--work-dir DIR] [--directory DIR] [--extension EXT] [--suffix SUFFIX]\n"
|
||||
<< " load-project --path FILE\n"
|
||||
<< " parse-layout --path FILE\n"
|
||||
@@ -1510,6 +1531,49 @@ int plan_document_version(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_export_start_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanExportStartArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--requires-license") {
|
||||
args.requires_license = true;
|
||||
} else if (key == "--demo") {
|
||||
args.license_valid = false;
|
||||
} else if (key == "--no-canvas") {
|
||||
args.has_canvas = false;
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_export_start(int argc, char** argv)
|
||||
{
|
||||
PlanExportStartArgs args;
|
||||
const auto status = parse_plan_export_start_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-export-start", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto decision = pp::app::plan_document_export_start(
|
||||
args.requires_license,
|
||||
args.license_valid,
|
||||
args.has_canvas);
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-export-start\""
|
||||
<< ",\"state\":{\"requiresLicense\":" << json_bool(args.requires_license)
|
||||
<< ",\"licenseValid\":" << json_bool(args.license_valid)
|
||||
<< ",\"hasCanvas\":" << json_bool(args.has_canvas)
|
||||
<< "},\"decision\":\"" << document_export_start_decision_name(decision)
|
||||
<< "\"}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_export_target_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -3653,6 +3717,10 @@ int main(int argc, char** argv)
|
||||
return plan_document_version(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-export-start") {
|
||||
return plan_export_start(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-export-target") {
|
||||
return plan_export_target(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user