#include #include #include #include "str_utils.h" #include #ifndef VERSION #define VERSION "unknown-DEV" #endif bool shortHand(const char* str, char shortHand); int main(const int argc, char** argv) { if (argc > 1) { for (int i = 1; i < argc; i++) { const char* arg = argv[i]; if (strcmp(arg, "--help") == 0 || shortHand(arg, 'h')) { std::cout << "Server Arduino Watchdog version '" << VERSION << "' by Zacharias (c) 2025" << std::endl << std::endl << "Options:" << std::endl << "[requires root] -short --long-option Description" << std::endl << "[X] --init Initializes the Server end of this system, find the arduino and creates systemd services" << std::endl << " -h --help Prints this help message" << std::endl << " -b --heartbeat Sends a heartbeat to the arduino, Intended to be send by systemd unit and timer" << std::endl << " -i --info Queries the Arduino Watchdog for status, like time before time-out" << std::endl << " -v --version Print's the version" << std::endl ; return 0; } else if (strcmp(arg, "--init") == 0) { if (getuid() != 0) { std::cerr << "Initialization requires root!" << std::endl; return -1; } std::cout << "Initialization :)" << std::endl; } else if (strcmp(arg, "--heartbeat") == 0 || shortHand(arg, 'b')) { // TODO: Send heartbeat } else if (strcmp(arg, "--info") == 0 || shortHand(arg, 'i')) { // TODO: Send info // TODO: Print response status } else if (strcmp(arg, "--version") == 0 || shortHand(arg, 'v')) { std::cout << VERSION << " by Zacharias (c) 2025" << std::endl; } else { std::cerr << "Unknown option '" << arg << "'" << std::endl << "Test '" << argv[0] << " --help'" << std::endl; return -1; } } } else { std::cerr << "Missing arguments, try " << argv[0] << " --help" << std::endl; return -1; } return -1; } bool shortHand(const char* str, char shortHand) { if (str == nullptr) return false; if (shortHand == 0) return false; return startWith(str, '-') && contains(str, shortHand); }