Util: Add additional System operator support
This commit is contained in:
+55
-2
@@ -77,9 +77,58 @@ System System::operator()(const std::vector<std::string_view>& arguments)
|
|||||||
return System(stringArguments);
|
return System(stringArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shell equivalent ;
|
||||||
|
System System::operator+(System rhs)
|
||||||
|
{
|
||||||
|
auto lhs = *this;
|
||||||
|
|
||||||
|
lhs.exec();
|
||||||
|
rhs.m_output.append(lhs.m_output);
|
||||||
|
rhs.m_error.append(lhs.m_error);
|
||||||
|
rhs.exec();
|
||||||
|
|
||||||
|
return rhs;
|
||||||
|
}
|
||||||
|
|
||||||
System System::operator|(System rhs)
|
System System::operator|(System rhs)
|
||||||
{
|
{
|
||||||
rhs.exec(exec().output());
|
auto lhs = *this;
|
||||||
|
|
||||||
|
lhs.exec();
|
||||||
|
rhs.exec(lhs.m_output);
|
||||||
|
|
||||||
|
return rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
System System::operator||(System rhs)
|
||||||
|
{
|
||||||
|
auto lhs = *this;
|
||||||
|
|
||||||
|
lhs.exec();
|
||||||
|
if (lhs.m_status == 0) {
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
rhs.m_output.append(lhs.m_output);
|
||||||
|
rhs.m_error.append(lhs.m_error);
|
||||||
|
rhs.exec();
|
||||||
|
|
||||||
|
return rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
System System::operator&&(System rhs)
|
||||||
|
{
|
||||||
|
auto lhs = *this;
|
||||||
|
|
||||||
|
lhs.exec();
|
||||||
|
if (lhs.m_status > 0) {
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
rhs.m_output.append(lhs.m_output);
|
||||||
|
rhs.m_error.append(lhs.m_error);
|
||||||
|
rhs.exec();
|
||||||
|
|
||||||
return rhs;
|
return rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,6 +152,10 @@ void System::print(const std::vector<std::string>& arguments)
|
|||||||
|
|
||||||
System System::exec(std::string input)
|
System System::exec(std::string input)
|
||||||
{
|
{
|
||||||
|
if (m_arguments.empty()) {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
int stdinFd[2];
|
int stdinFd[2];
|
||||||
int stdoutFd[2];
|
int stdoutFd[2];
|
||||||
int stderrFd[2];
|
int stderrFd[2];
|
||||||
@@ -146,6 +199,7 @@ System System::exec(std::string input)
|
|||||||
}
|
}
|
||||||
// Parent
|
// Parent
|
||||||
default:
|
default:
|
||||||
|
m_arguments.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +224,6 @@ System System::exec(std::string input)
|
|||||||
void System::readFromFileDescriptor(int fileDescriptor[2], std::string& output)
|
void System::readFromFileDescriptor(int fileDescriptor[2], std::string& output)
|
||||||
{
|
{
|
||||||
close(fileDescriptor[WriteFileDescriptor]);
|
close(fileDescriptor[WriteFileDescriptor]);
|
||||||
output.clear();
|
|
||||||
|
|
||||||
constexpr int bufferSize = 4096;
|
constexpr int bufferSize = 4096;
|
||||||
char buffer[bufferSize];
|
char buffer[bufferSize];
|
||||||
|
|||||||
@@ -30,7 +30,10 @@ public:
|
|||||||
System operator()(const std::vector<std::string>& arguments);
|
System operator()(const std::vector<std::string>& arguments);
|
||||||
System operator()(const std::vector<std::string_view>& arguments);
|
System operator()(const std::vector<std::string_view>& arguments);
|
||||||
|
|
||||||
|
System operator+(System rhs);
|
||||||
System operator|(System rhs);
|
System operator|(System rhs);
|
||||||
|
System operator||(System rhs);
|
||||||
|
System operator&&(System rhs);
|
||||||
|
|
||||||
void print(const std::vector<std::string>& arguments);
|
void print(const std::vector<std::string>& arguments);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user