Skip to content
Snippets Groups Projects
Commit f9872179 authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

ENH: add control on key prefix

parent d911771c
Branches
Tags
No related merge requests found
......@@ -107,6 +107,12 @@ CommandLineLauncher::Load()
itkExceptionMacro("No expression specified...");
}
if( this->CheckParametersPrefix() == false )
{
std::cerr<<"ERROR: Parameter keys have to set using \"--\""<<std::endl;
return false;
}
if( this->CheckUnicity() == false )
{
std::cerr<<"ERROR: At least one key is not unique in the expression..."<<std::endl;
......@@ -798,6 +804,35 @@ CommandLineLauncher::CheckUnicity()
return res;
}
bool
CommandLineLauncher::CheckParametersPrefix()
{
bool res = true;
// Extract Expression elements
std::vector<itksys::String> spaceSplittedExp = itksys::SystemTools::SplitString(m_Expression.c_str(), ' ', false);
// if the chain is " module", SplitString will return: [ ], [module]
for(unsigned int i=0; i<spaceSplittedExp.size(); i++)
{
if( spaceSplittedExp[i] == " ")
{
spaceSplittedExp.erase(spaceSplittedExp.begin()+i);
i--;
}
}
// If the expression contains parameters
if( spaceSplittedExp.size() > 2 )
{
// Check if the chain "--" appears at least one time
if( m_Expression.find("--") == std::string::npos)
{
res = false;
}
}
return res;
}
bool
CommandLineLauncher::CheckKeyValidity()
{
......
......@@ -141,6 +141,12 @@ protected:
/** Check if each key is unique in the expression. */
bool CheckUnicity();
/** Check if option contains at least one "--".
* return false if m_Expression contains more than 2 element (module
* name and path) and doesn't contains "--"
*/
bool CheckParametersPrefix();
/** Check if each key is valid for the application. */
bool CheckKeyValidity();
......
......@@ -100,7 +100,7 @@ CommandLineParser::GetPaths( std::vector<std::string> & paths, const std::string
std::string fullPath = itksys::SystemTools::CollapseFullPath(pathAttribut[i].c_str());
if( !itksys::SystemTools::FileIsDirectory(fullPath.c_str()) )
{
std::cout<<"module path INVALIDMODULEPATH"<<std::endl;
std::cerr<<"module path Inavlid module path"<<std::endl;
return INVALIDMODULEPATH;
}
paths.push_back(fullPath);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment