MCPcopy Create free account
hub / github.com/OSGeo/gdal / ParseCommandLineArguments

Method ParseCommandLineArguments

gcore/gdalalgorithm.cpp:2170–2703  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2168/************************************************************************/
2169
2170bool GDALAlgorithm::ParseCommandLineArguments(
2171 const std::vector<std::string> &args)
2172{
2173 if (m_parsedSubStringAlreadyCalled)
2174 {
2175 ReportError(CE_Failure, CPLE_AppDefined,
2176 "ParseCommandLineArguments() can only be called once per "
2177 "instance.");
2178 return false;
2179 }
2180 m_parsedSubStringAlreadyCalled = true;
2181
2182 // AWS like syntax supported too (not advertized)
2183 if (args.size() == 1 && args[0] == "help")
2184 {
2185 auto arg = GetArg("help");
2186 assert(arg);
2187 arg->Set(true);
2188 arg->RunActions();
2189 return true;
2190 }
2191
2192 if (HasSubAlgorithms())
2193 {
2194 if (args.empty())
2195 {
2196 ReportError(CE_Failure, CPLE_AppDefined, "Missing %s name.",
2197 m_callPath.size() == 1 ? "command" : "subcommand");
2198 return false;
2199 }
2200 if (!args[0].empty() && args[0][0] == '-')
2201 {
2202 // go on argument parsing
2203 }
2204 else
2205 {
2206 const auto nCounter = CPLGetErrorCounter();
2207 m_selectedSubAlgHolder = InstantiateSubAlgorithm(args[0]);
2208 if (m_selectedSubAlgHolder)
2209 {
2210 m_selectedSubAlg = m_selectedSubAlgHolder.get();
2211 m_selectedSubAlg->SetReferencePathForRelativePaths(
2212 m_referencePath);
2213 m_selectedSubAlg->m_executionForStreamOutput =
2214 m_executionForStreamOutput;
2215 m_selectedSubAlg->m_calledFromCommandLine =
2216 m_calledFromCommandLine;
2217 m_selectedSubAlg->m_skipValidationInParseCommandLine =
2218 m_skipValidationInParseCommandLine;
2219 bool bRet = m_selectedSubAlg->ParseCommandLineArguments(
2220 std::vector<std::string>(args.begin() + 1, args.end()));
2221 m_selectedSubAlg->PropagateSpecialActionTo(this);
2222 return bRet;
2223 }
2224 else
2225 {
2226 if (!(CPLGetErrorCounter() == nCounter + 1 &&
2227 strstr(CPLGetLastErrorMsg(), "Do you mean")))

Calls 15

GetArgFunction · 0.85
ends_withFunction · 0.85
CPLGetValueTypeFunction · 0.85
moveFunction · 0.85
RunActionsMethod · 0.80
eraseMethod · 0.80
frontMethod · 0.80
ReportErrorFunction · 0.50
sizeMethod · 0.45
SetMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected