Plan save-version targets in app core
This commit is contained in:
@@ -103,6 +103,12 @@ struct PlanDocumentFileArgs {
|
||||
bool target_exists = false;
|
||||
};
|
||||
|
||||
struct PlanDocumentVersionArgs {
|
||||
std::string directory;
|
||||
std::string document_name;
|
||||
std::vector<std::string> existing_paths;
|
||||
};
|
||||
|
||||
struct PlanExportTargetArgs {
|
||||
std::string kind;
|
||||
std::string work_directory;
|
||||
@@ -372,6 +378,7 @@ void print_help()
|
||||
<< " inspect-project --path FILE\n"
|
||||
<< " classify-open --path FILE\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-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"
|
||||
@@ -1272,6 +1279,75 @@ int plan_document_file(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_document_version_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanDocumentVersionArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--directory") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
args.directory = argv[++i];
|
||||
} else if (key == "--doc-name") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
args.document_name = argv[++i];
|
||||
} else if (key == "--existing-path") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
args.existing_paths.push_back(argv[++i]);
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
if (args.directory.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("directory must not be empty");
|
||||
}
|
||||
|
||||
if (args.document_name.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("document name must not be empty");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int plan_document_version(int argc, char** argv)
|
||||
{
|
||||
PlanDocumentVersionArgs args;
|
||||
const auto status = parse_plan_document_version_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-document-version", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
const auto target = pp::app::find_next_document_version_target(
|
||||
args.directory,
|
||||
args.document_name,
|
||||
[&args](const std::string& path) {
|
||||
return std::find(args.existing_paths.begin(), args.existing_paths.end(), path)
|
||||
!= args.existing_paths.end();
|
||||
});
|
||||
if (!target) {
|
||||
print_error("plan-document-version", target.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-document-version\""
|
||||
<< ",\"input\":{\"directory\":\"" << json_escape(args.directory)
|
||||
<< "\",\"documentName\":\"" << json_escape(args.document_name)
|
||||
<< "\",\"existingPaths\":" << args.existing_paths.size()
|
||||
<< "},\"target\":{\"name\":\"" << json_escape(target.value().name)
|
||||
<< "\",\"path\":\"" << json_escape(target.value().path)
|
||||
<< "\"}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_export_target_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -3403,6 +3479,10 @@ int main(int argc, char** argv)
|
||||
return plan_document_file(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-document-version") {
|
||||
return plan_document_version(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-export-target") {
|
||||
return plan_export_target(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user