X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmap_cli.cc;h=b158499a8d204628a87ddeb275d102d5f9556242;hb=742d96e86a262d0238105bc869ec8f350e36ccae;hp=e38af69cf08e9773dba3d7b00b18683c06ad434b;hpb=b5abb07ea62e5f4708c57b6f888101d3d3434aa8;p=dcpomatic.git diff --git a/src/lib/map_cli.cc b/src/lib/map_cli.cc index e38af69cf..b158499a8 100644 --- a/src/lib/map_cli.cc +++ b/src/lib/map_cli.cc @@ -56,7 +56,7 @@ using boost::optional; static void help(std::function out) { - out(String::compose("Syntax: %1 [OPTION} [ ... ]", program_name)); + out(String::compose("Syntax: %1 [OPTION} [ ... ]", program_name)); out(" -V, --version show libdcp version"); out(" -h, --help show this help"); out(" -o, --output output directory"); @@ -138,12 +138,12 @@ map_cli(int argc, char* argv[], std::function out) State::override_path = *config_dir; } - vector cpl_filenames; + vector cpl_filenames_or_ids; for (int i = optind; i < argc; ++i) { - cpl_filenames.push_back(argv[i]); + cpl_filenames_or_ids.push_back(argv[i]); } - if (cpl_filenames.empty()) { + if (cpl_filenames_or_ids.empty()) { return string{"No CPL specified."}; } @@ -181,13 +181,28 @@ map_cli(int argc, char* argv[], std::function out) /* Find all the CPLs */ vector> cpls; - for (auto filename: cpl_filenames) { - try { - auto cpl = make_shared(filename); - cpl->resolve_refs(assets); - cpls.push_back(cpl); - } catch (std::exception& e) { - return String::compose("Could not read CPL %1: %2", filename, e.what()); + for (auto filename_or_id: cpl_filenames_or_ids) { + if (boost::filesystem::exists(filename_or_id)) { + try { + auto cpl = make_shared(filename_or_id); + cpl->resolve_refs(assets); + cpls.push_back(cpl); + } catch (std::exception& e) { + return String::compose("Could not read CPL %1: %2", filename_or_id, e.what()); + } + } else { + auto cpl_iter = std::find_if(assets.begin(), assets.end(), [filename_or_id](shared_ptr asset) { + return asset->id() == filename_or_id; + }); + if (cpl_iter == assets.end()) { + return String::compose("Could not find CPL with ID %1", filename_or_id); + } + if (auto cpl = dynamic_pointer_cast(*cpl_iter)) { + cpl->resolve_refs(assets); + cpls.push_back(cpl); + } else { + return String::compose("Could not find CPL with ID %1", filename_or_id); + } } }