This commit is contained in:
parent
d5d211b866
commit
b0fba2f9d8
@ -121,3 +121,38 @@ void DropshellScriptManager::addAutocomplete(const std::string& toolName) {
|
||||
for (const auto& l : lines) outfile << l << "\n";
|
||||
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();
|
||||
}
|
@ -9,4 +9,5 @@ public:
|
||||
void addToolEntry(const std::string& toolName, const std::string& toolDir);
|
||||
void removeToolEntry(const std::string& toolName);
|
||||
void addAutocomplete(const std::string& toolName);
|
||||
void removeAutocomplete(const std::string& toolName);
|
||||
};
|
@ -370,6 +370,51 @@ int create_tool(int argc, char* argv[]) {
|
||||
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
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@ -380,6 +425,8 @@ int main(int argc, char* argv[]) {
|
||||
std::string command = argv[1];
|
||||
if (command == "install") {
|
||||
return install_tool(argc, argv);
|
||||
} else if (command == "uninstall") {
|
||||
return uninstall_tool(argc, argv);
|
||||
} else if (command == "publish") {
|
||||
return publish_tool(argc, argv);
|
||||
} else if (command == "update") {
|
||||
@ -387,6 +434,7 @@ int main(int argc, char* argv[]) {
|
||||
} else if (command == "autocomplete") {
|
||||
std::vector<std::string> args(argv + 2, argv + argc);
|
||||
if (args.empty()) std::cout << R"(install
|
||||
uninstall
|
||||
publish
|
||||
update
|
||||
version
|
||||
@ -402,6 +450,7 @@ help
|
||||
std::cout << "Commands:" << 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 << " 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 << " update Update getpkg and all tools" << std::endl;
|
||||
std::cout << " version Show getpkg version" << std::endl;
|
||||
|
7
getpkg/test-uninstall/test-uninstall
Executable file
7
getpkg/test-uninstall/test-uninstall
Executable file
@ -0,0 +1,7 @@
|
||||
#\!/bin/bash
|
||||
if [ "$1" = "version" ]; then
|
||||
echo "1.0.0"
|
||||
elif [ "$1" = "autocomplete" ]; then
|
||||
echo "help"
|
||||
echo "version"
|
||||
fi
|
7
getpkg/test-uninstall/test-uninstall-dir/test-uninstall
Executable file
7
getpkg/test-uninstall/test-uninstall-dir/test-uninstall
Executable file
@ -0,0 +1,7 @@
|
||||
#\!/bin/bash
|
||||
if [ "$1" = "version" ]; then
|
||||
echo "1.0.0"
|
||||
elif [ "$1" = "autocomplete" ]; then
|
||||
echo "help"
|
||||
echo "version"
|
||||
fi
|
Loading…
x
Reference in New Issue
Block a user