]> git.stg.codes - stg.git/blobdiff - projects/sgconf/options.cpp
Merge branch 'stg-2.409-radius'
[stg.git] / projects / sgconf / options.cpp
index 772bee6db6d368b4a90b40425ff96ec9ef228306..49e04d648d958c75d7b395cc26a9ef53163d20de 100644 (file)
@@ -122,7 +122,7 @@ if (!m_shortName.empty())
     std::cout << "-" << m_shortName << ", ";
 std::cout << "--" << m_longName << " " << m_action->ParamDescription()
           << "\t" << m_description << m_action->DefaultDescription() << "\n";
-m_action->Suboptions().Help(level + 1);
+m_action->Suboptions().Help(level);
 }
 
 bool OPTION::Check(const char * arg) const
@@ -134,25 +134,28 @@ if (*arg++ != '-')
     return false;
 
 if (*arg == '-')
+{
     return m_longName == arg + 1;
+}
 
 return m_shortName == arg;
 }
 
-PARSER_STATE OPTION::Parse(int argc, char ** argv)
+PARSER_STATE OPTION::Parse(int argc, char ** argv, void * data)
 {
 if (!m_action)
     throw ERROR("Option is not defined.");
 try
     {
-    return m_action->Parse(argc, argv);
+    return m_action->Parse(argc, argv, data);
     }
 catch (const ACTION::ERROR & ex)
     {
     if (m_longName.empty())
         throw ERROR("-" + m_shortName + ": " + ex.what());
     else
-        throw ERROR("--" + m_longName + ", -" + m_shortName + ": " + ex.what());
+        throw m_shortName.empty() ? ERROR("--" + m_longName + ": " + ex.what())
+                                  : ERROR("--" + m_longName + ", -" + m_shortName + ": " + ex.what());
     }
 }
 
@@ -191,20 +194,23 @@ void OPTION_BLOCK::Help(size_t level) const
 {
 if (m_options.empty())
     return;
-std::cout << m_description << ":\n";
+if (!m_description.empty())
+    std::cout << m_description << ":\n";
 std::for_each(m_options.begin(),
               m_options.end(),
               std::bind2nd(std::mem_fun_ref(&OPTION::Help), level + 1));
 }
 
-PARSER_STATE OPTION_BLOCK::Parse(int argc, char ** argv)
+PARSER_STATE OPTION_BLOCK::Parse(int argc, char ** argv, void * data)
 {
 PARSER_STATE state(false, argc, argv);
+if (state.argc == 0)
+    return state;
 while (state.argc > 0 && !state.stop)
     {
     std::vector<OPTION>::iterator it = std::find_if(m_options.begin(), m_options.end(), std::bind2nd(std::mem_fun_ref(&OPTION::Check), *state.argv));
     if (it != m_options.end())
-        state = it->Parse(--state.argc, ++state.argv);
+        state = it->Parse(--state.argc, ++state.argv, data);
     else
         break;
     ++it;
@@ -241,7 +247,7 @@ PARSER_STATE OPTION_BLOCKS::Parse(int argc, char ** argv)
 {
 PARSER_STATE state(false, argc, argv);
 std::list<OPTION_BLOCK>::iterator it(m_blocks.begin());
-while (!state.stop && it != m_blocks.end())
+while (state.argc > 0 && !state.stop && it != m_blocks.end())
     {
     state = it->Parse(state.argc, state.argv);
     ++it;