mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-29 10:03:26 +02:00
CmdReport: Added findExtension with auto-completion
This commit is contained in:
parent
0f9797da87
commit
41d76bbf87
1 changed files with 31 additions and 0 deletions
|
@ -26,9 +26,40 @@
|
||||||
|
|
||||||
#include <cmake.h>
|
#include <cmake.h>
|
||||||
#include <commands.h>
|
#include <commands.h>
|
||||||
|
#include <shared.h>
|
||||||
|
#include <format.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#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 (
|
int CmdReport (
|
||||||
const std::vector <std::string>& args,
|
const std::vector <std::string>& args,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue