diff --git a/include/dip.h b/include/dip.h index 6bebeb7..8ab88a4 100644 --- a/include/dip.h +++ b/include/dip.h @@ -27,6 +27,7 @@ namespace dip { void _compose(); void _dnsdock(); void _ssh(); + void _load_config(); Code _command_code(std::string); @@ -37,7 +38,7 @@ namespace dip { void execute(); - + void merge_env(std::string key, std::string value); std::string dig(std::vector keys, std::string prefix); }; diff --git a/include/environment.h b/include/environment.h index efe08ee..b581b40 100644 --- a/include/environment.h +++ b/include/environment.h @@ -12,6 +12,7 @@ namespace dip { Environment(YAML::Node*, char**); std::string replace(std::string); + void set(std::string, std::string); std::string operator[](std::string); }; } diff --git a/src/arguments.cpp b/src/arguments.cpp index 9776bce..1051006 100644 --- a/src/arguments.cpp +++ b/src/arguments.cpp @@ -78,8 +78,10 @@ std::string dip::Arguments::params(int index) const { std::string res = ""; for (int i = index; i < _splited_params.size(); ++i) { - res += _splited_params[i]; - res += " "; + if (!_splited_params[i].empty()) { + res += "\"" + _splited_params[i] + "\""; + res += " "; + } } return res; } diff --git a/src/commands/compose.cpp b/src/commands/compose.cpp index 2f674d9..98fdd27 100644 --- a/src/commands/compose.cpp +++ b/src/commands/compose.cpp @@ -1,10 +1,14 @@ #include "commands/compose.h" #include "dip.h" #include +#include void dip::Compose::run(std::string params) { - std::string command = "docker-compose " + _files() + " " + _project_name() + " " + params; + std::string command = "docker-compose " + _files() + " " + _project_name(); + if (!params.empty()) { + command += " " + params; + } system(command.c_str()); } diff --git a/src/commands/service.cpp b/src/commands/service.cpp index 070c07a..2fa14f8 100644 --- a/src/commands/service.cpp +++ b/src/commands/service.cpp @@ -1,4 +1,5 @@ #include "commands/service.h" +#include "commands/compose.h" #include "dip.h" #include "arguments.h" #include @@ -46,7 +47,17 @@ void dip::Service::run(std::string name, std::shared_ptr args) } service_args = args->params(); } + + YAML::Node environment = service_node["environment"]; + if (environment.IsMap()) { + for (YAML::const_iterator it = environment.begin(); it != environment.end(); ++it) { + _dip->merge_env(it->first.as(), it->second.as()); + } + + } } - system((std::string("dip compose run --rm ") + service_name + " " + service_command + " " + service_args).c_str()); + std::string command = std::string("run --rm ") + service_name + " " + service_command + " " + service_args; + dip::Compose compose(this->_dip); + compose.run(command); } \ No newline at end of file diff --git a/src/dip.cpp b/src/dip.cpp index 60b54d7..446c45d 100644 --- a/src/dip.cpp +++ b/src/dip.cpp @@ -184,6 +184,10 @@ std::string dip::Dip::dig(std::vector keys, std::string prefix) }; } +void dip::Dip::merge_env(std::string key, std::string value) { + _env->set(key, value); +} + YAML::Node dip::Dip::operator[](std::string key) { return _root[key]; diff --git a/src/environment.cpp b/src/environment.cpp index cfb256e..69b7d79 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -35,4 +35,9 @@ std::string dip::Environment::replace(std::string value) std::string dip::Environment::operator[](std::string key) { return _env[key]; +} + +void dip::Environment::set(std::string key, std::string value) { + _env[key] = value; + _putenv((key + "=" + value).c_str()); } \ No newline at end of file