mirror of
https://github.com/lucaspalomodevelop/autom.git
synced 2026-03-12 23:27:21 +00:00
add scriptBuilder function to build script command with json-config options
This commit is contained in:
parent
8c7edfc55e
commit
c38ad5a890
31
src/main.cpp
31
src/main.cpp
@ -37,6 +37,30 @@ void input(int argc, char *argv[])
|
|||||||
command.runCommand(argv[1], argc, 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<bool>())
|
||||||
|
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<std::string>() + " && " + builded_script;
|
||||||
|
|
||||||
|
if (script_settings.contains("args") && script_settings.at("args").size() > 0)
|
||||||
|
builded_script = builded_script + " " + script_settings.at("args").get<std::string>();
|
||||||
|
|
||||||
|
if (script_settings.contains("background") && script_settings.at("background").get<bool>())
|
||||||
|
builded_script = builded_script + " &";
|
||||||
|
|
||||||
|
std::cout
|
||||||
|
<< "script: " << builded_script << std::endl;
|
||||||
|
|
||||||
|
return builded_script;
|
||||||
|
}
|
||||||
|
|
||||||
// run a script with is in the autom directory
|
// run a script with is in the autom directory
|
||||||
void runScript(int argc, char *argv[])
|
void runScript(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -90,7 +114,8 @@ void runScript(int argc, char *argv[])
|
|||||||
args += argv[i];
|
args += argv[i];
|
||||||
args += " ";
|
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;
|
std::cout << "executing: " << (dir + "/" + argv[1] + " " + args) << std::endl;
|
||||||
|
|
||||||
// if (script_settings["sudo"])
|
// if (script_settings["sudo"])
|
||||||
@ -99,8 +124,8 @@ void runScript(int argc, char *argv[])
|
|||||||
// if (script_settings["background"])
|
// if (script_settings["background"])
|
||||||
// script = script + " &";
|
// script = script + " &";
|
||||||
|
|
||||||
if (script_settings["pre_script"].size() > 0)
|
// if (script_settings["pre_script"].size() > 0)
|
||||||
system(script_settings["pre_script"].get<std::string>().c_str());
|
// system(script_settings["pre_script"].get<std::string>().c_str());
|
||||||
|
|
||||||
system(script.c_str());
|
system(script.c_str());
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -20,6 +20,8 @@ Command command;
|
|||||||
|
|
||||||
// input function for parsing arguments and creating commands and running them
|
// input function for parsing arguments and creating commands and running them
|
||||||
void input(int argc, char *argv[]);
|
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
|
// run a script with is in the autom directory
|
||||||
void runScript(int argc, char *argv[]);
|
void runScript(int argc, char *argv[]);
|
||||||
// config function for configuring autom
|
// config function for configuring autom
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user