Centralize legacy brush package export
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "app_core/app_preferences.h"
|
||||
#include "app_core/app_status.h"
|
||||
#include "app_core/app_startup.h"
|
||||
#include "app_core/brush_package_export.h"
|
||||
#include "app_core/brush_ui.h"
|
||||
#include "app_core/canvas_hotkey.h"
|
||||
#include "app_core/canvas_tool_ui.h"
|
||||
@@ -235,6 +236,17 @@ struct PlanAppStartupArgs {
|
||||
bool license_valid = true;
|
||||
};
|
||||
|
||||
struct PlanBrushPackageExportArgs {
|
||||
std::string path;
|
||||
std::string author;
|
||||
std::string email;
|
||||
std::string url;
|
||||
std::string description;
|
||||
std::string destination_path;
|
||||
bool export_data = false;
|
||||
bool has_header_image = false;
|
||||
};
|
||||
|
||||
struct PlanAppStatusArgs {
|
||||
std::string document_name = "no-name";
|
||||
bool unsaved = false;
|
||||
@@ -1862,6 +1874,7 @@ void print_help()
|
||||
<< " plan-app-preferences [--ui-scale N] [--display-density N] [--current-scale N] [--scale-option N] [--viewport-scale N] [--rtl] [--timelapse-disabled] [--recording-running] [--vr-controllers-disabled] [--cursor-mode N]\n"
|
||||
<< " plan-app-startup [--run-counter N] [--auto-timelapse-disabled] [--vr-controllers-disabled] [--license-invalid]\n"
|
||||
<< " plan-app-status [--doc-name NAME] [--unsaved] [--resolution N] [--resolution-index N] [--zoom N] [--history-bytes N] [--recording-running] [--encoder-available] [--encoded-frames N] [--framebuffer-fetch] [--float32] [--float32-linear] [--float16]\n"
|
||||
<< " plan-brush-package-export --path FILE [--author NAME] [--email EMAIL] [--url URL] [--description TEXT] [--dest-path DIR] [--export-data|--no-export-data] [--header-image]\n"
|
||||
<< " plan-tools-menu --command panels|options|clear-grids|reset-camera|shortcuts|sonarpen [--sonarpen-available]\n"
|
||||
<< " plan-tools-panel --panel presets|color|color-advanced|layers|brush|grids|animation [--already-visible]\n"
|
||||
<< " plan-about-menu --command help|about|news|crash|performance [--version-major N] [--version-minor N] [--version-fix N] [--no-diagnostics] [--no-canvas]\n"
|
||||
@@ -3489,6 +3502,98 @@ int plan_app_startup(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_brush_package_export_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanBrushPackageExportArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--path" || key == "--author" || key == "--email" || key == "--url"
|
||||
|| key == "--description" || key == "--dest-path") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
if (key == "--path") {
|
||||
args.path = argv[++i];
|
||||
} else if (key == "--author") {
|
||||
args.author = argv[++i];
|
||||
} else if (key == "--email") {
|
||||
args.email = argv[++i];
|
||||
} else if (key == "--url") {
|
||||
args.url = argv[++i];
|
||||
} else if (key == "--description") {
|
||||
args.description = argv[++i];
|
||||
} else {
|
||||
args.destination_path = argv[++i];
|
||||
}
|
||||
} else if (key == "--export-data") {
|
||||
args.export_data = true;
|
||||
} else if (key == "--no-export-data") {
|
||||
args.export_data = false;
|
||||
} else if (key == "--header-image") {
|
||||
args.has_header_image = true;
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
class CliBrushPackageExportServices final : public pp::app::BrushPackageExportServices {
|
||||
public:
|
||||
void export_brush_package(std::string_view path, const pp::app::BrushPackageExportRequest& request) override
|
||||
{
|
||||
exports += 1;
|
||||
last_path = std::string(path);
|
||||
last_request = request;
|
||||
}
|
||||
|
||||
int exports = 0;
|
||||
std::string last_path;
|
||||
pp::app::BrushPackageExportRequest last_request;
|
||||
};
|
||||
|
||||
int plan_brush_package_export(int argc, char** argv)
|
||||
{
|
||||
PlanBrushPackageExportArgs args;
|
||||
const auto status = parse_plan_brush_package_export_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-brush-package-export", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
pp::app::BrushPackageExportRequest request;
|
||||
request.author = args.author;
|
||||
request.email = args.email;
|
||||
request.url = args.url;
|
||||
request.description = args.description;
|
||||
request.destination_path = args.destination_path;
|
||||
request.export_data = args.export_data;
|
||||
request.has_header_image = args.has_header_image;
|
||||
|
||||
CliBrushPackageExportServices services;
|
||||
const auto export_status = pp::app::execute_brush_package_export(args.path, request, services);
|
||||
if (!export_status.ok()) {
|
||||
print_error("plan-brush-package-export", export_status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-brush-package-export\""
|
||||
<< ",\"request\":{\"path\":\"" << json_escape(services.last_path)
|
||||
<< "\",\"author\":\"" << json_escape(services.last_request.author)
|
||||
<< "\",\"email\":\"" << json_escape(services.last_request.email)
|
||||
<< "\",\"url\":\"" << json_escape(services.last_request.url)
|
||||
<< "\",\"description\":\"" << json_escape(services.last_request.description)
|
||||
<< "\",\"destPath\":\"" << json_escape(services.last_request.destination_path)
|
||||
<< "\",\"exportData\":" << json_bool(services.last_request.export_data)
|
||||
<< ",\"hasHeaderImage\":" << json_bool(services.last_request.has_header_image)
|
||||
<< "},\"dispatches\":" << services.exports
|
||||
<< "}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_tools_menu_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -8569,6 +8674,10 @@ int main(int argc, char** argv)
|
||||
return plan_app_startup(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-brush-package-export") {
|
||||
return plan_brush_package_export(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-app-status") {
|
||||
return plan_app_status(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user