Commit 993f51dd authored by Julien Michel's avatar Julien Michel
Browse files

ENH: Modify behaviour of -help so as to get the long description of app and params

No related merge requests found
Showing with 102 additions and 24 deletions
+102 -24
...@@ -109,7 +109,10 @@ public: ...@@ -109,7 +109,10 @@ public:
bool BeforeExecute(); bool BeforeExecute();
/** Create and display the help of the application */ /** Create and display the help of the application */
void DisplayHelp(); void DisplayHelp(bool longHelp=false);
/** Create and display the long help of the application */
void DisplayLongHelp();
/** Performs specific action for testing environment */ /** Performs specific action for testing environment */
void LoadTestEnv(); void LoadTestEnv();
...@@ -141,7 +144,7 @@ protected: ...@@ -141,7 +144,7 @@ protected:
/** Create and display the help of the application */ /** Create and display the help of the application */
std::string DisplayParameterHelp( const Parameter::Pointer & param, std::string DisplayParameterHelp( const Parameter::Pointer & param,
const std::string paramKey ); const std::string paramKey, bool longHelp = false);
/** Check if each key is unique in the expression. */ /** Check if each key is unique in the expression. */
bool CheckUnicity(); bool CheckUnicity();
......
...@@ -197,7 +197,36 @@ bool CommandLineLauncher::BeforeExecute() ...@@ -197,7 +197,36 @@ bool CommandLineLauncher::BeforeExecute()
// if help is asked... // if help is asked...
if (m_Parser->IsAttributExists("-help", m_VExpression) == true) if (m_Parser->IsAttributExists("-help", m_VExpression) == true)
{ {
this->DisplayHelp(); std::vector<std::string> val;
val = m_Parser->GetAttribut("-help", m_VExpression);
if(val.empty())
{
this->DisplayHelp(true);
}
else
{
const unsigned int nbOfParam = appKeyList.size();
m_MaxKeySize = std::string("progress").size();
for (unsigned int i = 0; i < nbOfParam; i++)
{
if (m_Application->GetParameterRole(appKeyList[i]) != Role_Output)
{
if( m_MaxKeySize < appKeyList[i].size() )
m_MaxKeySize = appKeyList[i].size();
}
}
for(std::vector<std::string>::const_iterator it = val.begin(); it!=val.end();++it)
{
Parameter::Pointer param = m_Application->GetParameterByKey(*it);
if (param->GetRole() != Role_Output)
{
std::cerr << this->DisplayParameterHelp(param, *it,true)<<std::endl;
}
}
}
return false; return false;
} }
...@@ -549,11 +578,11 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters() ...@@ -549,11 +578,11 @@ CommandLineLauncher::ParamResultType CommandLineLauncher::LoadParameters()
{ {
dynamic_cast<EmptyParameter *> (param.GetPointer())->SetActive(false); dynamic_cast<EmptyParameter *> (param.GetPointer())->SetActive(false);
} }
else else
{ {
std::cerr << "ERROR: Wrong parameter value: " << paramKey << std::endl; std::cerr << "ERROR: Wrong parameter value: " << paramKey << std::endl;
return WRONGPARAMETERVALUE; return WRONGPARAMETERVALUE;
} }
} }
// Update the flag UserValue // Update the flag UserValue
param->SetUserValue(true); param->SetUserValue(true);
...@@ -685,19 +714,38 @@ void CommandLineLauncher::LinkWatchers(itk::Object * itkNotUsed(caller), const i ...@@ -685,19 +714,38 @@ void CommandLineLauncher::LinkWatchers(itk::Object * itkNotUsed(caller), const i
} }
} }
void CommandLineLauncher::DisplayHelp() void CommandLineLauncher::DisplayHelp(bool longHelp)
{ {
std::cerr << "This is the "<<m_Application->GetName() << " application, version " << OTB_VERSION_STRING <<std::endl; std::cerr<<std::endl;
std::cerr << "This is the "<<m_Application->GetDocName() << " ("<<m_Application->GetName()<<") application, version " << OTB_VERSION_STRING <<std::endl<<std::endl;
std::cerr << m_Application->GetDescription() << std::endl; std::cerr << m_Application->GetDescription() << std::endl;
std::cerr<<std::endl;
std::string link = m_Application->GetDocLink(); if(longHelp)
if (!link.empty()) {
{ std::cerr<<"Tags: ";
std::cerr << "Complete documentation: " << link << std::endl;
std::vector<std::string> tags = m_Application->GetDocTags();
for(std::vector<std::string>::const_iterator it = tags.begin(); it!=tags.end();++it)
{
std::cerr<<*it<<" ";
}
std::cerr<<std::endl;
std::cerr<<std::endl;
std::cerr<<m_Application->GetDocLongDescription() << std::endl;
std::cerr<<std::endl; std::cerr<<std::endl;
} }
else
{
std::string link = m_Application->GetDocLink();
if (!link.empty())
{
std::cerr << "Complete documentation: " << link << " or -help" <<std::endl;
std::cerr<<std::endl;
}
}
std::cerr << "Parameters: " << std::endl; std::cerr << "Parameters: " << std::endl;
...@@ -723,31 +771,47 @@ void CommandLineLauncher::DisplayHelp() ...@@ -723,31 +771,47 @@ void CommandLineLauncher::DisplayHelp()
for (unsigned int i = 0; i < nbOfParam; i++) for (unsigned int i = 0; i < nbOfParam; i++)
{ {
Parameter::Pointer param = m_Application->GetParameterByKey(appKeyList[i]); Parameter::Pointer param = m_Application->GetParameterByKey(appKeyList[i]);
if (param->GetRole() != Role_Output) if (param->GetRole() != Role_Output)
{ {
std::cerr << this->DisplayParameterHelp(param, appKeyList[i]); std::cerr << this->DisplayParameterHelp(param, appKeyList[i]);
} }
} }
std::cerr<<std::endl; std::cerr<<std::endl;
//std::string cl(m_Application->GetCLExample()); //std::string cl(m_Application->GetCLExample());
std::cerr<<"Use -help param1 [... paramN] to see detailed documentation of those parameters."<<std::endl;
std::cerr<<std::endl;
std::cerr << "Examples: " << std::endl; std::cerr << "Examples: " << std::endl;
std::cerr << m_Application->GetCLExample() << std::endl; std::cerr << m_Application->GetCLExample() << std::endl;
} if(longHelp)
{
std::cerr<<"Authors: "<<std::endl<<m_Application->GetDocAuthors() << std::endl;
std::cerr<<std::endl;
std::cerr<<"Limitations: "<<std::endl<<m_Application->GetDocLimitations() << std::endl;
std::cerr<<std::endl;
std::cerr<<"See also: "<<std::endl<<m_Application->GetDocSeeAlso() << std::endl;
std::cerr<<std::endl;
}
}
void CommandLineLauncher::LoadTestEnv() void CommandLineLauncher::LoadTestEnv()
{ {
//Set seed for rand and itk mersenne twister //Set seed for rand and itk mersenne twister
//srand(1); //srand(1);
// itk::Statistics::MersenneTwisterRandomVariateGenerator::GetInstance()->SetSeed(121212); // itk::Statistics::MersenneTwisterRandomVariateGenerator::GetInstance()->SetSeed(121212);
} }
std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer & param, const std::string paramKey) std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer & param, const std::string paramKey, bool longHelp)
{ {
// Display the type the type // Display the type the type
ParameterType type = m_Application->GetParameterType(paramKey); ParameterType type = m_Application->GetParameterType(paramKey);
...@@ -924,6 +988,17 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer & ...@@ -924,6 +988,17 @@ std::string CommandLineLauncher::DisplayParameterHelp(const Parameter::Pointer &
oss<<")"; oss<<")";
oss << std::endl; oss << std::endl;
if(longHelp)
{
oss << " ";
for(unsigned int i=0; i<m_MaxKeySize;++i)
oss<<" ";
oss<<" ";
oss<<m_Application->GetParameterDescription(paramKey)<<std::endl;
}
return oss.str(); return oss.str();
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment