mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
CLI2: Begun ::analyze method
- Renamed A to A2, to avoid collisions for now. - Added A2::attribute, ctor, dtor. - Stubbbed CLI2::analyze.
This commit is contained in:
parent
23786515f9
commit
485899b0c5
3 changed files with 82 additions and 31 deletions
93
src/CLI2.cpp
93
src/CLI2.cpp
|
@ -46,39 +46,40 @@ int CLI2::minimumMatchLength = 3;
|
||||||
static int safetyValveDefault = 10;
|
static int safetyValveDefault = 10;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
A::A ()
|
A2::A2 ()
|
||||||
: _name ("")
|
: _name ("")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
A::A (const std::string& name, const std::string& raw)
|
A2::A2 (const std::string& name, const std::string& raw)
|
||||||
|
{
|
||||||
|
_name = name;
|
||||||
|
attribute ("raw", raw);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
A2::A2 (const std::string& name, const int raw)
|
||||||
{
|
{
|
||||||
_name = name;
|
_name = name;
|
||||||
attribute ("raw", raw);
|
attribute ("raw", raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
A::A (const std::string& name, const int raw)
|
A2::A2 (const std::string& name, const double raw)
|
||||||
{
|
{
|
||||||
_name = name;
|
_name = name;
|
||||||
attribute ("raw", raw);
|
attribute ("raw", raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
A::A (const std::string& name, const double raw)
|
A2::~A2 ()
|
||||||
{
|
|
||||||
_name = name;
|
|
||||||
attribute ("raw", raw);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
A::~A ()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
A::A (const A& other)
|
A2::A2 (const A2& other)
|
||||||
: _name (other._name)
|
: _name (other._name)
|
||||||
, _tags (other._tags)
|
, _tags (other._tags)
|
||||||
, _attributes (other._attributes)
|
, _attributes (other._attributes)
|
||||||
|
@ -86,7 +87,7 @@ A::A (const A& other)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
A& A::operator= (const A& other)
|
A2& A2::operator= (const A2& other)
|
||||||
{
|
{
|
||||||
if (this != &other)
|
if (this != &other)
|
||||||
{
|
{
|
||||||
|
@ -99,7 +100,7 @@ A& A::operator= (const A& other)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool A::hasTag (const std::string& tag) const
|
bool A2::hasTag (const std::string& tag) const
|
||||||
{
|
{
|
||||||
if (std::find (_tags.begin (), _tags.end (), tag) != _tags.end ())
|
if (std::find (_tags.begin (), _tags.end (), tag) != _tags.end ())
|
||||||
return true;
|
return true;
|
||||||
|
@ -108,14 +109,14 @@ bool A::hasTag (const std::string& tag) const
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void A::tag (const std::string& tag)
|
void A2::tag (const std::string& tag)
|
||||||
{
|
{
|
||||||
if (! hasTag (tag))
|
if (! hasTag (tag))
|
||||||
_tags.push_back (tag);
|
_tags.push_back (tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void A::unTag (const std::string& tag)
|
void A2::unTag (const std::string& tag)
|
||||||
{
|
{
|
||||||
for (auto i = _tags.begin (); i != _tags.end (); ++i)
|
for (auto i = _tags.begin (); i != _tags.end (); ++i)
|
||||||
{
|
{
|
||||||
|
@ -128,35 +129,37 @@ void A::unTag (const std::string& tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void A::unTagAll ()
|
void A2::unTagAll ()
|
||||||
{
|
{
|
||||||
_tags.clear ();
|
_tags.clear ();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Accessor for attributes.
|
// Accessor for attributes.
|
||||||
void A::attribute (const std::string& name, const std::string& value)
|
void A2::attribute (const std::string& name, const std::string& value)
|
||||||
{
|
{
|
||||||
_attributes[name] = value;
|
_attributes[name] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Accessor for attributes.
|
// Accessor for attributes.
|
||||||
void A::attribute (const std::string& name, const int value)
|
void A2::attribute (const std::string& name, const int value)
|
||||||
{
|
{
|
||||||
_attributes[name] = format (value);
|
_attributes[name] = format (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Accessor for attributes.
|
// Accessor for attributes.
|
||||||
void A::attribute (const std::string& name, const double value)
|
void A2::attribute (const std::string& name, const double value)
|
||||||
{
|
{
|
||||||
_attributes[name] = format (value, 1, 8);
|
_attributes[name] = format (value, 1, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Accessor for attributes.
|
// Accessor for attributes.
|
||||||
const std::string A::attribute (const std::string& name) const
|
const std::string A2::attribute (const std::string& name) const
|
||||||
{
|
{
|
||||||
// Prevent autovivification.
|
// Prevent autovivification.
|
||||||
auto i = _attributes.find (name);
|
auto i = _attributes.find (name);
|
||||||
|
@ -167,13 +170,13 @@ const std::string A::attribute (const std::string& name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void A::removeAttribute (const std::string& name)
|
void A2::removeAttribute (const std::string& name)
|
||||||
{
|
{
|
||||||
_attributes.erase (name);
|
_attributes.erase (name);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
const std::string A::dump () const
|
const std::string A2::dump () const
|
||||||
{
|
{
|
||||||
std::string output = _name;
|
std::string output = _name;
|
||||||
|
|
||||||
|
@ -337,6 +340,48 @@ void CLI2::add (const std::string& argument)
|
||||||
_original_args.push_back (argument);
|
_original_args.push_back (argument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Intended to be called after ::add() to perform the final analysis.
|
||||||
|
void CLI2::analyze ()
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < _original_args.size (); ++i)
|
||||||
|
{
|
||||||
|
std::string raw = _original_args[i];
|
||||||
|
A a ("arg", raw);
|
||||||
|
/*
|
||||||
|
a.tag ("ORIGINAL");
|
||||||
|
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
a.tag ("BINARY");
|
||||||
|
|
||||||
|
std::string basename = "task";
|
||||||
|
auto slash = raw.rfind ('/');
|
||||||
|
if (slash != std::string::npos)
|
||||||
|
basename = raw.substr (slash + 1);
|
||||||
|
|
||||||
|
a.attribute ("basename", basename);
|
||||||
|
if (basename == "cal" || basename == "calendar")
|
||||||
|
a.tag ("CALENDAR");
|
||||||
|
else if (basename == "task" || basename == "tw" || basename == "t")
|
||||||
|
a.tag ("TW");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
_args.push_back (a);
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (a.hasTag ("CALENDAR"))
|
||||||
|
{
|
||||||
|
A cal ("argCal", "calendar");
|
||||||
|
_args.push_back (cal);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.config.getInteger ("debug.parser") >= 3)
|
||||||
|
context.debug ("CLI2::analyze end");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Capture the original, intact command line arguments.
|
// Capture the original, intact command line arguments.
|
||||||
|
|
18
src/CLI2.h
18
src/CLI2.h
|
@ -35,12 +35,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Represents a single argument.
|
// Represents a single argument.
|
||||||
/*
|
class A2
|
||||||
class A
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
A ();
|
A2 ();
|
||||||
A (const std::string&, const std::string&);
|
A2 (const std::string&, const std::string&);
|
||||||
|
/*
|
||||||
A (const std::string&, const int);
|
A (const std::string&, const int);
|
||||||
A (const std::string&, const double);
|
A (const std::string&, const double);
|
||||||
~A ();
|
~A ();
|
||||||
|
@ -50,19 +50,22 @@ public:
|
||||||
void tag (const std::string&);
|
void tag (const std::string&);
|
||||||
void unTag (const std::string&);
|
void unTag (const std::string&);
|
||||||
void unTagAll ();
|
void unTagAll ();
|
||||||
|
*/
|
||||||
void attribute (const std::string&, const std::string&);
|
void attribute (const std::string&, const std::string&);
|
||||||
|
/*
|
||||||
void attribute (const std::string&, const int);
|
void attribute (const std::string&, const int);
|
||||||
void attribute (const std::string&, const double);
|
void attribute (const std::string&, const double);
|
||||||
const std::string attribute (const std::string&) const;
|
const std::string attribute (const std::string&) const;
|
||||||
void removeAttribute (const std::string&);
|
void removeAttribute (const std::string&);
|
||||||
const std::string dump () const;
|
const std::string dump () const;
|
||||||
|
*/
|
||||||
public:
|
public:
|
||||||
std::string _name;
|
std::string _name;
|
||||||
|
/*
|
||||||
std::vector <std::string> _tags;
|
std::vector <std::string> _tags;
|
||||||
|
*/
|
||||||
std::map <std::string, std::string> _attributes;
|
std::map <std::string, std::string> _attributes;
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
|
|
||||||
// Represents the command line.
|
// Represents the command line.
|
||||||
class CLI2
|
class CLI2
|
||||||
|
@ -81,6 +84,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 analyze ();
|
||||||
/*
|
/*
|
||||||
void initialize (int, const char**);
|
void initialize (int, const char**);
|
||||||
void add (const std::string&);
|
void add (const std::string&);
|
||||||
|
@ -146,9 +150,9 @@ public:
|
||||||
std::multimap <std::string, std::string> _entities;
|
std::multimap <std::string, std::string> _entities;
|
||||||
std::map <std::string, std::string> _aliases;
|
std::map <std::string, std::string> _aliases;
|
||||||
std::vector <std::string> _original_args;
|
std::vector <std::string> _original_args;
|
||||||
/*
|
|
||||||
std::vector <A> _args;
|
std::vector <A> _args;
|
||||||
|
|
||||||
|
/*
|
||||||
std::vector <std::pair <int, int>> _id_ranges;
|
std::vector <std::pair <int, int>> _id_ranges;
|
||||||
std::vector <std::string> _uuid_list;
|
std::vector <std::string> _uuid_list;
|
||||||
bool _strict;
|
bool _strict;
|
||||||
|
|
|
@ -229,6 +229,8 @@ int Context::initialize (int argc, const char** argv)
|
||||||
for (int i = 0; i < argc; i++)
|
for (int i = 0; i < argc; i++)
|
||||||
cli2.add (argv[i]);
|
cli2.add (argv[i]);
|
||||||
|
|
||||||
|
cli2.analyze ();
|
||||||
|
|
||||||
cli.initialize (argc, argv);
|
cli.initialize (argc, argv);
|
||||||
cli.analyze (true, true);
|
cli.analyze (true, true);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue