mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Code Cleanup
- Consolidated two forms of guess ().
This commit is contained in:
parent
4ede817ead
commit
98978c7c00
1 changed files with 12 additions and 29 deletions
|
@ -156,12 +156,11 @@ static const char* commands[] =
|
||||||
static std::vector <std::string> customReports;
|
static std::vector <std::string> customReports;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void guess (const std::string& type, const char** list, std::string& candidate)
|
void guess (
|
||||||
|
const std::string& type,
|
||||||
|
std::vector<std::string>& options,
|
||||||
|
std::string& candidate)
|
||||||
{
|
{
|
||||||
std::vector <std::string> options;
|
|
||||||
for (int i = 0; list[i][0]; ++i)
|
|
||||||
options.push_back (list[i]);
|
|
||||||
|
|
||||||
std::vector <std::string> matches;
|
std::vector <std::string> matches;
|
||||||
autoComplete (candidate, options, matches);
|
autoComplete (candidate, options, matches);
|
||||||
if (1 == matches.size ())
|
if (1 == matches.size ())
|
||||||
|
@ -189,32 +188,16 @@ void guess (const std::string& type, const char** list, std::string& candidate)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void guess (const std::string& type, std::vector<std::string>& options, std::string& candidate)
|
void guess (
|
||||||
|
const std::string& type,
|
||||||
|
const char** list,
|
||||||
|
std::string& candidate)
|
||||||
{
|
{
|
||||||
std::vector <std::string> matches;
|
std::vector <std::string> options;
|
||||||
autoComplete (candidate, options, matches);
|
for (int i = 0; list[i][0]; ++i)
|
||||||
if (1 == matches.size ())
|
options.push_back (list[i]);
|
||||||
candidate = matches[0];
|
|
||||||
|
|
||||||
else if (0 == matches.size ())
|
guess (type, options, candidate);
|
||||||
candidate = "";
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::string error = "Ambiguous ";
|
|
||||||
error += type;
|
|
||||||
error += " '";
|
|
||||||
error += candidate;
|
|
||||||
error += "' - could be either of ";
|
|
||||||
for (size_t i = 0; i < matches.size (); ++i)
|
|
||||||
{
|
|
||||||
if (i)
|
|
||||||
error += ", ";
|
|
||||||
error += matches[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue