Version 0.0.2 added the variable env in json.

This commit is contained in:
unrealdragon 2026-05-20 20:41:38 +05:30
commit 709b7fd7ca

View file

@ -87,7 +87,7 @@ void printHelp() {
}
void printVersion() {
std::cout << "StartUpRunner: Version-0.0.1 Pre-Alpha Pre-BigBang Era Edition." << std::endl;
std::cout << "StartUpRunner: Version-0.0.2 Pre-Alpha Pre-BigBang Era Edition." << std::endl;
}
void printDefaults() {
@ -106,9 +106,18 @@ void printJsonHelp() {
std::cout << "\t[REQUIRED] app_name[string] : Path to the program with its name." << std::endl;
std::cout << "\t[OPTIONAL] app_args[list[string]] : List of arguments to the program." << std::endl;
std::cout << "\t[REQUIRED] run_mode[string] : Mode can be daemon or script." << std::endl;
std::cout << "\t\tMode daemon: The app forks the program and exits without waiting." << std::endl;
std::cout << "\t\tMode script: The app forks the program and waits for it to finish execution." << std::endl;
std::cout << "\t\tMode script: If no run_mode is given it is presumed to be script." << std::endl;
std::cout << "\t\tMode daemon : The app forks the program and exits without waiting." << std::endl;
std::cout << "\t\tMode script : The app forks the program and waits for it to finish execution." << std::endl;
std::cout << "\t\tMode script : If no run_mode is given it is presumed to be script." << std::endl;
std::cout << "\t[OPTIONAL] after[{name,state}] : List containing names and state of modules." << std::endl;
std::cout << "\t\tname[string] : Name of the other module." << std::endl;
std::cout << "\t\tstate[string]: State of the other module." << std::endl;
std::cout << "\t\t\t\tState exited : Specified module must have finished execution." << std::endl;
std::cout << "\t\t\t\tState running : Specified module must be running." << std::endl;
std::cout << "\t\tThis module will be launched after the module found\n\t\t"
"in this list using name is at the state specified as state." << std::endl;
std::cout << "\t[OPTIONAL] env{} : Additional enviroment variables" << std::endl;
std::cout << "\t\tEvery key in this object will be used as environment name\n\t\t, and every corresponding value as its value" << std::endl;
std::cout << "\t[OPTIONAL] working_dir[string] : Working directory of the program." << std::endl;
std::cout << "\t[OPTIONAL] create_log[boolean] : Create a log file at logs path." << std::endl;
std::cout << std::endl << "Example startup_apps.json: ";
@ -128,7 +137,8 @@ void printJsonHelp() {
"app_args": ["-l"],
"run_mode": "script",
"create_log": true,
"after": [{"module": "LS 0", "state": "exited"}]
"after": [{"module": "LS 0", "state": "exited"}],
"env": {"PATH": "/home/:/usr/bin/", "NAME": "ONE"}
"working_dir": "/home/etc"
}
]
@ -476,6 +486,7 @@ int main(int argc, char *argv[]) {
}
}
std::unordered_map<std::string, std::string> after_list;
std::unordered_map<std::string, std::string> env_list;
if(object.find("after") != object.end()) {
for(const auto &k: object["after"].get<json>()) {
auto l = k.get<json>();
@ -484,11 +495,18 @@ int main(int argc, char *argv[]) {
after_list[key] = value;
}
}
if(object.find("env") != object.end()) {
json k = object["env"].get<json>();
for (auto &it: k.items()) {
env_list[it.key()] = it.value();
}
}
app_info.args = arg_list;
if(object.find("working_dir") != object.end())
app_info.working_dir = object["working_dir"].get<std::string>();
if(object.find("create_log") != object.end())
app_info.create_log = object["create_log"].get<bool>();
app_info.env = env_list;
app_info.after = after_list;
app_info.module_name = object["name"].get<std::string>();
app_info.run_mode = object["run_mode"].get<std::string>();