mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
A3t
- Renamed resolve_aliases to findAliases, for a better fit. - Partially implemented findAliases.
This commit is contained in:
parent
6ad9ef78ba
commit
f439cd4813
3 changed files with 23 additions and 42 deletions
61
src/A3t.cpp
61
src/A3t.cpp
|
@ -45,6 +45,9 @@ extern Context context;
|
||||||
|
|
||||||
static const int minimumMatchLength = 3;
|
static const int minimumMatchLength = 3;
|
||||||
|
|
||||||
|
// Alias expansion limit. Any more indicates some kind of error.
|
||||||
|
const int safetyValveDefault = 10;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
A3t::A3t ()
|
A3t::A3t ()
|
||||||
{
|
{
|
||||||
|
@ -495,71 +498,49 @@ void A3t::inject_defaults ()
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// An alias must be a distinct word on the command line.
|
// An alias must be a distinct word on the command line.
|
||||||
// Aliases may not recurse.
|
void A3t::findAliases ()
|
||||||
void A3t::resolve_aliases ()
|
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
std::vector <std::string> expanded;
|
|
||||||
bool something;
|
bool something;
|
||||||
int safety_valve = safetyValveDefault;
|
int safety_valve = safetyValveDefault;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
something = false;
|
something = false;
|
||||||
std::vector <Arg>::iterator arg;
|
|
||||||
for (arg = this->begin (); arg != this->end (); ++arg)
|
std::string command;
|
||||||
|
std::vector <Tree*>::iterator i;
|
||||||
|
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
||||||
{
|
{
|
||||||
// The -- operator stops alias expansion.
|
// Parser override operator.
|
||||||
if (arg->_raw == "--")
|
if ((*i)->attribute ("raw") == "--")
|
||||||
break;
|
break;
|
||||||
|
|
||||||
std::map <std::string, std::string>::iterator match =
|
// Skip known args.
|
||||||
context.aliases.find (arg->_raw);
|
if (! (*i)->hasTag ("?"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::string raw = (*i)->attribute ("raw");
|
||||||
|
std::map <std::string, std::string>::iterator match = context.aliases.find (raw);
|
||||||
if (match != context.aliases.end ())
|
if (match != context.aliases.end ())
|
||||||
{
|
{
|
||||||
context.debug (std::string ("A3::resolve_aliases '")
|
something = true;
|
||||||
+ arg->_raw
|
|
||||||
+ "' --> '"
|
|
||||||
+ context.aliases[arg->_raw]
|
|
||||||
+ "'");
|
|
||||||
|
|
||||||
std::vector <std::string> words;
|
std::vector <std::string> words;
|
||||||
splitq (words, context.aliases[arg->_raw], ' ');
|
splitq (words, context.aliases[raw], ' ');
|
||||||
|
|
||||||
std::vector <std::string>::iterator word;
|
std::vector <std::string>::iterator word;
|
||||||
for (word = words.begin (); word != words.end (); ++word)
|
for (word = words.begin (); word != words.end (); ++word)
|
||||||
expanded.push_back (*word);
|
{
|
||||||
|
// TODO Insert branch (words) in place of (*i).
|
||||||
something = true;
|
std::cout << "# alias word '" << *word << "'\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
expanded.push_back (arg->_raw);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy any residual tokens.
|
|
||||||
for (; arg != this->end (); ++arg)
|
|
||||||
expanded.push_back (arg->_raw);
|
|
||||||
|
|
||||||
// Only overwrite if something happened.
|
|
||||||
if (something)
|
|
||||||
{
|
|
||||||
this->clear ();
|
|
||||||
std::vector <std::string>::iterator e;
|
|
||||||
for (e = expanded.begin (); e != expanded.end (); ++e)
|
|
||||||
this->push_back (Arg (*e));
|
|
||||||
|
|
||||||
expanded.clear ();
|
|
||||||
|
|
||||||
// The push_back destroyed categorization, redo that now.
|
|
||||||
categorize ();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (something && --safety_valve > 0);
|
while (something && --safety_valve > 0);
|
||||||
|
|
||||||
if (safety_valve <= 0)
|
if (safety_valve <= 0)
|
||||||
context.debug (format ("Nested alias limit of {1} reached.", safetyValveDefault));
|
context.debug (format ("Nested alias limit of {1} reached.", safetyValveDefault));
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -48,12 +48,12 @@ public:
|
||||||
void findCommand ();
|
void findCommand ();
|
||||||
void findIdSequence ();
|
void findIdSequence ();
|
||||||
void findUUIDList ();
|
void findUUIDList ();
|
||||||
|
void findAliases ();
|
||||||
|
|
||||||
void get_overrides (std::string&, File&);
|
void get_overrides (std::string&, File&);
|
||||||
void get_data_location (Path&);
|
void get_data_location (Path&);
|
||||||
void apply_overrides ();
|
void apply_overrides ();
|
||||||
void inject_defaults ();
|
void inject_defaults ();
|
||||||
void resolve_aliases ();
|
|
||||||
void capture_first (const std::string&);
|
void capture_first (const std::string&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -152,7 +152,7 @@ int Context::initialize (int argc, const char** argv)
|
||||||
// Handle Aliases.
|
// Handle Aliases.
|
||||||
loadAliases ();
|
loadAliases ();
|
||||||
a3.resolve_aliases ();
|
a3.resolve_aliases ();
|
||||||
a3t.resolve_aliases ();
|
a3t.findAliases ();
|
||||||
|
|
||||||
// Initialize the color rules, if necessary.
|
// Initialize the color rules, if necessary.
|
||||||
if (color ())
|
if (color ())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue