feat: Add the ability to set current dir and env vars
This commit is contained in:
56
README.md
56
README.md
@@ -150,6 +150,62 @@ let command = cmd!(
|
||||
assert_eq!(format!("{command:?}"), r#""echo" "test" "2" "4" "6""#.to_string());
|
||||
```
|
||||
|
||||
### Set Current Directory
|
||||
Specify the directory to run the command.
|
||||
|
||||
```rust
|
||||
use comlexr::cmd;
|
||||
|
||||
let command = cmd!(
|
||||
cd "~/";
|
||||
"echo",
|
||||
"test",
|
||||
);
|
||||
|
||||
assert_eq!(format!("{command:?}"), r#"cd "~/" && "echo" "test""#);
|
||||
```
|
||||
|
||||
### Setting Environment Variables
|
||||
Set environment variables for the command.
|
||||
|
||||
```rust
|
||||
use comlexr::cmd;
|
||||
|
||||
const NEW_VAR: &str = "NEW_VAR";
|
||||
|
||||
let command = cmd!(
|
||||
env {
|
||||
"TEST": "test",
|
||||
NEW_VAR: "new_var"
|
||||
};
|
||||
"echo",
|
||||
"test",
|
||||
);
|
||||
|
||||
assert_eq!(format!("{command:?}"), r#"NEW_VAR="new_var" TEST="test" "echo" "test""#);
|
||||
```
|
||||
|
||||
#### Current Directory and Env Variable Order Matters
|
||||
Environment variable declarations **MUST** come after the current directory declaration.
|
||||
|
||||
```rust
|
||||
use comlexr::cmd;
|
||||
|
||||
let command = cmd!(
|
||||
cd "~/";
|
||||
env {
|
||||
"TEST": "test",
|
||||
};
|
||||
"echo",
|
||||
"test",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
format!("{command:?}"),
|
||||
r#"cd "~/" && TEST="test" "echo" "test""#
|
||||
);
|
||||
```
|
||||
|
||||
## Features
|
||||
- Conditional expressions (`if`, `if let`)
|
||||
- Iteration constructs (`for`, `for in`)
|
||||
|
||||
Reference in New Issue
Block a user