mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Bug 445 - The command 'task h' should be ambiguous, yet works
- Fixed bug #445, which caused task to not notice that the command 'h' is ambiguous. This was caused by mistakenly first autoCompleting against a set of alias names, during canonicalization, instead of autoCompleting against the whole set of possible commands and aliases, then doing the canonicalization. The order was reversed. - Also populated list of all commands with alias names, so the above could be corrected.
This commit is contained in:
parent
e886f7635b
commit
3952765de0
3 changed files with 88 additions and 66 deletions
|
@ -36,6 +36,8 @@
|
|||
+ Fixed bug #439, which ignored dateformat.annotation for sparse annotations.
|
||||
+ Fixed bug #441, which misparsed '/a/a:/' as an attribute, rather than a
|
||||
substitution (thanks to Michelle Crane).
|
||||
+ Fixed bug #445, which caused task to not notice that the command 'h' is
|
||||
ambiguous.
|
||||
+ Fixed problem with command line configuration overrides that had no
|
||||
values.
|
||||
|
||||
|
|
42
src/Cmd.cpp
42
src/Cmd.cpp
|
@ -56,44 +56,64 @@ Cmd::~Cmd ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Determines whether the string represents a unique command name or custom
|
||||
// report name.
|
||||
//
|
||||
// To be a valid command:
|
||||
// 1. 'input' should autocomplete to one of 'commands'.
|
||||
bool Cmd::valid (const std::string& input)
|
||||
{
|
||||
load ();
|
||||
|
||||
std::vector <std::string> matches;
|
||||
autoComplete (lowerCase (context.canonicalize (input)), commands, matches);
|
||||
return matches.size () == 1 ? true : false;
|
||||
autoComplete (lowerCase (input), commands, matches);
|
||||
if (matches.size () == 1)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Determines whether the string represents a valid custom report name.
|
||||
//
|
||||
// To be a valid custom command:
|
||||
// 1. 'input' should autocomplete to one of 'commands'.
|
||||
// 2. the result, canonicalized, should autocomplete to one of 'customreports'.
|
||||
bool Cmd::validCustom (const std::string& input)
|
||||
{
|
||||
load ();
|
||||
|
||||
std::vector <std::string> matches;
|
||||
autoComplete (lowerCase (context.canonicalize (input)), customReports, matches);
|
||||
return matches.size () == 1 ? true : false;
|
||||
autoComplete (lowerCase (input), commands, matches);
|
||||
if (matches.size () == 1)
|
||||
{
|
||||
std::string canonical = context.canonicalize (matches[0]);
|
||||
matches.clear ();
|
||||
autoComplete (canonical, customReports, matches);
|
||||
if (matches.size () == 1)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// To be a valid custom command:
|
||||
// 1. 'input' should autocomplete to one of 'commands'.
|
||||
// 2. the result may then canonicalize to another command.
|
||||
void Cmd::parse (const std::string& input)
|
||||
{
|
||||
load ();
|
||||
|
||||
std::string candidate = lowerCase (context.canonicalize (input));
|
||||
|
||||
std::vector <std::string> matches;
|
||||
autoComplete (candidate, commands, matches);
|
||||
autoComplete (input, commands, matches);
|
||||
if (1 == matches.size ())
|
||||
command = matches[0];
|
||||
command = context.canonicalize (matches[0]);
|
||||
|
||||
else if (0 == matches.size ())
|
||||
command = "";
|
||||
|
||||
else
|
||||
{
|
||||
std::string error = "Ambiguous command '" + candidate + "' - could be either of "; // TODO i18n
|
||||
std::string error = "Ambiguous command '" + input + "' - could be either of "; // TODO i18n
|
||||
|
||||
std::sort (matches.begin (), matches.end ());
|
||||
std::string combined;
|
||||
|
@ -180,6 +200,10 @@ void Cmd::load ()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now load the aliases.
|
||||
foreach (i, context.aliases)
|
||||
commands.push_back (i->first);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -475,10 +475,6 @@ int handleCompletionCommands (std::string &outs)
|
|||
std::vector <std::string> commands;
|
||||
context.cmd.allCommands (commands);
|
||||
|
||||
// Concatenate a list of all aliases.
|
||||
foreach (name, context.aliases)
|
||||
commands.push_back (name->first);
|
||||
|
||||
// Sort alphabetically.
|
||||
std::sort (commands.begin (), commands.end ());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue