Skip to content

Commit

Permalink
environment fix, arguments escape with quaotas
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskorobicyn committed Apr 10, 2017
1 parent dff0171 commit 6218736
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/dip.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace dip {
void _compose();
void _dnsdock();
void _ssh();


void _load_config();
Code _command_code(std::string);
Expand All @@ -37,7 +38,7 @@ namespace dip {

void execute();


void merge_env(std::string key, std::string value);
std::string dig(std::vector<std::string> keys, std::string prefix);

};
Expand Down
1 change: 1 addition & 0 deletions include/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
Expand Down
6 changes: 4 additions & 2 deletions src/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion src/commands/compose.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "commands/compose.h"
#include "dip.h"
#include <string>
#include <iostream>

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());
}

Expand Down
13 changes: 12 additions & 1 deletion src/commands/service.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "commands/service.h"
#include "commands/compose.h"
#include "dip.h"
#include "arguments.h"
#include <iostream>
Expand Down Expand Up @@ -46,7 +47,17 @@ void dip::Service::run(std::string name, std::shared_ptr<Arguments> 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<std::string>(), it->second.as<std::string>());
}

}
}

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);
}
4 changes: 4 additions & 0 deletions src/dip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ std::string dip::Dip::dig(std::vector<std::string> 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];
Expand Down
5 changes: 5 additions & 0 deletions src/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

0 comments on commit 6218736

Please sign in to comment.