CLI
- Combined all elements into the single _args list.
This commit is contained in:
77
src/CLI.cpp
77
src/CLI.cpp
@@ -204,8 +204,6 @@ const std::string A::dump () const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
CLI::CLI ()
|
CLI::CLI ()
|
||||||
: _rc ("")
|
|
||||||
, _readOnly (false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,11 +231,6 @@ void CLI::initialize (int argc, const char** argv)
|
|||||||
// Clean what needs to be cleaned. Everything in this case.
|
// Clean what needs to be cleaned. Everything in this case.
|
||||||
_original_args.clear ();
|
_original_args.clear ();
|
||||||
_args.clear ();
|
_args.clear ();
|
||||||
_rc = "";
|
|
||||||
_command.clear ();
|
|
||||||
_readOnly = false;
|
|
||||||
_filter.clear ();
|
|
||||||
_modifications.clear ();
|
|
||||||
|
|
||||||
for (int i = 0; i < argc; ++i)
|
for (int i = 0; i < argc; ++i)
|
||||||
{
|
{
|
||||||
@@ -269,12 +262,6 @@ void CLI::add (const std::string& arg)
|
|||||||
{
|
{
|
||||||
// Clean what needs to be cleaned. Most in this case.
|
// Clean what needs to be cleaned. Most in this case.
|
||||||
_args.clear ();
|
_args.clear ();
|
||||||
_rc = "";
|
|
||||||
_command.clear ();
|
|
||||||
_readOnly = false;
|
|
||||||
_filter.clear ();
|
|
||||||
_modifications.clear ();
|
|
||||||
|
|
||||||
_original_args.push_back (arg);
|
_original_args.push_back (arg);
|
||||||
|
|
||||||
for (int i = 0; i < _original_args.size (); ++i)
|
for (int i = 0; i < _original_args.size (); ++i)
|
||||||
@@ -302,12 +289,16 @@ void CLI::add (const std::string& arg)
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
const std::string CLI::getFilter ()
|
const std::string CLI::getFilter ()
|
||||||
{
|
{
|
||||||
|
// TODO Convert to _args.
|
||||||
|
/*
|
||||||
// Remove all the syntactic sugar.
|
// Remove all the syntactic sugar.
|
||||||
unsweetenTags ();
|
unsweetenTags ();
|
||||||
// TODO all the other types: att, attmod, pattern, id, uuid ...
|
// TODO all the other types: att, attmod, pattern, id, uuid ...
|
||||||
|
*/
|
||||||
|
|
||||||
std::string filter = "";
|
std::string filter = "";
|
||||||
|
|
||||||
|
/*
|
||||||
if (_filter.size ())
|
if (_filter.size ())
|
||||||
{
|
{
|
||||||
filter = "(";
|
filter = "(";
|
||||||
@@ -323,6 +314,7 @@ const std::string CLI::getFilter ()
|
|||||||
|
|
||||||
filter += ')';
|
filter += ')';
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
dump ("CLI::getFilter");
|
dump ("CLI::getFilter");
|
||||||
return filter;
|
return filter;
|
||||||
@@ -419,32 +411,35 @@ void CLI::findOverrides ()
|
|||||||
void CLI::categorize ()
|
void CLI::categorize ()
|
||||||
{
|
{
|
||||||
bool foundCommand = false;
|
bool foundCommand = false;
|
||||||
|
bool readOnly = false;
|
||||||
|
|
||||||
std::vector <A>::iterator i;
|
std::vector <A>::iterator a;
|
||||||
for (i = _args.begin (); i != _args.end (); ++i)
|
for (a = _args.begin (); a != _args.end (); ++a)
|
||||||
{
|
{
|
||||||
std::string raw = i->attribute ("raw");
|
std::string raw = a->attribute ("raw");
|
||||||
std::string command;
|
std::string canonical;
|
||||||
if (canonicalize (command, "cmd", raw))
|
if (canonicalize (canonical, "cmd", raw))
|
||||||
{
|
{
|
||||||
_command._name = "argCmd";
|
readOnly = ! exactMatch ("writecmd", canonical);
|
||||||
_command.attribute ("raw", raw);
|
|
||||||
_command.attribute ("canonical", command);
|
a->tag ("CMD");
|
||||||
_readOnly = ! exactMatch ("writecmd", command);
|
a->tag (readOnly ? "READCMD" : "WRITECMD");
|
||||||
_command.tag (_readOnly ? "READCMD" : "WRITECMD");
|
a->attribute ("canonical", canonical);
|
||||||
foundCommand = true;
|
foundCommand = true;
|
||||||
}
|
}
|
||||||
else if (foundCommand && ! _readOnly)
|
else if (a->hasTag ("BINARY") ||
|
||||||
|
a->hasTag ("CONFIG") ||
|
||||||
|
a->hasTag ("RC"))
|
||||||
{
|
{
|
||||||
A a ("argMod", raw);
|
// NOP
|
||||||
a.tag ("MODIFICATION");
|
}
|
||||||
_modifications.push_back (a);
|
else if (foundCommand && ! readOnly)
|
||||||
|
{
|
||||||
|
a->tag ("MODIFICATION");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
A a ("argFilt", raw);
|
a->tag ("FILTER");
|
||||||
a.tag ("FILTER");
|
|
||||||
_filter.push_back (a);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -514,6 +509,8 @@ bool CLI::canonicalize (
|
|||||||
// -tag --> tags _notag_ tag
|
// -tag --> tags _notag_ tag
|
||||||
void CLI::unsweetenTags ()
|
void CLI::unsweetenTags ()
|
||||||
{
|
{
|
||||||
|
// TODO Convert from _filter to _args.
|
||||||
|
/*
|
||||||
std::vector <A> reconstructed;
|
std::vector <A> reconstructed;
|
||||||
std::vector <A>::iterator i;
|
std::vector <A>::iterator i;
|
||||||
for (i = _filter.begin (); i != _filter.end (); ++i)
|
for (i = _filter.begin (); i != _filter.end (); ++i)
|
||||||
@@ -544,6 +541,7 @@ void CLI::unsweetenTags ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
_filter = reconstructed;
|
_filter = reconstructed;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -565,25 +563,6 @@ void CLI::dump (const std::string& label) const
|
|||||||
std::vector <A>::const_iterator a;
|
std::vector <A>::const_iterator a;
|
||||||
for (a = _args.begin (); a != _args.end (); ++a)
|
for (a = _args.begin (); a != _args.end (); ++a)
|
||||||
std::cout << " " << a->dump () << "\n";
|
std::cout << " " << a->dump () << "\n";
|
||||||
|
|
||||||
std::cout << " _rc " << _rc << "\n";
|
|
||||||
|
|
||||||
if (_filter.size ())
|
|
||||||
{
|
|
||||||
std::cout << " _filter\n";
|
|
||||||
for (a = _filter.begin (); a != _filter.end (); ++a)
|
|
||||||
std::cout << " " << a->dump () << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << " _command\n"
|
|
||||||
<< " " << _command.dump () << "\n";
|
|
||||||
|
|
||||||
if (_modifications.size ())
|
|
||||||
{
|
|
||||||
std::cout << " _modifications\n";
|
|
||||||
for (a = _modifications.begin (); a != _modifications.end (); ++a)
|
|
||||||
std::cout << " " << a->dump () << "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -84,11 +84,6 @@ public:
|
|||||||
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::string _rc;
|
|
||||||
A _command;
|
|
||||||
bool _readOnly;
|
|
||||||
std::vector <A> _filter;
|
|
||||||
std::vector <A> _modifications;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user