From 7ea9c1e587689cb624582feb92621d06550444a5 Mon Sep 17 00:00:00 2001
From: Victor Poughon <victor.poughon@cnes.fr>
Date: Thu, 18 May 2017 11:44:57 +0200
Subject: [PATCH] RFC-91: CommandLineLauncher::LoadApplication return bool to
 fail earlier

---
 .../include/otbWrapperCommandLineLauncher.h            |  2 +-
 .../CommandLine/src/otbWrapperCommandLineLauncher.cxx  | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Modules/Wrappers/CommandLine/include/otbWrapperCommandLineLauncher.h b/Modules/Wrappers/CommandLine/include/otbWrapperCommandLineLauncher.h
index 36b0b0de53..0224ea66d0 100644
--- a/Modules/Wrappers/CommandLine/include/otbWrapperCommandLineLauncher.h
+++ b/Modules/Wrappers/CommandLine/include/otbWrapperCommandLineLauncher.h
@@ -131,7 +131,7 @@ protected:
     * Pay attention, the executable paths have to be loaded or set in
     * the environment before calling the function.
     */
-  void LoadApplication();
+  bool LoadApplication();
 
   /** Parse the user expression, extract the key and the associated
     * string and set it as value of each corresponding application
diff --git a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx
index 0a260332af..67ccace3e9 100644
--- a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx
+++ b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx
@@ -124,9 +124,7 @@ bool CommandLineLauncher::Load()
       }
     }
 
-  this->LoadApplication();
-
-  return true;
+  return this->LoadApplication();
 }
 
 bool CommandLineLauncher::Execute()
@@ -283,7 +281,7 @@ bool CommandLineLauncher::LoadPath()
   return true;
 }
 
-void CommandLineLauncher::LoadApplication()
+bool CommandLineLauncher::LoadApplication()
 {
   // Look for the module name
   std::string moduleName;
@@ -291,7 +289,7 @@ void CommandLineLauncher::LoadApplication()
   if (m_Parser->GetModuleName(moduleName, m_VExpression) != CommandLineParser::OK)
     {
     std::cerr << "ERROR: LoadApplication, no module found." << std::endl;
-    return;
+    return false;
     }
 
   // Instantiate the application using the factory
@@ -316,6 +314,7 @@ void CommandLineLauncher::LoadApplication()
         std::cerr << "\t" << *it << std::endl;
         }
       }
+    return false;
     }
   else
     {
@@ -327,6 +326,7 @@ void CommandLineLauncher::LoadApplication()
     // Add an observer to the AddedProcess event
     m_Application->AddObserver(AddProcessToWatchEvent(), m_AddProcessCommand.GetPointer());
 
+    return true;
     }
 }
 
-- 
GitLab