Freyskeyd / environment

6 stars 2 forks source link

Add save method #4

Closed Freyskeyd closed 1 year ago

Freyskeyd commented 6 years ago

Add a save method which accept a regex to save some variables when using the empty method.

Signed-off-by: Freyskeyd simon.paitrault@gmail.com

Freyskeyd commented 6 years ago

ping @killercup and @epage for issue killercup/assert_cli#51

killercup commented 6 years ago

If this is only for killercup/assert_cli#51, I'd rather do it like killercup/assert_cli#54. But this feature has its own merits.

I'd not call it save, though. Maybe recover?

Freyskeyd commented 6 years ago

Yeah, I think this is a feature needed outside of assert_cli.

I was divide about the name.

What do you think?

killercup commented 6 years ago

So, the starting point is an empty env, and we are copying the parent scope's env var.

Maybe inherit_var?

Am 13.10.2017 um 10:55 schrieb Simon Paitrault notifications@github.com:

Yeah, I think this is a feature needed outside of assert_cli.

I was divide about the name.

• save • recover • keep What do you think?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Freyskeyd commented 6 years ago

why not:

let env = Environment::empty()
    .inherit_vars("^CARGO_.*")
    .insert("CARGO_SOMETHING", "ok");

We can also:


let env = Environment::inherit_matches("^CARGO_*")
    .insert("CARGO_SOMETHING", "ok");
epage commented 6 years ago

I agree about inherit for the base name.

For consistency, a inherit_vars should probably take an iterator. We could do some From stuff so it assumes a string is a regex, though I tend to prefer things more explicit. I like inherit_matches for that reason

So overall, I'd like to see

Question: If clients do not need inherit_matches, should we force a regex dependency on them? Should it be a feature (default or not) so users can better control their compile times?