ls: List scripts outside of hack/scripts

Closes #412
develop
lethosor 2017-02-05 22:11:35 -05:00
parent 34988e53b9
commit f2164d27c9
1 changed files with 21 additions and 8 deletions

@ -279,19 +279,24 @@ static void listScripts(PluginManager *plug_mgr, std::map<string,string> &pset,
std::vector<string> files;
Filesystem::listdir(path, files);
path += '/';
for (size_t i = 0; i < files.size(); i++)
{
if (hasEnding(files[i], ".lua"))
{
std::string help = getScriptHelp(path + files[i], "--");
pset[prefix + files[i].substr(0, files[i].size()-4)] = help;
string help = getScriptHelp(path + files[i], "--");
string key = prefix + files[i].substr(0, files[i].size()-4);
if (pset.find(key) == pset.end()) {
pset[key] = help;
}
}
else if (plug_mgr->ruby && plug_mgr->ruby->is_enabled() && hasEnding(files[i], ".rb"))
{
std::string help = getScriptHelp(path + files[i], "#");
pset[prefix + files[i].substr(0, files[i].size()-3)] = help;
string help = getScriptHelp(path + files[i], "#");
string key = prefix + files[i].substr(0, files[i].size()-3);
if (pset.find(key) == pset.end()) {
pset[key] = help;
}
}
else if (all && !files[i].empty() && files[i][0] != '.')
{
@ -300,6 +305,14 @@ static void listScripts(PluginManager *plug_mgr, std::map<string,string> &pset,
}
}
static void listAllScripts(map<string, string> &pset, bool all)
{
vector<string> paths;
Core::getInstance().getScriptPaths(&paths);
for (string path : paths)
listScripts(Core::getInstance().getPluginManager(), pset, path, all);
}
namespace {
struct ScriptArgs {
const string *pcmd;
@ -418,7 +431,7 @@ static bool try_autocomplete(color_ostream &con, const std::string &first, std::
bool all = (first.find('/') != std::string::npos);
std::map<string, string> scripts;
listScripts(plug_mgr, scripts, Core::getInstance().getHackPath() + "scripts/", all);
listAllScripts(scripts, all);
for (auto iter = scripts.begin(); iter != scripts.end(); ++iter)
if (iter->first.substr(0, first.size()) == first)
possible.push_back(iter->first);
@ -907,7 +920,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, v
con.reset_color();
}
std::map<string, string> scripts;
listScripts(plug_mgr, scripts, getHackPath() + "scripts/", all);
listAllScripts(scripts, all);
if (!scripts.empty())
{
con.print("\nscripts:\n");