diff --git a/src/main.cpp b/src/main.cpp index 58d50f8..5b0324a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,6 +37,30 @@ void input(int argc, char *argv[]) command.runCommand(argv[1], argc, argv); } +std::string scriptBuilder(std::string script, std::string args, json script_settings) +{ + + std::string builded_script = ""; + builded_script = script; + + if (script_settings.contains("sudo") && script_settings.at("sudo").get()) + builded_script = "sudo " + script; + + if (script_settings.contains("pre_script") && script_settings.at("pre_script").size() > 0) + builded_script = script_settings.at("pre_script").get() + " && " + builded_script; + + if (script_settings.contains("args") && script_settings.at("args").size() > 0) + builded_script = builded_script + " " + script_settings.at("args").get(); + + if (script_settings.contains("background") && script_settings.at("background").get()) + builded_script = builded_script + " &"; + + std::cout + << "script: " << builded_script << std::endl; + + return builded_script; +} + // run a script with is in the autom directory void runScript(int argc, char *argv[]) { @@ -90,7 +114,8 @@ void runScript(int argc, char *argv[]) args += argv[i]; args += " "; } - std::string script = pre_script + dir + "/" + argv[1] + " " + args; + // std::string script = pre_script + dir + "/" + argv[1] + " " + args; + script = scriptBuilder(script, args, script_settings); std::cout << "executing: " << (dir + "/" + argv[1] + " " + args) << std::endl; // if (script_settings["sudo"]) @@ -99,8 +124,8 @@ void runScript(int argc, char *argv[]) // if (script_settings["background"]) // script = script + " &"; - if (script_settings["pre_script"].size() > 0) - system(script_settings["pre_script"].get().c_str()); + // if (script_settings["pre_script"].size() > 0) + // system(script_settings["pre_script"].get().c_str()); system(script.c_str()); return; diff --git a/src/main.h b/src/main.h index f4aa53e..f30cfdb 100644 --- a/src/main.h +++ b/src/main.h @@ -20,6 +20,8 @@ Command command; // input function for parsing arguments and creating commands and running them void input(int argc, char *argv[]); +// build a script +std::string scriptBuilder(std::string pre_script, std::string script_name, std::string args, json script_settings); // run a script with is in the autom directory void runScript(int argc, char *argv[]); // config function for configuring autom