#include "command_builder.h" namespace build { command_builder::command_builder(std::string const & cmd, int indent) : indent_{indent}, buffer_() { buffer_ << cmd; } template command_builder && command_builder::operator<<(T const & value) && { return std::move((*this) << value); } template command_builder & command_builder::operator<<(T const & value) & { buffer_ << ' '; write(value); return *this; } template command_builder & command_builder::operator<<(std::vector const & value) & { for (T const & v : value) { (*this) << v; } return *this; } void command_builder::write(version const & vers) { switch (vers) { case version::cxx11: buffer_ << "-std=c++11"; break; case version::cxx14: buffer_ << "-std=c++14"; break; case version::cxx17: buffer_ << "-std=c++17"; break; case none: break; } } void command_builder::write(source_file const & file) { buffer_ << "-c " << file.get(); } void command_builder::write(output_file const & file) { buffer_ << "-o " << file.get(); } std::ostream & operator<<(std::ostream & os, indent_t const & value) { for (int i = 0; i < value.value; ++i) { os << " "; } return os; } int command_builder::execute() const { std::string cmdstr = buffer_.str(); // TODO(samjaffe): Not sure this belongs here, so much as command_builder // should take a formatter object (including things like color config) std::cout << indent_ << cmdstr << std::endl; return std::system(cmdstr.c_str()); } }