Compare commits
14 Commits
v1.3.0
...
5b9f8d32d4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b9f8d32d4 | ||
|
|
697b412a68 | ||
|
|
e0543c0d41 | ||
|
|
f5993a72ec | ||
|
|
0c02a26b5d | ||
| 720f1fd358 | |||
| 66166b47f0 | |||
| b72ca67302 | |||
| 2f5575d6ef | |||
| da51c0b41e | |||
| 0cdd0bbc07 | |||
| a5d442f7ff | |||
| ac948f193b | |||
| 2d7d6cf641 |
19
.gitlab/dependabot.yml
Normal file
19
.gitlab/dependabot.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
version: 2
|
||||
update-options:
|
||||
rebase-strategy:
|
||||
strategy: auto
|
||||
on-approval: true
|
||||
with-assignee: dependabot-wunker-bunker
|
||||
schedule:
|
||||
interval: weekly
|
||||
auto-merge: true
|
||||
approvers:
|
||||
- gmpinder
|
||||
reviewers:
|
||||
- gmpinder
|
||||
assignees:
|
||||
- dependabot-wunker-bunker
|
||||
open-pull-requests-limit: -1
|
||||
updates:
|
||||
- package-ecosystem: cargo
|
||||
directory: /
|
||||
37
CHANGELOG.md
37
CHANGELOG.md
@@ -2,12 +2,49 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [1.4.2] - 2025-05-18
|
||||
|
||||
### ⚙️ Miscellaneous Tasks
|
||||
|
||||
- Clippy fixes
|
||||
|
||||
## [1.4.1] - 2025-04-06
|
||||
|
||||
### ⚙️ Miscellaneous Tasks
|
||||
|
||||
- Upgrade deps
|
||||
- Release
|
||||
|
||||
## [1.4.0] - 2025-04-06
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- Default env variables
|
||||
|
||||
### ⚙️ Miscellaneous Tasks
|
||||
|
||||
- Release
|
||||
|
||||
## [1.3.1] - 2025-01-31
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
- Better enforce typing for commands
|
||||
|
||||
### ⚙️ Miscellaneous Tasks
|
||||
|
||||
- Release
|
||||
|
||||
## [1.3.0] - 2025-01-31
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- Pipe
|
||||
|
||||
### ⚙️ Miscellaneous Tasks
|
||||
|
||||
- Release
|
||||
|
||||
## [1.2.0] - 2025-01-14
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
119
Cargo.lock
generated
119
Cargo.lock
generated
@@ -19,9 +19,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.8.0"
|
||||
version = "2.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
|
||||
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
@@ -40,7 +40,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "comlexr"
|
||||
version = "1.3.0"
|
||||
version = "1.4.2"
|
||||
dependencies = [
|
||||
"comlexr_macro",
|
||||
"rstest",
|
||||
@@ -51,7 +51,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "comlexr_macro"
|
||||
version = "1.3.0"
|
||||
version = "1.4.2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -71,15 +71,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.10"
|
||||
version = "0.3.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d"
|
||||
checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
@@ -151,14 +151,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8"
|
||||
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"wasi",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -191,9 +191,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.7.0"
|
||||
version = "2.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f"
|
||||
checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.15.2",
|
||||
@@ -201,15 +201,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.169"
|
||||
version = "0.2.171"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||
checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.15"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"
|
||||
checksum = "fe7db12097d22ec582439daf8618b8fdd1a7bef6270e9af3b1ebcd30893cf413"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
@@ -225,9 +225,9 @@ checksum = "ab250442c86f1850815b5d268639dff018c0627022bc1940eb2d642ca1ce12f0"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.20.2"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
@@ -243,31 +243,37 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "3.2.0"
|
||||
version = "3.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b"
|
||||
checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35"
|
||||
dependencies = [
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.93"
|
||||
version = "1.0.95"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99"
|
||||
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.38"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "5.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.1"
|
||||
@@ -305,9 +311,9 @@ checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2"
|
||||
|
||||
[[package]]
|
||||
name = "rstest"
|
||||
version = "0.24.0"
|
||||
version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "03e905296805ab93e13c1ec3a03f4b6c4f35e9498a3d5fa96dc626d22c03cd89"
|
||||
checksum = "6fc39292f8613e913f7df8fa892b8944ceb47c247b78e1b1ae2f09e019be789d"
|
||||
dependencies = [
|
||||
"futures-timer",
|
||||
"futures-util",
|
||||
@@ -317,9 +323,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rstest_macros"
|
||||
version = "0.24.0"
|
||||
version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef0053bbffce09062bee4bcc499b0fbe7a57b879f1efe088d6d8d4c7adcdef9b"
|
||||
checksum = "1f168d99749d307be9de54d23fd226628d99768225ef08f6ffb52e0182a27746"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"glob",
|
||||
@@ -344,9 +350,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.44"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154"
|
||||
checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
@@ -369,24 +375,24 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.24"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba"
|
||||
checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.217"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
|
||||
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.217"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
|
||||
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -404,9 +410,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.96"
|
||||
version = "2.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80"
|
||||
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -415,11 +421,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.16.0"
|
||||
version = "3.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38c246215d7d24f48ae091a2902398798e05d978b24315d6efbc00ede9a8bb91"
|
||||
checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
@@ -429,18 +434,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.69"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.69"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -464,20 +469,20 @@ checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.22.22"
|
||||
version = "0.22.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5"
|
||||
checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474"
|
||||
dependencies = [
|
||||
"indexmap 2.7.0",
|
||||
"indexmap 2.9.0",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.14"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
@@ -487,9 +492,9 @@ checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.13.3+wasi-0.2.2"
|
||||
version = "0.14.2+wasi-0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26816d2e1a4a36a2940b96c5296ce403917633dff8f3440e9b236ed6f6bacad2"
|
||||
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
|
||||
dependencies = [
|
||||
"wit-bindgen-rt",
|
||||
]
|
||||
@@ -569,18 +574,18 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.6.24"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8d71a593cc5c42ad7876e2c1fda56f314f3754c084128833e64f1345ff8a03a"
|
||||
checksum = "0e97b544156e9bebe1a0ffbc03484fc1ffe3100cbce3ffb17eac35f7cdd7ab36"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rt"
|
||||
version = "0.33.0"
|
||||
version = "0.39.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3268f3d866458b787f390cf61f4bbb563b922d091359f9608842999eaee3943c"
|
||||
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
]
|
||||
|
||||
10
Cargo.toml
10
Cargo.toml
@@ -4,13 +4,13 @@ members = ["macro"]
|
||||
[workspace.package]
|
||||
description = "Dynamically build Command objects with conditional expressions"
|
||||
repository = "https://gitlab.com/wunker-bunker/comlexr"
|
||||
version = "1.3.0"
|
||||
version = "1.4.2"
|
||||
edition = "2021"
|
||||
rust-version = "1.60"
|
||||
license = "MIT"
|
||||
|
||||
[workspace.dependencies]
|
||||
tempfile = "3.6"
|
||||
tempfile = "3.20"
|
||||
|
||||
[workspace.lints.rust]
|
||||
unsafe_code = "forbid"
|
||||
@@ -43,11 +43,11 @@ pre-release-replacements = [
|
||||
all-features = true
|
||||
|
||||
[dependencies]
|
||||
comlexr_macro = { version = "=1.3.0", path = "./macro" }
|
||||
thiserror = "1.0.65"
|
||||
comlexr_macro = { version = "=1.4.2", path = "./macro" }
|
||||
thiserror = "2.0.12"
|
||||
|
||||
[dev-dependencies]
|
||||
rstest = "0.24"
|
||||
rstest = "0.25"
|
||||
rusty-hook = "0.11"
|
||||
|
||||
tempfile.workspace = true
|
||||
|
||||
23
README.md
23
README.md
@@ -8,7 +8,7 @@ Add `comlexr` to your project's `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
comlexr = "1.3.0"
|
||||
comlexr = "1.4.2"
|
||||
```
|
||||
|
||||
## MSRV
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -437,24 +437,50 @@ impl ToTokens for EnvVars {
|
||||
struct EnvVar {
|
||||
key: Value,
|
||||
value: Value,
|
||||
conditional: bool,
|
||||
}
|
||||
|
||||
impl Parse for EnvVar {
|
||||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
||||
let key = input.parse()?;
|
||||
|
||||
_ = input.parse::<Token![:]>()?;
|
||||
|
||||
let conditional = if input.lookahead1().peek(Token![?]) {
|
||||
input.parse::<Token![?]>()?;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
let value = input.parse()?;
|
||||
|
||||
Ok(Self { key, value })
|
||||
Ok(Self {
|
||||
key,
|
||||
value,
|
||||
conditional,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for EnvVar {
|
||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||
let Self { key, value } = self;
|
||||
let Self {
|
||||
key,
|
||||
value,
|
||||
conditional,
|
||||
} = self;
|
||||
|
||||
if *conditional {
|
||||
tokens.extend(quote! {
|
||||
if ::std::env::var(#key).ok().is_none() {
|
||||
_c.env(#key, #value);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
tokens.extend(quote! { _c.env(#key, #value); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CurrentDir(Option<Value>);
|
||||
|
||||
@@ -56,6 +56,26 @@ mod pipe;
|
||||
/// 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_macro::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 Environment Variable Order
|
||||
/// ```
|
||||
/// # use comlexr_macro::cmd;
|
||||
|
||||
@@ -6,7 +6,7 @@ use syn::{
|
||||
Error, Token,
|
||||
};
|
||||
|
||||
use crate::{cmd::Value, macros::enum_to_tokens};
|
||||
use crate::cmd::Value;
|
||||
|
||||
pub struct Pipe {
|
||||
stdin: Option<Value>,
|
||||
@@ -47,7 +47,7 @@ impl ToTokens for Pipe {
|
||||
let first_command = commands_iter.next().unwrap();
|
||||
|
||||
let initial = quote! {
|
||||
let mut _c_0 = #first_command;
|
||||
let mut _c_0: #first_command;
|
||||
_c_0.stdout(::std::process::Stdio::piped());
|
||||
_c_0.stdin(::std::process::Stdio::piped());
|
||||
let mut _child_0 = _c_0.spawn()?;
|
||||
@@ -90,12 +90,12 @@ impl ToTokens for Pipe {
|
||||
|
||||
if !_output.status.success() {
|
||||
return Err(::comlexr::ExecutorError::FailedCommand{
|
||||
command: #prev_com_ident,
|
||||
command: std::boxed::Box::new(#prev_com_ident),
|
||||
exit_code: _output.status.code().unwrap_or(1),
|
||||
});
|
||||
}
|
||||
|
||||
let mut #com_ident = #command;
|
||||
let mut #com_ident: #command;
|
||||
#com_ident.stdout(::std::process::Stdio::piped());
|
||||
#com_ident.stdin(::std::process::Stdio::piped());
|
||||
|
||||
@@ -171,4 +171,21 @@ impl Parse for CommandExpr {
|
||||
}
|
||||
}
|
||||
|
||||
enum_to_tokens! {CommandExpr: Macro, Reference, Function, Block}
|
||||
impl ToTokens for CommandExpr {
|
||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||
tokens.extend(match self {
|
||||
Self::Macro(macr) => quote! {
|
||||
::std::process::Command = #macr
|
||||
},
|
||||
Self::Reference(refer) => quote! {
|
||||
&mut ::std::process::Command = #refer
|
||||
},
|
||||
Self::Function(fun) => quote! {
|
||||
::std::process::Command = #fun
|
||||
},
|
||||
Self::Block(block) => quote! {
|
||||
::std::process::Command = #block
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,10 @@ pub enum ExecutorError {
|
||||
.collect::<Vec<_>>()
|
||||
.join(" "),
|
||||
)]
|
||||
FailedCommand { command: Command, exit_code: i32 },
|
||||
FailedCommand {
|
||||
command: Box<Command>,
|
||||
exit_code: i32,
|
||||
},
|
||||
|
||||
/// No stdin Error
|
||||
#[error("Unable to get mutable stdin")]
|
||||
|
||||
33
tests/cmd.rs
33
tests/cmd.rs
@@ -1,6 +1,8 @@
|
||||
extern crate comlexr;
|
||||
extern crate rstest;
|
||||
|
||||
use std::env;
|
||||
|
||||
use comlexr::cmd;
|
||||
use rstest::rstest;
|
||||
|
||||
@@ -35,6 +37,37 @@ fn env_vars() {
|
||||
assert_eq!(format!("{command:?}"), r#"TEST="test" "echo" "test""#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn conditional_env_vars() {
|
||||
env::set_var("TEST", "realvalue");
|
||||
env::set_var("TEST2", "won't see");
|
||||
|
||||
let command = cmd!(
|
||||
env {
|
||||
"TEST":? "test",
|
||||
"TEST2": "test2"
|
||||
};
|
||||
"echo",
|
||||
"test",
|
||||
);
|
||||
|
||||
assert_eq!(format!("{command:?}"), r#"TEST2="test2" "echo" "test""#);
|
||||
|
||||
let command = cmd!(
|
||||
env {
|
||||
"TEST": "test",
|
||||
"TEST2": "test2"
|
||||
};
|
||||
"echo",
|
||||
"test",
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
format!("{command:?}"),
|
||||
r#"TEST="test" TEST2="test2" "echo" "test""#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cd_env_vars() {
|
||||
let command = cmd!(
|
||||
|
||||
Reference in New Issue
Block a user