| 57 | /************************************************************************/ |
| 58 | |
| 59 | bool GDALMainAlgorithm::ParseCommandLineArguments( |
| 60 | const std::vector<std::string> &args) |
| 61 | { |
| 62 | // Detect shortest form of pipeline: |
| 63 | // "gdal read in.tif ! .... ! write out.tif" |
| 64 | if (args.size() >= 2 && args[0] == "read") |
| 65 | { |
| 66 | m_subAlg = |
| 67 | GDALGlobalAlgorithmRegistry::GetSingleton().Instantiate("pipeline"); |
| 68 | if (m_subAlg) |
| 69 | { |
| 70 | bool ret = m_subAlg->ParseCommandLineArguments(args); |
| 71 | if (ret) |
| 72 | { |
| 73 | m_selectedSubAlg = &(m_subAlg->GetActualAlgorithm()); |
| 74 | std::vector<std::string> callPath(m_callPath); |
| 75 | callPath.push_back("vector"); |
| 76 | m_selectedSubAlg->SetCallPath(callPath); |
| 77 | return true; |
| 78 | } |
| 79 | else if (strstr(CPLGetLastErrorMsg(), |
| 80 | "has both raster and vector content")) |
| 81 | { |
| 82 | m_showUsage = false; |
| 83 | return false; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return GDALAlgorithm::ParseCommandLineArguments(args); |
| 88 | } |
| 89 | else if (args.size() == 1 && args[0].size() >= 2 && args[0][0] == '-' && |
| 90 | args[0][1] == '-') |
| 91 | { |
| 92 | return GDALAlgorithm::ParseCommandLineArguments(args); |
| 93 | } |
| 94 | |
| 95 | // Generic case: "gdal {subcommand} arguments" |
| 96 | // where subcommand is a known subcommand |
| 97 | else if (args.size() >= 1) |
| 98 | { |
| 99 | const auto nCounter = CPLGetErrorCounter(); |
| 100 | if (InstantiateSubAlgorithm(args[0])) |
| 101 | return GDALAlgorithm::ParseCommandLineArguments(args); |
| 102 | if (CPLGetErrorCounter() == nCounter + 1 && |
| 103 | strstr(CPLGetLastErrorMsg(), "Do you mean")) |
| 104 | { |
| 105 | return false; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // Otherwise check if that is the shortest form of "gdal read mydataset" |
| 110 | // where "read" is omitted: "gdal in.tif" |
| 111 | { |
| 112 | VSIStatBufL sStat; |
| 113 | for (const auto &arg : args) |
| 114 | { |
| 115 | if (VSIStatL(arg.c_str(), &sStat) == 0) |
| 116 | { |
no test coverage detected