From 1eb95ce3cf0df487f9da2b0aeeb64b58cdfd3dc5 Mon Sep 17 00:00:00 2001
From: Julien Michel <julien.michel@cnes.fr>
Date: Wed, 20 Jun 2018 12:22:08 +0200
Subject: [PATCH] ENH: Warn users about paramters from command-line that will
 be ignored

---
 .../src/otbWrapperCommandLineLauncher.cxx     | 31 +++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx
index e0a324191d..35c80f7b30 100644
--- a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx
+++ b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx
@@ -522,6 +522,37 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
       return MISSINGMANDATORYPARAMETER;
       }
 
+    // Check for ignored parameters
+    if(m_Application->HasUserValue(paramKey))
+      {
+      unsigned int start = 0;
+      auto end = paramKey.find_first_of('.',start);
+    
+      while(end != std::string::npos)
+        {
+        std::string key = paramKey.substr(0,end);
+        ParameterType type = m_Application->GetParameterType(key);
+        
+        if(type == ParameterType_Choice)
+          {
+          std::string value = m_Application->GetParameterString(key);
+
+          if(paramKey.find(value) == std::string::npos)
+            {
+            start = end+1;
+            end = paramKey.find_first_of('.',start);
+            std::string missingMode = paramKey.substr(start,end-start);
+            std::cerr<<"WARNING: Parameter -"<<paramKey<<" will be ignored because -"<<key<<" is "<<value<<". Consider adding -"<<key<<" "<<missingMode<<" to application parameters."<<std::endl;
+            
+            break;
+            }
+          }
+        
+        start = end+1;
+        end = paramKey.find_first_of('.',start);
+        }
+      }
+
     // Check output paths validity
     if (m_Application->HasValue(paramKey) &&
         type == ParameterType_OutputFilename)
-- 
GitLab