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

Method GetUsageAsJSON

gcore/gdalalgorithm.cpp:6904–7202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6902/************************************************************************/
6903
6904std::string GDALAlgorithm::GetUsageAsJSON() const
6905{
6906 CPLJSONDocument oDoc;
6907 auto oRoot = oDoc.GetRoot();
6908
6909 if (m_displayInJSONUsage)
6910 {
6911 oRoot.Add("name", m_name);
6912 CPLJSONArray jFullPath;
6913 for (const std::string &s : m_callPath)
6914 {
6915 jFullPath.Add(s);
6916 }
6917 oRoot.Add("full_path", jFullPath);
6918 }
6919
6920 oRoot.Add("description", m_description);
6921 if (!m_helpURL.empty())
6922 {
6923 oRoot.Add("short_url", m_helpURL);
6924 oRoot.Add("url", GetHelpFullURL());
6925 }
6926
6927 CPLJSONArray jSubAlgorithms;
6928 for (const auto &subAlgName : GetSubAlgorithmNames())
6929 {
6930 auto subAlg = InstantiateSubAlgorithm(subAlgName);
6931 if (subAlg && subAlg->m_displayInJSONUsage && !subAlg->IsHidden())
6932 {
6933 CPLJSONDocument oSubDoc;
6934 CPL_IGNORE_RET_VAL(oSubDoc.LoadMemory(subAlg->GetUsageAsJSON()));
6935 jSubAlgorithms.Add(oSubDoc.GetRoot());
6936 }
6937 }
6938 oRoot.Add("sub_algorithms", jSubAlgorithms);
6939
6940 if (m_arbitraryLongNameArgsAllowed)
6941 {
6942 oRoot.Add("user_provided_arguments_allowed", true);
6943 }
6944
6945 const auto ProcessArg = [this](const GDALAlgorithmArg *arg)
6946 {
6947 CPLJSONObject jArg;
6948 jArg.Add("name", arg->GetName());
6949 jArg.Add("type", GDALAlgorithmArgTypeName(arg->GetType()));
6950 jArg.Add("description", arg->GetDescription());
6951
6952 const auto &metaVar = arg->GetMetaVar();
6953 if (!metaVar.empty() && metaVar != CPLString(arg->GetName()).toupper())
6954 {
6955 if (metaVar.front() == '<' && metaVar.back() == '>' &&
6956 metaVar.substr(1, metaVar.size() - 2).find('>') ==
6957 std::string::npos)
6958 jArg.Add("metavar", metaVar.substr(1, metaVar.size() - 2));
6959 else
6960 jArg.Add("metavar", metaVar);
6961 }

Callers 1

Calls 15

GDALAlgorithmArgTypeNameFunction · 0.85
CPLStringFunction · 0.85
CPLErrorFunction · 0.85
isnanFunction · 0.85
LoadMemoryMethod · 0.80
frontMethod · 0.80
GetCategoryMethod · 0.80
SaveAsStringMethod · 0.80
CPL_IGNORE_RET_VALFunction · 0.50
GetRootMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected