test: Update 6 files
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 22s
Build-Test-Publish / build (linux/arm64) (push) Successful in 26s

This commit is contained in:
j842
2025-08-17 16:36:20 +12:00
parent c36dadb76f
commit 629210ee9d
6 changed files with 24 additions and 81 deletions

View File

@@ -9,13 +9,11 @@ Usage: dehydrate [OPTIONS] SOURCE DEST
Options:
-s Silent mode (no output)
-u Update dehydrate to the latest version
-v Show version only
Examples:
dehydrate file.txt output/ Creates _file.txt.cpp and _file.txt.hpp in output/
dehydrate src/ output/ Creates _src.cpp and _src.hpp in output/
dehydrate -u Updates dehydrate to the latest version
dehydrate -v Shows version number
dehydrate version Shows version number
)";
@@ -36,8 +34,6 @@ Args parse_args(int argc, char* argv[]) {
if (flag == "-s") {
args.silent = true;
} else if (flag == "-u") {
args.update = true;
} else if (flag == "-v") {
args.version = true;
} else {
@@ -47,8 +43,8 @@ Args parse_args(int argc, char* argv[]) {
idx++;
}
// If update or version flag is set, return early
if (args.update || args.version) {
// If version flag is set, return early
if (args.version) {
return args;
}

View File

@@ -3,7 +3,6 @@
struct Args {
bool silent = false;
bool update = false;
bool version = false;
std::string source;
std::string dest;

View File

@@ -1,58 +1,11 @@
#include <iostream>
#include <filesystem>
#include <unistd.h>
#include "argparse.hpp"
#include "generator.hpp"
#include "version.hpp"
std::string get_arch()
{
// determine the architecture of the system
std::string arch;
#ifdef __aarch64__
arch = "arm64";
#elif __x86_64__
arch = "amd64";
#endif
return arch;
}
int update()
{
// determine path to this executable
std::filesystem::path exepath = std::filesystem::canonical("/proc/self/exe");
std::filesystem::path parent_path = exepath.parent_path();
std::string project_name = exepath.filename().string();
// determine the architecture of the system
std::string arch = get_arch();
std::string url = "https://gitea.jde.nz/public/"+project_name+"/releases/download/latest/"+project_name+"." + arch;
// download new version, preserve permissions and ownership
std::string bash_script;
bash_script += "docker run --rm -v "+parent_path.string()+":/target";
bash_script += " gitea.jde.nz/public/debian-curl:latest";
bash_script += " sh -c \"";
bash_script += " curl -fsSL " + url + " -o /target/"+project_name+"_temp &&";
bash_script += " chmod --reference=/target/"+project_name+" /target/"+project_name+"_temp &&";
bash_script += " chown --reference=/target/"+project_name+" /target/"+project_name+"_temp &&";
bash_script += " mv /target/"+project_name+"_temp /target/"+project_name;
bash_script += "\"";
std::cout << "Updating " << exepath << " to the latest " << arch << " version." << std::endl;
// std::cout << "bash_script: " << std::endl
// << bash_script << std::endl;
// run the bash script
execlp("bash", "bash", "-c", bash_script.c_str(), (char *)nullptr);
std::cerr << "Failed to execute command." << std::endl;
return -1;
}
int main(int argc, char* argv[]) {
@@ -65,12 +18,6 @@ int main(int argc, char* argv[]) {
return 0;
}
// Handle update request
if (args.update) {
std::cout << "Dehydrate version " << VERSION << std::endl;
return update();
}
// Show version for normal operations (unless silent)
if (!args.silent) {
std::cout << "Dehydrate version " << VERSION << std::endl;