mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 09:53:08 +02:00
CLI2: Generalize 'add' to insert arguments at arbitrary position
This commit is contained in:
parent
9bc726ba61
commit
9128798fee
2 changed files with 6 additions and 5 deletions
|
@ -329,15 +329,16 @@ void CLI2::add (const std::string& argument)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Capture a set of arguments, inserted immediately after the binary.
|
// Capture a set of arguments, inserted immediately after <offset> arguments
|
||||||
void CLI2::add (const std::vector <std::string>& arguments)
|
// after the binary..
|
||||||
|
void CLI2::add (const std::vector <std::string>& arguments, int offset /* = 0 */)
|
||||||
{
|
{
|
||||||
std::vector <A2> replacement {_original_args[0]};
|
std::vector <A2> replacement {_original_args.begin(), _original_args.begin() + offset + 1};
|
||||||
|
|
||||||
for (const auto& arg : arguments)
|
for (const auto& arg : arguments)
|
||||||
replacement.push_back (A2 (arg, Lexer::Type::word));
|
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]);
|
replacement.push_back (_original_args[i]);
|
||||||
|
|
||||||
_original_args = replacement;
|
_original_args = replacement;
|
||||||
|
|
|
@ -70,7 +70,7 @@ public:
|
||||||
void entity (const std::string&, const std::string&);
|
void entity (const std::string&, const std::string&);
|
||||||
|
|
||||||
void add (const std::string&);
|
void add (const std::string&);
|
||||||
void add (const std::vector <std::string>&);
|
void add (const std::vector <std::string>&, int offset = 0);
|
||||||
void analyze ();
|
void analyze ();
|
||||||
void addFilter (const std::string& arg);
|
void addFilter (const std::string& arg);
|
||||||
void addContextFilter ();
|
void addContextFilter ();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue