feat: Default env variables

This commit is contained in:
2025-04-06 14:21:17 -04:00
parent ac948f193b
commit a5d442f7ff
4 changed files with 103 additions and 3 deletions

View File

@@ -185,6 +185,27 @@ let command = cmd!(
assert_eq!(format!("{command:?}"), r#"NEW_VAR="new_var" TEST="test" "echo" "test""#);
```
#### Conditional
You can have a default value set for an environment variable.
```rust
use comlexr::cmd;
const NEW_VAR: &str = "NEW_VAR";
std::env::set_var("TEST", "realvalue");
let command = cmd!(
env {
"TEST":? "test",
NEW_VAR: "new_var"
};
"echo",
"test",
);
assert_eq!(format!("{command:?}"), r#"NEW_VAR="new_var" "echo" "test""#);
```
#### Current Directory and Env Variable Order Matters
Environment variable declarations **MUST** come after the current directory declaration.