| 6902 | /************************************************************************/ |
| 6903 | |
| 6904 | std::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 | } |
no test coverage detected