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