From 1311bd7a64480939432b7b4dd64795640e78ecca Mon Sep 17 00:00:00 2001 From: zawz Date: Tue, 14 Jan 2020 11:02:42 +0100 Subject: [PATCH] options: add stop_on_argument in process --- include/options.hpp | 10 ++++++---- src/options.cpp | 6 +++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/options.hpp b/include/options.hpp index 5773131..b9ade15 100644 --- a/include/options.hpp +++ b/include/options.hpp @@ -141,14 +141,16 @@ namespace ztd /*! If errors are encountered, exceptions option_error are thrown @param arguments vector of string containing arguments and options - @return Leftover arguments that are not options\n + @param ignore_numbers negative numbers are not considered as options + @param stop_on_argument stop processing when encountering a non-option argument + @return if @a stop_on_argument unprocessed arguments\n else leftover arguments that are not options\n */ - std::vector process(std::vector arguments, bool ignore_numbers=false); + std::vector process(std::vector arguments, bool ignore_numbers=false, bool stop_on_argument=false); //! @brief Process arguments through the option set /*! - calls process(std::vector arguments) + calls process(std::vector arguments, bool ignore_numbers, bool stop_on_argument) */ - inline std::vector process(int argc, char** argv, bool ignore_numbers=false) { return this->process(ztd::argVector(argc, argv), ignore_numbers); } + inline std::vector process(int argc, char** argv, bool ignore_numbers=false, bool stop_on_argument=false) { return this->process(ztd::argVector(argc, argv), ignore_numbers, stop_on_argument); } //! @brief Get option with char name /*! @see option* find(char c) diff --git a/src/options.cpp b/src/options.cpp index 8923042..cd9dabd 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -159,7 +159,7 @@ ztd::option* ztd::option_set::find(const std::string& str) return nullptr; } -std::vector ztd::option_set::process(std::vector arguments, bool ignore_numbers) +std::vector ztd::option_set::process(std::vector arguments, bool ignore_numbers, bool stop_on_argument) { std::vector out; unsigned int i=0; @@ -217,6 +217,8 @@ std::vector ztd::option_set::process(std::vector argum { while(it!=arguments.end() && (*it).size()>i) i++; + if(stop_on_argument) + return std::vector(it, arguments.end()); out.push_back(*it); } else @@ -266,6 +268,8 @@ std::vector ztd::option_set::process(std::vector argum } else { + if(stop_on_argument) + return std::vector(it, arguments.end()); out.push_back(*it); } if(it == arguments.end())