Compare commits
1 Commits
v2025.0630
...
main
Author | SHA1 | Date | |
---|---|---|---|
73c94f34f6 |
@ -1150,6 +1150,85 @@ void show_help() {
|
||||
std::cout << " ~/.local/bin/getpkg/ Installed tool binaries" << std::endl;
|
||||
}
|
||||
|
||||
int autocomplete_command(int argc, char* argv[]) {
|
||||
std::vector<std::string> args(argv + 2, argv + argc);
|
||||
|
||||
// If no arguments, return all commands
|
||||
if (args.empty()) {
|
||||
std::cout << "install\n";
|
||||
std::cout << "uninstall\n";
|
||||
std::cout << "publish\n";
|
||||
std::cout << "unpublish\n";
|
||||
std::cout << "update\n";
|
||||
std::cout << "version\n";
|
||||
std::cout << "create\n";
|
||||
std::cout << "hash\n";
|
||||
std::cout << "list\n";
|
||||
std::cout << "clean\n";
|
||||
std::cout << "help\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
const std::string& subcommand = args[0];
|
||||
|
||||
// Handle autocompletion for specific commands
|
||||
if (subcommand == "install") {
|
||||
// For install, we could suggest popular packages or recently published ones
|
||||
// For now, just return empty (no specific completions)
|
||||
return 0;
|
||||
} else if (subcommand == "uninstall") {
|
||||
// For uninstall, list installed tools
|
||||
std::filesystem::path configDir = std::filesystem::path(std::getenv("HOME")) / ".config" / "getpkg";
|
||||
if (std::filesystem::exists(configDir)) {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(configDir)) {
|
||||
if (entry.path().extension() == ".json") {
|
||||
std::string toolName = entry.path().stem().string();
|
||||
std::cout << toolName << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} else if (subcommand == "publish") {
|
||||
// For publish, suggest architecture suffixes after tool name
|
||||
if (args.size() >= 2) {
|
||||
// If we have tool_name already, suggest architectures
|
||||
std::cout << "x86_64\n";
|
||||
std::cout << "aarch64\n";
|
||||
std::cout << "universal\n";
|
||||
}
|
||||
return 0;
|
||||
} else if (subcommand == "unpublish") {
|
||||
// For unpublish, list installed tools (similar to uninstall)
|
||||
std::filesystem::path configDir = std::filesystem::path(std::getenv("HOME")) / ".config" / "getpkg";
|
||||
if (std::filesystem::exists(configDir)) {
|
||||
for (const auto& entry : std::filesystem::directory_iterator(configDir)) {
|
||||
if (entry.path().extension() == ".json") {
|
||||
std::string toolName = entry.path().stem().string();
|
||||
std::cout << toolName << "\n";
|
||||
// Also suggest with architecture suffixes
|
||||
std::cout << toolName << ":x86_64\n";
|
||||
std::cout << toolName << ":aarch64\n";
|
||||
std::cout << toolName << ":universal\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} else if (subcommand == "create") {
|
||||
// For create, no specific completions (tool name and directory are user-defined)
|
||||
return 0;
|
||||
} else if (subcommand == "hash") {
|
||||
// For hash, suggest file extensions
|
||||
if (args.size() >= 2) {
|
||||
std::cout << "*.tgz\n";
|
||||
std::cout << "*.tar.gz\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// No specific completions for other commands
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@ -1169,19 +1248,7 @@ int main(int argc, char* argv[]) {
|
||||
} else if (command == "update") {
|
||||
return update_tool(argc, argv);
|
||||
} else if (command == "autocomplete") {
|
||||
std::vector<std::string> args(argv + 2, argv + argc);
|
||||
if (args.empty()) std::cout << R"(install
|
||||
uninstall
|
||||
publish
|
||||
unpublish
|
||||
update
|
||||
version
|
||||
create
|
||||
hash
|
||||
list
|
||||
clean
|
||||
help
|
||||
)";
|
||||
return autocomplete_command(argc, argv);
|
||||
} else if (command == "version") {
|
||||
std::cout << dropshell::VERSION << std::endl;
|
||||
} else if (command == "create") {
|
||||
|
Reference in New Issue
Block a user