'Generic Commit'
Some checks failed
Build-Test-Publish / build (push) Failing after 17s

This commit is contained in:
Your Name 2025-06-22 09:05:41 +12:00
parent d5d211b866
commit b0fba2f9d8
5 changed files with 100 additions and 1 deletions

View File

@ -120,4 +120,39 @@ void DropshellScriptManager::addAutocomplete(const std::string& toolName) {
std::ofstream outfile(dropshelltool::DROPSHELL_RC_PATH, std::ios::trunc); std::ofstream outfile(dropshelltool::DROPSHELL_RC_PATH, std::ios::trunc);
for (const auto& l : lines) outfile << l << "\n"; for (const auto& l : lines) outfile << l << "\n";
outfile.close(); outfile.close();
} }
void DropshellScriptManager::removeAutocomplete(const std::string& toolName) {
ensureExists();
std::ifstream infile(dropshelltool::DROPSHELL_RC_PATH);
std::vector<std::string> lines;
std::string line;
std::string blockStart = "# GETPKG-AUTOCOMPLETE-START: " + toolName;
std::string blockEnd = "# GETPKG-AUTOCOMPLETE-END: " + toolName;
bool inBlock = false;
while (std::getline(infile, line)) {
if (trim(line) == blockStart) {
inBlock = true;
continue;
}
if (trim(line) == blockEnd) {
inBlock = false;
continue;
}
if (inBlock) {
continue;
}
// Also skip the complete line
if (line.find("# autocomplete: " + toolName) != std::string::npos) {
continue;
}
lines.push_back(line);
}
infile.close();
std::ofstream outfile(dropshelltool::DROPSHELL_RC_PATH, std::ios::trunc);
for (const auto& l : lines) outfile << l << "\n";
outfile.close();
}

View File

@ -9,4 +9,5 @@ public:
void addToolEntry(const std::string& toolName, const std::string& toolDir); void addToolEntry(const std::string& toolName, const std::string& toolDir);
void removeToolEntry(const std::string& toolName); void removeToolEntry(const std::string& toolName);
void addAutocomplete(const std::string& toolName); void addAutocomplete(const std::string& toolName);
void removeAutocomplete(const std::string& toolName);
}; };

View File

@ -370,6 +370,51 @@ int create_tool(int argc, char* argv[]) {
return 0; return 0;
} }
int uninstall_tool(int argc, char* argv[]) {
if (argc < 3) {
std::cerr << "Usage: getpkg uninstall <tool_name>" << std::endl;
return 1;
}
std::string toolName = argv[2];
// Validate tool name
if (!isValidToolName(toolName)) {
std::cerr << "Invalid tool name. Tool names can only contain letters, numbers, dash, underscore, and dot." << std::endl;
return 1;
}
std::string home = get_home();
std::filesystem::path configDir = std::filesystem::path(home) / ".config/getpkg";
std::filesystem::path binDir = std::filesystem::path(home) / ".local/bin/getpkg" / toolName;
std::filesystem::path toolInfoPath = configDir / (toolName + ".json");
// Check if tool is installed
if (!std::filesystem::exists(toolInfoPath)) {
std::cerr << "Tool " << toolName << " is not installed." << std::endl;
return 1;
}
std::cout << "Uninstalling " << toolName << "..." << std::endl;
// Remove tool entries from bashrc_getpkg
DropshellScriptManager scriptManager;
scriptManager.removeToolEntry(toolName);
scriptManager.removeAutocomplete(toolName);
// Remove tool directory
if (std::filesystem::exists(binDir)) {
std::filesystem::remove_all(binDir);
}
// Remove tool info file
if (std::filesystem::exists(toolInfoPath)) {
std::filesystem::remove(toolInfoPath);
}
std::cout << "Uninstalled " << toolName << " successfully." << std::endl;
return 0;
}
} // end anonymous namespace } // end anonymous namespace
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
@ -380,6 +425,8 @@ int main(int argc, char* argv[]) {
std::string command = argv[1]; std::string command = argv[1];
if (command == "install") { if (command == "install") {
return install_tool(argc, argv); return install_tool(argc, argv);
} else if (command == "uninstall") {
return uninstall_tool(argc, argv);
} else if (command == "publish") { } else if (command == "publish") {
return publish_tool(argc, argv); return publish_tool(argc, argv);
} else if (command == "update") { } else if (command == "update") {
@ -387,6 +434,7 @@ int main(int argc, char* argv[]) {
} else if (command == "autocomplete") { } else if (command == "autocomplete") {
std::vector<std::string> args(argv + 2, argv + argc); std::vector<std::string> args(argv + 2, argv + argc);
if (args.empty()) std::cout << R"(install if (args.empty()) std::cout << R"(install
uninstall
publish publish
update update
version version
@ -402,6 +450,7 @@ help
std::cout << "Commands:" << std::endl; std::cout << "Commands:" << std::endl;
std::cout << " <tool_name> Install/update the specified tool" << std::endl; std::cout << " <tool_name> Install/update the specified tool" << std::endl;
std::cout << " install <tool_name> Install/update tool (legacy)" << std::endl; std::cout << " install <tool_name> Install/update tool (legacy)" << std::endl;
std::cout << " uninstall <tool_name> Uninstall the specified tool" << std::endl;
std::cout << " publish <tool_name[:ARCH]> <folder> Publish a tool (ARCH optional)" << std::endl; std::cout << " publish <tool_name[:ARCH]> <folder> Publish a tool (ARCH optional)" << std::endl;
std::cout << " update Update getpkg and all tools" << std::endl; std::cout << " update Update getpkg and all tools" << std::endl;
std::cout << " version Show getpkg version" << std::endl; std::cout << " version Show getpkg version" << std::endl;

View File

@ -0,0 +1,7 @@
#\!/bin/bash
if [ "$1" = "version" ]; then
echo "1.0.0"
elif [ "$1" = "autocomplete" ]; then
echo "help"
echo "version"
fi

View File

@ -0,0 +1,7 @@
#\!/bin/bash
if [ "$1" = "version" ]; then
echo "1.0.0"
elif [ "$1" = "autocomplete" ]; then
echo "help"
echo "version"
fi