| 998 | } |
| 999 | |
| 1000 | int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, |
| 1001 | cm::optional<cm::StdIo::Console> console) |
| 1002 | { |
| 1003 | // IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx |
| 1004 | if (args.size() > 1) { |
| 1005 | // Copy file |
| 1006 | if (args[1] == "copy" && args.size() > 3) { |
| 1007 | using CommandArgument = |
| 1008 | cmCommandLineArgument<bool(std::string const& value)>; |
| 1009 | |
| 1010 | cm::optional<std::string> targetArg; |
| 1011 | std::vector<CommandArgument> argParsers{ |
| 1012 | { "-t", CommandArgument::Values::One, |
| 1013 | CommandArgument::setToValue(targetArg) }, |
| 1014 | }; |
| 1015 | |
| 1016 | std::vector<std::string> files; |
| 1017 | for (decltype(args.size()) i = 2; i < args.size(); i++) { |
| 1018 | std::string const& arg = args[i]; |
| 1019 | bool matched = false; |
| 1020 | for (auto const& m : argParsers) { |
| 1021 | if (m.matches(arg)) { |
| 1022 | matched = true; |
| 1023 | if (m.parse(arg, i, args)) { |
| 1024 | break; |
| 1025 | } |
| 1026 | return 1; // failed to parse |
| 1027 | } |
| 1028 | } |
| 1029 | if (!matched) { |
| 1030 | files.push_back(arg); |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | // If multiple source files specified, |
| 1035 | // then destination must be directory |
| 1036 | if (files.size() > 2 && !targetArg) { |
| 1037 | targetArg = files.back(); |
| 1038 | files.pop_back(); |
| 1039 | } |
| 1040 | if (targetArg && (!cmSystemTools::FileIsDirectory(*targetArg))) { |
| 1041 | std::cerr << "Error: Target (for copy command) \"" << *targetArg |
| 1042 | << "\" is not a directory.\n"; |
| 1043 | return 1; |
| 1044 | } |
| 1045 | if (!targetArg) { |
| 1046 | if (files.size() < 2) { |
| 1047 | std::cerr |
| 1048 | << "Error: No files or target specified (for copy command).\n"; |
| 1049 | return 1; |
| 1050 | } |
| 1051 | targetArg = files.back(); |
| 1052 | files.pop_back(); |
| 1053 | } |
| 1054 | // If error occurs we want to continue copying next files. |
| 1055 | bool return_value = false; |
| 1056 | for (auto const& file : files) { |
| 1057 | cmsys::SystemTools::CopyStatus const status = |
nothing calls this directly
no test coverage detected