diff --git a/build.cc b/build.cc index a4dbb29..105d2cf 100644 --- a/build.cc +++ b/build.cc @@ -112,7 +112,7 @@ static void print_help(ostd::string_range arg0) { static void exec_command(strvec const &args) { ostd::process_info pi; - pi.open(nullptr, ostd::iter(args)); + pi.open_command(ostd::iter(args)); if (int ret; (ret = pi.close())) { auto app = ostd::appender(); ostd::format(app, "command failed with code %d", ret); diff --git a/ostd/process.hh b/ostd/process.hh index dd0a5f4..a0e7141 100644 --- a/ostd/process.hh +++ b/ostd/process.hh @@ -129,8 +129,31 @@ struct OSTD_EXPORT process_info { ~process_info(); + int close(); + template - void open(string_range cmd, InputRange args, bool use_path = true) { + void open_path(string_range path, InputRange &&args) { + open_full(path, std::forward(args), false); + } + + template + void open_path(InputRange &&args) { + open_path(nullptr, std::forward(args)); + } + + template + void open_command(string_range cmd, InputRange &&args) { + open_full(cmd, std::forward(args), true); + } + + template + void open_command(InputRange &&args) { + open_command(nullptr, std::forward(args)); + } + +private: + template + void open_full(string_range cmd, InputRange args, bool use_path) { static_assert( std::is_constructible_v>, "The arguments must be strings" @@ -148,9 +171,6 @@ struct OSTD_EXPORT process_info { open_impl(std::string{cmd}, argv, use_path); } - int close(); - -private: void open_impl( std::string const &cmd, std::vector const &args, bool use_path