dropshell/runner/src/main.cpp
Your Name b5bc7b611d
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 21s
Runner.
2025-05-10 12:43:25 +12:00

42 lines
1.0 KiB
C++

#include "runner.h"
#include "base64.h"
#include <iostream>
#include <string>
void print_usage() {
std::cerr << "Usage: runner BASE64COMMAND" << std::endl;
std::cerr << " where BASE64COMMAND is a Base64 encoded JSON string" << std::endl;
}
int main(int argc, char* argv[]) {
if (argc != 2) {
print_usage();
return 1;
}
std::string base64_command = argv[1];
std::string json_string;
try {
// Decode Base64
json_string = base64_decode(base64_command);
} catch (const std::exception& e) {
std::cerr << "Error decoding Base64: " << e.what() << std::endl;
return 1;
}
// Parse JSON
nlohmann::json run_json;
try {
run_json = nlohmann::json::parse(json_string);
} catch (const nlohmann::json::parse_error& e) {
std::cerr << "Error parsing JSON: " << e.what() << std::endl;
return 1;
}
// Execute command
bool success = dropshell::Runner::run(run_json);
// Return the exit code
return success ? 0 : 1;
}