The templated pipeProcessImpl only contains a single unshared line of code [1]. It might be worthwhile to reduce the amount of duplication by using delegates instead of alias parameters.

pipeProcess
{
    return pipeProcessImpl(
        (SpawnFuncArgs args) => spawnProcess(program, args),
        redirectFlags, env, config);
}

pipeShell
{
    return pipeProcessImpl(
        (SpawnFuncArgs args) => spawnShell(command, args),
        redirectFlags, env, config);
}

private alias TypeTuple!(File, File, File, const string[string], Config) SpawnFuncArgs;

private ProcessPipes pipeProcessImpl(scope Pid delegate(SpawnFuncArgs) spawnFunc,
                                     Redirect redirectFlags,
                                     const string[string] env = null,
                                     Config config = Config.none)
{
    // ... shared code
auto pid = spawnFunc(childStdin, childStdout, childStderr, env, config);
}

[1]: https://github.com/kyllingstad/phobos/blob/994437169f20907f30515cfef54538710f3fc1fe/std/process.d#L1636

Reply via email to