mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
CLI
- Implemented ::canonicalize.
This commit is contained in:
parent
227e0bd8c8
commit
4d921c7920
1 changed files with 43 additions and 0 deletions
43
src/CLI.cpp
43
src/CLI.cpp
|
@ -33,6 +33,12 @@
|
|||
|
||||
extern Context context;
|
||||
|
||||
// Overridden by rc.abbreviation.minimum.
|
||||
static int minimumMatchLength = 3;
|
||||
|
||||
// Alias expansion limit. Any more indicates some kind of error.
|
||||
static int safetyValveDefault = 10;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CLI::CLI ()
|
||||
: _program ("")
|
||||
|
@ -128,6 +134,43 @@ bool CLI::exactMatch (
|
|||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Search for 'value' in _entities category, return canonicalized value.
|
||||
bool CLI::canonicalize (
|
||||
std::string& canonicalized,
|
||||
const std::string& category,
|
||||
const std::string& value) const
|
||||
{
|
||||
// Find the category.
|
||||
std::pair <std::multimap <std::string, std::string>::const_iterator, std::multimap <std::string, std::string>::const_iterator> c;
|
||||
c = _entities.equal_range (category);
|
||||
|
||||
// Extract a list of entities for category.
|
||||
std::vector <std::string> options;
|
||||
std::multimap <std::string, std::string>::const_iterator e;
|
||||
for (e = c.first; e != c.second; ++e)
|
||||
{
|
||||
// Shortcut: if an exact match is found, success.
|
||||
if (value == e->second)
|
||||
{
|
||||
canonicalized = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
options.push_back (e->second);
|
||||
}
|
||||
|
||||
// Match against the options, throw away results.
|
||||
std::vector <std::string> matches;
|
||||
if (autoComplete (value, options, matches, minimumMatchLength) == 1)
|
||||
{
|
||||
canonicalized = matches[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CLI::dump (const std::string& label) const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue