/**
* sci - a simple ci system
Copyright (C) 2024 Asger Gitz-Johansen
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include "cli.h"
#include
#include
#include
#include
cli_options new_options() {
cli_options result;
char* config_file = getenv("SCI_CONFIG_FILE");
result.config_file.has_value = config_file != NULL;
result.config_file.value = config_file;
result.executors = 32;
char* verbosity_env = getenv("SCI_VERBOSITY");
int verbosity = 1;
if(verbosity_env != NULL)
verbosity = atoi(verbosity_env);
result.verbosity = verbosity;
result.help = false;
result.version = false;
char* no_color = getenv("NO_COLOR");
bool color = true;
if(no_color != NULL && no_color[0] != '\0')
color = false;
result.use_colors = color;
char* log_file = getenv("SCI_LOG_file");
result.log_file.has_value = log_file != NULL;
result.log_file.value = log_file;
char* pipeline_log_dir = getenv("SCI_PIPELINE_LOG_DIR");
result.pipeline_log_dir.has_value = pipeline_log_dir != NULL;
result.pipeline_log_dir.value = pipeline_log_dir;
char* pipeline_cwd = getenv("SCI_PIPELINE_CWD");
result.pipeline_cwd.has_value = pipeline_cwd != NULL;
result.pipeline_cwd.value = pipeline_cwd;
char* environment_vars = getenv("SCI_PIPELINE_ENV_VARS");
if(environment_vars == NULL) {
result.environment_vars.has_value = false;
result.environment_vars.value = NULL;
} else {
char* tok = strtok(environment_vars, ";");
result.environment_vars.has_value = true;
result.environment_vars.value = create_strlist_node(tok);
tok = strtok(NULL, ";");
while(tok != NULL)
add_str(tok, result.environment_vars.value);
}
return result;
}
void destroy_options(cli_options v) {
if(v.config_file.has_value)
free(v.config_file.value);
if(v.log_file.has_value)
free(v.log_file.value);
if(v.pipeline_log_dir.has_value)
free(v.pipeline_log_dir.value);
if(v.environment_vars.has_value)
clear_strlist(v.environment_vars.value);
}
//