Scheduler/Console: Fix option parsing bug (closes: #14841)
g0dil [Thu, 27 Nov 2008 12:12:40 +0000 (12:12 +0000)]
Scheduler/Console: Add additional information to exceptions thrown while parsing command line arguments

git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@985 270642c3-0616-0410-b53a-bc976706d245

Scheduler/Console/Executor.test.cc
Scheduler/Console/ProgramOptions.cc

index 705622e..e2ff88a 100644 (file)
@@ -271,7 +271,6 @@ BOOST_AUTO_UNIT_TEST(executorAuto)
         BOOST_CHECK_EQUAL( os.str(), "testCommand\n" );
     }
     
-
     commands.clear();
     senf::console::root().remove("tdir1");
     senf::console::root().remove("dir2");
index 63bcfb1..0efbd7e 100644 (file)
@@ -60,7 +60,13 @@ prefix_ void senf::console::detail::ProgramOptionsSource::v_parse(RestrictedExec
             break;
         }
         else if (boost::algorithm::starts_with(arg, std::string("--")) && arg.size() > 2)
-            parseLongOption(arg.substr(2), executor);
+            try {
+                parseLongOption(arg.substr(2), executor);
+            }
+            catch (senf::ExceptionMixin & e) {
+                e << "\nwhile parsing command line option: " << arg;
+                throw;
+            }
         else if (boost::algorithm::starts_with(arg, std::string("-")) && arg.size() > 1) {
             for (std::string::size_type i (1); i<arg.size(); ++i) {
                 char opt (arg[i]);
@@ -87,7 +93,13 @@ prefix_ void senf::console::detail::ProgramOptionsSource::v_parse(RestrictedExec
                 }
                 if (boost::algorithm::starts_with(longOpt, std::string("--")))
                     longOpt = longOpt.substr(2);
-                parseLongOption(longOpt, executor);
+                try {
+                    parseLongOption(longOpt, executor);
+                }
+                catch (senf::ExceptionMixin & e) {
+                    e << "\nwhile parsing command line option: -" << opt << ' ' << param;
+                    throw;
+                }
             }
         }
         else
@@ -107,7 +119,7 @@ senf::console::detail::ProgramOptionsSource::parseLongOption(std::string const &
 
     ParseCommandInfo cmd;
     Path path;
-    
     DirectoryNode::ptr cwd (executor.root().thisptr());
     std::string::size_type b (0);
     while (b < name.size()) {
@@ -118,8 +130,10 @@ senf::console::detail::ProgramOptionsSource::parseLongOption(std::string const &
                 DirectoryNode::ChildrenRange completions (cwd->completions(key));
                 if (has_one_elt(completions))
                     key = completions.begin()->first;
-                else
+                else {
+                    e -= 1;
                     continue;
+                }
             }
             path.push_back(WordToken(key));
             if (e < name.size())
@@ -135,7 +149,7 @@ senf::console::detail::ProgramOptionsSource::parseLongOption(std::string const &
             b = name.size();
         }
     }
-    
+
     cmd.command(path);
     parser_.parseArguments(value, cmd);
     executor(std::cerr, cmd);