This commit is contained in:
parent
a6dafc3a51
commit
ea3367d8d9
@ -9,6 +9,19 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace autocomplete {
|
||||||
|
|
||||||
|
const std::set<std::string> system_commands_noargs = {"templates","autocomplete_list_servers","autocomplete_list_services","autocomplete_list_commands"};
|
||||||
|
const std::set<std::string> system_commands_always_available = {"help","edit"};
|
||||||
|
const std::set<std::string> system_commands_require_config = {"server","templates","create-service","create-template","create-server","ssh","list"};
|
||||||
|
|
||||||
|
bool is_no_arg_cmd(std::string cmd)
|
||||||
|
{
|
||||||
|
return system_commands_noargs.find(cmd) != system_commands_noargs.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool dropshell::autocomplete(const std::vector<std::string> &args)
|
bool dropshell::autocomplete(const std::vector<std::string> &args)
|
||||||
{
|
{
|
||||||
if (args.size() < 3) // dropshell autocomplete ???
|
if (args.size() < 3) // dropshell autocomplete ???
|
||||||
@ -30,10 +43,8 @@ bool dropshell::autocomplete(const std::vector<std::string> &args)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (autocomplete::is_no_arg_cmd(cmd))
|
||||||
std::string noargcmds[] = {"templates","autocomplete_list_servers","autocomplete_list_services","autocomplete_list_commands"};
|
return true; // no arguments needed.
|
||||||
if (std::find(std::begin(noargcmds), std::end(noargcmds), cmd) != std::end(noargcmds))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (!dropshell::gConfig().is_config_set())
|
if (!dropshell::gConfig().is_config_set())
|
||||||
return false; // can't help without working config.
|
return false; // can't help without working config.
|
||||||
@ -89,14 +100,11 @@ bool dropshell::autocomplete_list_commands()
|
|||||||
dropshell::get_all_used_commands(commands);
|
dropshell::get_all_used_commands(commands);
|
||||||
|
|
||||||
// add in commmands hard-coded and handled in main
|
// add in commmands hard-coded and handled in main
|
||||||
commands.merge(std::set<std::string>{
|
commands.insert(autocomplete::system_commands_always_available.begin(), autocomplete::system_commands_always_available.end());
|
||||||
"help","edit" // these are always available.
|
|
||||||
});
|
|
||||||
if (dropshell::gConfig().is_config_set())
|
if (dropshell::gConfig().is_config_set())
|
||||||
commands.merge(std::set<std::string>{
|
commands.insert(autocomplete::system_commands_require_config.begin(), autocomplete::system_commands_require_config.end());
|
||||||
"server","templates","create-service","create-template","create-server","ssh",
|
|
||||||
"list" // only if we have a config.
|
|
||||||
});
|
|
||||||
for (const auto& command : commands) {
|
for (const auto& command : commands) {
|
||||||
std::cout << command << std::endl;
|
std::cout << command << std::endl;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user