The new std.process is ready for review
Lars T. Kyllingstad
public at kyllingen.net
Wed Mar 13 13:43:59 PDT 2013
On Wednesday, 13 March 2013 at 20:26:44 UTC, Steven Schveighoffer
wrote:
> I hate to have feature creep at this point, but one kind of
> annoying thing
> is, if you want to *add* to the current environment, it is a
> multi-step
> process:
>
> auto curenv = environment.toAA;
> curenv["x"] = "y";
> spawnProcess("helloworld", curenv);
>
> But with something similar to Dennis' idea, we have a possible
> way to do
> that without making a copy of the current environment into an
> AA and
> adding:
>
> struct EnvironmentArg
> {
> this(string[string] env, bool useParent=false) { this.env
> = env;
> this.useParent = useParent;}
> this(bool useParent) {this.useParent = useParent;}
> string[string] env;
> bool useParent;
> }
>
> spawnProcess("helloworld", EnvironmentArg(["x":"y"], true)); //
> use parent
> environment, add x=y
> spawnProcess("helloworld", EnvironmentArg(["x":"y"])); //
> replace
> environment with x=y
> spawnProcess("helloworld", EnvironmentArg(false)); // use empty
> environment
> spawnProcess("helloworld", EnvironmentArg(true)); // use parent
> environment exactly
>
> EnvironmentArg should probably have better name, and I would
> recommend
> some global functions that make common things, like:
>
> EnvironmentArg emptyEnvironment() { return EnvironmentArg(null,
> false);}
> EnvironmentArg parentEnvironment() { return
> EnvironmentArg(null, true);}
>
> Like? Hate?
Hmm.. what if spawnProcess() takes a normal string[string] like
it does now, but we add a flag to Config that determines whether
it is merged with the parent's environment or not?
string[string] myEnv = [ "foo" : "bar" ];
spawnProcess("helloworld", null); // Parent's env
spawnProcess("helloworld", myEnv); // Parent's env + myEnv
spawnProcess("helloworld", null, ..., Config.clearEnv); // Empty
env
spawnProcess("helloworld", myEnv, ..., Config.clearEnv); // Only
myEnv
Lars
More information about the Digitalmars-d
mailing list