From cc57eeb2455a342d4d44e998dda03037e6c686e5 Mon Sep 17 00:00:00 2001 From: g0dil <g0dil@wiback.org> Date: Thu, 27 Nov 2008 12:12:40 +0000 Subject: [PATCH] Scheduler/Console: Fix option parsing bug (closes: #14841) Scheduler/Console: Add additional information to exceptions thrown while parsing command line arguments --- Scheduler/Console/Executor.test.cc | 1 - Scheduler/Console/ProgramOptions.cc | 24 +++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Scheduler/Console/Executor.test.cc b/Scheduler/Console/Executor.test.cc index 705622e16..e2ff88a68 100644 --- a/Scheduler/Console/Executor.test.cc +++ b/Scheduler/Console/Executor.test.cc @@ -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"); diff --git a/Scheduler/Console/ProgramOptions.cc b/Scheduler/Console/ProgramOptions.cc index 63bcfb15f..0efbd7e36 100644 --- a/Scheduler/Console/ProgramOptions.cc +++ b/Scheduler/Console/ProgramOptions.cc @@ -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); -- GitLab