Skip to content

Commit b901784

Browse files
committed
chore: docs update
1 parent 29b28ba commit b901784

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ let dir = "/var/log";
8888
run_cmd!(du -ah $dir | sort -hr | head -n 10)?;
8989

9090
// or a group of commands
91-
// if any command fails, just return Err(...)
91+
// if any command fails, just return Err(...), which is similar to bash's `set -euo pipefail`
9292
let file = "/tmp/f";
9393
let keyword = "rust";
9494
run_cmd! {
@@ -104,7 +104,7 @@ run_cmd! {
104104
- [`run_fun!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.run_fun.html) -> [`FunResult`](https://docs.rs/cmd_lib/latest/cmd_lib/type.FunResult.html)
105105

106106
```rust
107-
let version = run_fun!(rustc --version)?;
107+
let version = run_fun!(rustc --version | awk r"{print $2}")?;
108108
eprintln!("Your rust version is {}", version);
109109

110110
// with pipes
@@ -347,5 +347,4 @@ That said, there are some limitations to be aware of:
347347
[std::env::remove_var]: https://doc.rust-lang.org/std/env/fn.remove_var.html
348348
[must not be called]: https://doc.rust-lang.org/nightly/edition-guide/rust-2024/newly-unsafe-functions.html#stdenvset_var-remove_var
349349

350-
351350
License: MIT OR Apache-2.0

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
//! run_cmd!(du -ah $dir | sort -hr | head -n 10)?;
9797
//!
9898
//! // or a group of commands
99-
//! // if any command fails, just return Err(...)
99+
//! // if any command fails, just return Err(...), which is similar to bash's `set -euo pipefail`
100100
//! let file = "/tmp/f";
101101
//! let keyword = "rust";
102102
//! run_cmd! {
@@ -114,7 +114,7 @@
114114
//!
115115
//! ```
116116
//! # use cmd_lib::run_fun;
117-
//! let version = run_fun!(rustc --version)?;
117+
//! let version = run_fun!(rustc --version | awk r"{print $2}")?;
118118
//! eprintln!("Your rust version is {}", version);
119119
//!
120120
//! // with pipes
@@ -369,11 +369,13 @@
369369
//! - [std::env::set_var] and [std::env::remove_var] **[must not be called]** in a multi-threaded program
370370
//! - [`tls_init!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.tls_init.html),
371371
//! [`tls_get!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.tls_get.html), and
372-
//! [`tls_set!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.tls_set.html) create *thread-local* variables, which
373-
//! means each thread will have its own independent version of the variable
372+
//! [`tls_set!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.tls_set.html) create *thread-local* variables, which means
373+
//! each thread will have its own independent version of the variable
374374
//! - [`set_debug`](https://docs.rs/cmd_lib/latest/cmd_lib/fn.set_debug.html) and
375375
//! [`set_pipefail`](https://docs.rs/cmd_lib/latest/cmd_lib/fn.set_pipefail.html) are *global* and affect all threads;
376-
//! there is currently no way to change those settings without affecting other threads
376+
//! to change those settings without affecting other threads, use
377+
//! [`ScopedDebug`](https://docs.rs/cmd_lib/latest/cmd_lib/struct.ScopedDebug.html) and
378+
//! [`ScopedPipefail`](https://docs.rs/cmd_lib/latest/cmd_lib/struct.ScopedPipefail.html)
377379
//!
378380
//! [std::env::set_var]: https://doc.rust-lang.org/std/env/fn.set_var.html
379381
//! [std::env::remove_var]: https://doc.rust-lang.org/std/env/fn.remove_var.html

src/process.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ static PIPEFAIL_ENABLED: LazyLock<AtomicBool> =
109109
///
110110
/// Setting environment variable CMD_LIB_DEBUG=0|1 has the same effect, but the environment variable is only
111111
/// checked once at an unspecified time, so the only reliable way to do that is when the program is first started.
112+
///
113+
/// ## Example
114+
/// ```console
115+
/// λ test_cmd_lib git:(master) ✗ cat src/main.rs
116+
/// use cmd_lib::*;
117+
///
118+
/// #[cmd_lib::main]
119+
/// fn main() -> CmdResult {
120+
/// run_cmd!(cat src/main.rs | wc -l)
121+
/// }
122+
/// λ test_cmd_lib git:(master) ✗ RUST_LOG=debug CMD_LIB_DEBUG=1 cargo r
123+
/// Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
124+
/// Running `target/debug/test_cmd_lib`
125+
/// [DEBUG] Running ["cat" "src/main.rs" | "wc" "-l"] at src/main.rs:5 ...
126+
/// 6
127+
/// ```
112128
pub fn set_debug(enable: bool) {
113129
DEBUG_ENABLED.store(enable, SeqCst);
114130
}
@@ -117,7 +133,7 @@ pub fn set_debug(enable: bool) {
117133
///
118134
/// This is **global**, and affects all threads. To set it for the current thread only, use [`ScopedPipefail`].
119135
///
120-
/// Setting environment variable CMD_LIB_DEBUG=0|1 has the same effect, but the environment variable is only
136+
/// Setting environment variable CMD_LIB_PIPEFAIL=0|1 has the same effect, but the environment variable is only
121137
/// checked once at an unspecified time, so the only reliable way to do that is when the program is first started.
122138
pub fn set_pipefail(enable: bool) {
123139
PIPEFAIL_ENABLED.store(enable, SeqCst);

0 commit comments

Comments
 (0)