aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-09-13 23:22:09 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-09-13 23:31:04 +0200
commit4ed66735b67b785efad7e23599a1777343c264b5 (patch)
tree956b94aa16a8a2d6da9bf659ccb848bedfd610b7 /src/libutil
parentc3e9acd1c0e2e31a35d68a70749c980e5c027175 (diff)
RunOptions: Use designated initializers
Also get rid of _killStderr because it wasn't actually checked anywhere.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.cc12
-rw-r--r--src/libutil/util.hh14
2 files changed, 6 insertions, 20 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index 72405ac83..d2660a5d3 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -1034,17 +1034,10 @@ std::vector<char *> stringsToCharPtrs(const Strings & ss)
return res;
}
-// Output = "standard out" output stream
string runProgram(Path program, bool searchPath, const Strings & args,
const std::optional<std::string> & input)
{
- RunOptions opts(program, args);
- opts.searchPath = searchPath;
- // This allows you to refer to a program with a pathname relative to the
- // PATH variable.
- opts.input = input;
-
- auto res = runProgram(opts);
+ auto res = runProgram({.program = program, .searchPath = searchPath, .args = args, .input = input});
if (!statusOk(res.first))
throw ExecError(res.first, fmt("program '%1%' %2%", program, statusToString(res.first)));
@@ -1053,9 +1046,8 @@ string runProgram(Path program, bool searchPath, const Strings & args,
}
// Output = error code + "standard out" output stream
-std::pair<int, std::string> runProgram(const RunOptions & options_)
+std::pair<int, std::string> runProgram(RunOptions && options)
{
- RunOptions options(options_);
StringSink sink;
options.standardOut = &sink;
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index a8dd4bd47..bee77b53f 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -276,26 +276,20 @@ string runProgram(Path program, bool searchPath = false,
struct RunOptions
{
+ Path program;
+ bool searchPath = true;
+ Strings args;
std::optional<uid_t> uid;
std::optional<uid_t> gid;
std::optional<Path> chdir;
std::optional<std::map<std::string, std::string>> environment;
- Path program;
- bool searchPath = true;
- Strings args;
std::optional<std::string> input;
Source * standardIn = nullptr;
Sink * standardOut = nullptr;
bool mergeStderrToStdout = false;
- bool _killStderr = false;
-
- RunOptions(const Path & program, const Strings & args)
- : program(program), args(args) { };
-
- RunOptions & killStderr(bool v) { _killStderr = true; return *this; }
};
-std::pair<int, std::string> runProgram(const RunOptions & options);
+std::pair<int, std::string> runProgram(RunOptions && options);
void runProgram2(const RunOptions & options);