mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
zcmdcat: Refactor for clang 3.0 compatibility
This commit is contained in:
parent
c78fc47402
commit
aea3091bdb
1 changed files with 40 additions and 9 deletions
|
@ -77,25 +77,56 @@ CmdZshCommands::CmdZshCommands ()
|
||||||
_category = Command::Category::internal;
|
_category = Command::Category::internal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
struct ZshCommand
|
||||||
|
{
|
||||||
|
bool operator< (const struct ZshCommand&);
|
||||||
|
Command::Category _category;
|
||||||
|
std::string _command;
|
||||||
|
std::string _description;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool ZshCommand::operator< (const struct ZshCommand& other)
|
||||||
|
{
|
||||||
|
// Lexicographical comparison.
|
||||||
|
if (_category != other._category)
|
||||||
|
return (_category < other._category);
|
||||||
|
|
||||||
|
if (_command != other._command)
|
||||||
|
return (_command < other._command);
|
||||||
|
|
||||||
|
if (_description != other._description)
|
||||||
|
return (_description < other._description);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int CmdZshCommands::execute (std::string& output)
|
int CmdZshCommands::execute (std::string& output)
|
||||||
{
|
{
|
||||||
// Get a list of all command descriptions, sorted by category and then
|
// Get a list of all command descriptions, sorted by category and then
|
||||||
// alphabetically by command name.
|
// alphabetically by command name.
|
||||||
typedef std::tuple <Command::Category, std::string, std::string> Element;
|
|
||||||
std::vector <Element> commands;
|
// Since not all supported compilers support tuples, we use a least common
|
||||||
|
// denominator alternative: a custom struct type.
|
||||||
|
|
||||||
|
std::vector <ZshCommand> commands;
|
||||||
for (auto& command : context.commands)
|
for (auto& command : context.commands)
|
||||||
commands.push_back (std::make_tuple (command.second->_category,
|
{
|
||||||
|
ZshCommand zshCommand {command.second->_category,
|
||||||
command.first,
|
command.first,
|
||||||
command.second->description()));
|
command.second->description ()};
|
||||||
|
commands.push_back (zshCommand);
|
||||||
|
}
|
||||||
|
|
||||||
std::sort (commands.begin (), commands.end ());
|
std::sort (commands.begin (), commands.end ());
|
||||||
|
|
||||||
// Emit the commands in order.
|
// Emit the commands in order.
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
for (auto& c : commands)
|
for (auto& zc : commands)
|
||||||
out << std::get<1> (c) << ":"
|
out << zc._command << ":"
|
||||||
<< Command::categoryNames.at (std::get<0> (c)) << ":"
|
<< Command::categoryNames.at (zc._category) << ":"
|
||||||
<< std::get<2> (c) << "\n";
|
<< zc._description << "\n";
|
||||||
|
|
||||||
output = out.str ();
|
output = out.str ();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue