CmdReport: Added findExtension with auto-completion

This commit is contained in:
Paul Beckingham 2016-03-26 12:02:32 -04:00
parent 0f9797da87
commit 41d76bbf87

View file

@ -26,9 +26,40 @@
#include <cmake.h>
#include <commands.h>
#include <shared.h>
#include <format.h>
#include <iostream>
#include <sstream>
////////////////////////////////////////////////////////////////////////////////
// Given a partial match for an extension script name, find the full patch of
// the extension it may match.
static std::string findExtension (
Extensions& extensions,
const std::string& partial)
{
auto scripts = extensions.all ();
std::vector <std::string> options;
for (auto& script : scripts)
options.push_back (File (script).name ());
std::vector <std::string> matches;
autoComplete (partial, options, matches, 3);
if (matches.size () == 0)
throw format ("The report '{1}' is not recognized.", partial);
if (matches.size () > 1)
throw format ("The report '{1}' is ambiguous, and could mean one of: {2}",
partial,
join (", ", matches));
// Now map matches[0] back to it's corresponding option.
for (auto& script : scripts)
if (File (script).name () == matches[0])
return script;
}
////////////////////////////////////////////////////////////////////////////////
int CmdReport (
const std::vector <std::string>& args,