Fix autocomplete bugs.
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 20s

This commit is contained in:
Your Name
2025-05-11 19:26:25 +12:00
parent 7e95779d98
commit a2340dcb80
7 changed files with 79 additions and 38 deletions

View File

@ -41,34 +41,34 @@ int main(int argc, char* argv[]) {
if (args.size() < 2)
args.push_back("help");
ASSERT(args.size() > 1, "No command provided, logic error.");
std::string cmd = args[1];
CommandContext ctx{args[0], args[1], std::vector<std::string>(args.begin() + 2, args.end())};
if (cmd == "autocomplete") {
CommandRegistry::instance().autocomplete(args);
if (ctx.command == "autocomplete") {
CommandRegistry::instance().autocomplete(ctx);
return 0;
}
const CommandInfo* info = CommandRegistry::instance().find_command(cmd);
const CommandInfo* info = CommandRegistry::instance().find_command(ctx.command);
if (!info) {
std::cerr << "Unknown command: " << cmd << std::endl;
std::cerr << "Unknown command: " << ctx.command << std::endl;
return 1;
}
if (info->requires_config && !gConfig().is_config_set()) {
std::cerr << "Configuration required for command: " << cmd << std::endl;
std::cerr << "Valid dropshell configuration required for command: " << ctx.command << std::endl;
std::cerr << "Please run 'dropshell edit' to set up the dropshell configuration." << std::endl;
return 1;
}
int arg_count = args.size() - 2;
int arg_count = ctx.args.size();
if (arg_count < info->min_args || (info->max_args != -1 && arg_count > info->max_args)) {
std::cerr << "Invalid number of arguments for command: " << cmd << std::endl;
std::cerr << "Invalid number of arguments for command: " << ctx.command << std::endl;
std::cerr << "Usage: " << std::endl;
std::cout << " ";
print_left_aligned(info->help_usage,30);
std::cout << info->help_description << std::endl;
return 1;
}
CommandContext ctx{args[0], cmd, std::vector<std::string>(args.begin() + 2, args.end())};
return info->handler(ctx);
}