v0.2.12 - Command line variables added

This commit is contained in:
Your Name
2025-09-06 07:41:43 -04:00
parent 6f51f445b7
commit 6d9b4efb7e
8 changed files with 98 additions and 21 deletions

View File

@@ -3012,13 +3012,22 @@ void print_usage(const char* program_name) {
printf("C Nostr Relay Server\n");
printf("\n");
printf("Options:\n");
printf(" -p, --port PORT Listen port (default: %d)\n", DEFAULT_PORT);
printf(" -h, --help Show this help message\n");
printf(" -p, --port PORT Listen port (default: %d)\n", DEFAULT_PORT);
printf(" -c, --config FILE Configuration file path\n");
printf(" -d, --config-dir DIR Configuration directory path\n");
printf(" -h, --help Show this help message\n");
printf("\n");
printf("Examples:\n");
printf(" %s --config /path/to/config.json\n", program_name);
printf(" %s --config-dir ~/.config/c-relay-dev\n", program_name);
printf(" %s --port 9999 --config-dir /etc/c-relay\n", program_name);
printf("\n");
}
int main(int argc, char* argv[]) {
int port = DEFAULT_PORT;
char* config_dir_override = NULL;
char* config_file_override = NULL;
// Parse command line arguments
for (int i = 1; i < argc; i++) {
@@ -3042,6 +3051,20 @@ int main(int argc, char* argv[]) {
log_error("Port argument requires a value");
return 1;
}
} else if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--config") == 0) {
if (i + 1 < argc) {
config_file_override = argv[++i];
} else {
log_error("Config file argument requires a value");
return 1;
}
} else if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--config-dir") == 0) {
if (i + 1 < argc) {
config_dir_override = argv[++i];
} else {
log_error("Config directory argument requires a value");
return 1;
}
} else {
log_error("Unknown argument");
print_usage(argv[0]);
@@ -3049,6 +3072,14 @@ int main(int argc, char* argv[]) {
}
}
// Store config overrides in global variables for configuration system access
if (config_dir_override) {
setenv("C_RELAY_CONFIG_DIR_OVERRIDE", config_dir_override, 1);
}
if (config_file_override) {
setenv("C_RELAY_CONFIG_FILE_OVERRIDE", config_file_override, 1);
}
// Set up signal handlers
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);