From 9128798feec9386012ca75d4271330df13349740 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Thu, 28 Jan 2021 00:27:11 -0500 Subject: [PATCH] CLI2: Generalize 'add' to insert arguments at arbitrary position --- src/CLI2.cpp | 9 +++++---- src/CLI2.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/CLI2.cpp b/src/CLI2.cpp index f7ae2af6b..2482dc4db 100644 --- a/src/CLI2.cpp +++ b/src/CLI2.cpp @@ -329,15 +329,16 @@ void CLI2::add (const std::string& argument) } //////////////////////////////////////////////////////////////////////////////// -// Capture a set of arguments, inserted immediately after the binary. -void CLI2::add (const std::vector & arguments) +// Capture a set of arguments, inserted immediately after arguments +// after the binary.. +void CLI2::add (const std::vector & arguments, int offset /* = 0 */) { - std::vector replacement {_original_args[0]}; + std::vector replacement {_original_args.begin(), _original_args.begin() + offset + 1}; for (const auto& arg : arguments) replacement.push_back (A2 (arg, Lexer::Type::word)); - for (unsigned int i = 1; i < _original_args.size (); ++i) + for (unsigned int i = 1 + offset; i < _original_args.size (); ++i) replacement.push_back (_original_args[i]); _original_args = replacement; diff --git a/src/CLI2.h b/src/CLI2.h index a1b620ddc..1e46ef2cc 100644 --- a/src/CLI2.h +++ b/src/CLI2.h @@ -70,7 +70,7 @@ public: void entity (const std::string&, const std::string&); void add (const std::string&); - void add (const std::vector &); + void add (const std::vector &, int offset = 0); void analyze (); void addFilter (const std::string& arg); void addContextFilter ();