mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
CLI2: Special handling of argv[0], and subsequent args
This commit is contained in:
parent
7060c82767
commit
92a9ce732c
1 changed files with 52 additions and 34 deletions
44
src/CLI2.cpp
44
src/CLI2.cpp
|
@ -25,7 +25,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cmake.h>
|
||||
//#include <sstream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <Context.h>
|
||||
//#include <Nibbler.h>
|
||||
|
@ -355,15 +355,17 @@ void CLI2::analyze ()
|
|||
// Start from scratch.
|
||||
_args.clear ();
|
||||
|
||||
// Look at each arg, and decide if it warrants lexing.
|
||||
for (unsigned int i = 0; i < _original_args.size (); ++i)
|
||||
if (context.config.getInteger ("debug.parser") >= 3)
|
||||
{
|
||||
std::string raw = _original_args[i];
|
||||
context.debug ("---------------------------------------------------------------------------------");
|
||||
context.debug (dump ("CLI2::analyze start"));
|
||||
}
|
||||
|
||||
// Capture _original_args[0] separately, because it is the command run, and
|
||||
// could need special handling.
|
||||
std::string raw = _original_args[0];
|
||||
A2 a ("arg", raw, Lexer::Type::word);
|
||||
a.tag ("ORIGINAL");
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
a.tag ("BINARY");
|
||||
|
||||
std::string basename = "task";
|
||||
|
@ -376,7 +378,6 @@ void CLI2::analyze ()
|
|||
a.tag ("CALENDAR");
|
||||
else if (basename == "task" || basename == "tw" || basename == "t")
|
||||
a.tag ("TW");
|
||||
}
|
||||
|
||||
_args.push_back (a);
|
||||
|
||||
|
@ -385,15 +386,32 @@ void CLI2::analyze ()
|
|||
A2 cal ("argCal", "calendar", Lexer::Type::word);
|
||||
_args.push_back (cal);
|
||||
}
|
||||
}
|
||||
|
||||
if (context.config.getInteger ("debug.parser") >= 3)
|
||||
// Look at each arg, and decide if it warrants lexing.
|
||||
// Note: Starts interating at index 1.
|
||||
for (unsigned int i = 1; i < _original_args.size (); ++i)
|
||||
{
|
||||
context.debug ("---------------------------------------------------------------------------------");
|
||||
context.debug (dump ("CLI2::analyze start"));
|
||||
raw = _original_args[i];
|
||||
|
||||
// Lex each remaining argument. The apply a series of disqualifying tests
|
||||
// that cause the lexemes to be ignored, and the original arugment used
|
||||
// intact.
|
||||
std::string lexeme;
|
||||
Lexer::Type type;
|
||||
Lexer lex (raw);
|
||||
lex.ambiguity (false);
|
||||
|
||||
std::vector <std::pair <std::string, Lexer::Type>> lexemes;
|
||||
while (lex.token (lexeme, type))
|
||||
{
|
||||
lexemes.push_back (std::pair <std::string, Lexer::Type> (lexeme, type));
|
||||
context.debug (format ("lexeme {1} {2}", lexeme, lex.typeToString (type)));
|
||||
}
|
||||
|
||||
// TODO Analysis here.
|
||||
// TODO Replace this with some discerning logic.
|
||||
A2 arg ("arg", raw, Lexer::Type::word);
|
||||
_args.push_back (arg);
|
||||
}
|
||||
|
||||
if (context.config.getInteger ("debug.parser") >= 3)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue