|
236 | 236 | //! |
237 | 237 | //! #### error, warn, info, debug, trace |
238 | 238 | //! |
239 | | -//! Print messages to logging with different logging levels. |
| 239 | +//! Print messages to logging with different levels. You can also use the normal logging macros, |
| 240 | +//! if you don't need to do logging inside the command group. |
240 | 241 | //! |
241 | 242 | //! ```no_run |
242 | 243 | //! # use cmd_lib::*; |
243 | 244 | //! run_cmd!(error "This is an error message")?; |
244 | 245 | //! run_cmd!(warn "This is a warning message")?; |
245 | | -//! run_cmd!(info "This is an infomation message")?; |
| 246 | +//! run_cmd!(info "This is an information message")?; |
246 | 247 | //! // output: |
247 | 248 | //! // [ERROR] This is an error message |
248 | 249 | //! // [WARN ] This is a warning message |
249 | | -//! // [INFO ] This is an infomation message |
| 250 | +//! // [INFO ] This is an information message |
250 | 251 | //! # Ok::<(), std::io::Error>(()) |
251 | 252 | //! ``` |
252 | 253 | //! |
253 | | -//! ### Macros to register your own commands |
254 | | -//! Declare your function with the right signature, and register it with [`use_custom_cmd!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.use_custom_cmd.html) macro: |
255 | | -//! |
256 | | -//! ``` |
257 | | -//! # use cmd_lib::*; |
258 | | -//! # use std::io::Write; |
259 | | -//! fn my_cmd(env: &mut CmdEnv) -> CmdResult { |
260 | | -//! let msg = format!("msg from foo(), args: {:?}", env.args()); |
261 | | -//! writeln!(env.stderr(), "{}", msg)?; |
262 | | -//! writeln!(env.stdout(), "bar") |
263 | | -//! } |
264 | | -//! |
265 | | -//! use_custom_cmd!(my_cmd); |
266 | | -//! run_cmd!(my_cmd)?; |
267 | | -//! println!("get result: {}", run_fun!(my_cmd)?); |
268 | | -//! # Ok::<(), std::io::Error>(()) |
269 | | -//! ``` |
270 | 254 | //! ### Low-level process spawning macros |
271 | 255 | //! |
272 | 256 | //! [`spawn!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.spawn.html) macro executes the whole command as a child process, returning a handle to it. By |
|
275 | 259 | //! for the process to finish. |
276 | 260 | //! |
277 | 261 | //! With [`spawn_with_output!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.spawn_with_output.html) you can get output by calling |
278 | | -//! [`wait_with_output()`](https://docs.rs/cmd_lib/latest/cmd_lib/struct.FunChildren.html#method.wait_with_output), or even do stream |
| 262 | +//! [`wait_with_output()`](https://docs.rs/cmd_lib/latest/cmd_lib/struct.FunChildren.html#method.wait_with_output), |
| 263 | +//! [`wait_with_all()`](https://docs.rs/cmd_lib/latest/cmd_lib/struct.FunChildren.html#method.wait_with_all) |
| 264 | +//! or even do stream |
279 | 265 | //! processing with [`wait_with_pipe()`](https://docs.rs/cmd_lib/latest/cmd_lib/struct.FunChildren.html#method.wait_with_pipe). |
280 | 266 | //! |
281 | 267 | //! There are also other useful APIs, and you can check the docs for more details. |
|
304 | 290 | //! # Ok::<(), std::io::Error>(()) |
305 | 291 | //! ``` |
306 | 292 | //! |
| 293 | +//! ### Macro to register your own commands |
| 294 | +//! Declare your function with the right signature, and register it with [`use_custom_cmd!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.use_custom_cmd.html) macro: |
| 295 | +//! |
| 296 | +//! ``` |
| 297 | +//! # use cmd_lib::*; |
| 298 | +//! # use std::io::Write; |
| 299 | +//! fn my_cmd(env: &mut CmdEnv) -> CmdResult { |
| 300 | +//! let args = env.args(); |
| 301 | +//! let (res, stdout, stderr) = spawn_with_output! { |
| 302 | +//! orig_cmd $[args] |
| 303 | +//! --long-option xxx |
| 304 | +//! --another-option yyy |
| 305 | +//! }? |
| 306 | +//! .wait_with_all(); |
| 307 | +//! writeln!(env.stdout(), "{}", stdout?)?; |
| 308 | +//! writeln!(env.stderr(), "{}", stderr?)?; |
| 309 | +//! res |
| 310 | +//! } |
| 311 | +//! |
| 312 | +//! use_custom_cmd!(my_cmd); |
| 313 | +//! # Ok::<(), std::io::Error>(()) |
| 314 | +//! ``` |
307 | 315 | //! |
308 | 316 | //! ### Macros to define, get and set thread-local global variables |
309 | 317 | //! - [`tls_init!`](https://docs.rs/cmd_lib/latest/cmd_lib/macro.tls_init.html) to define thread local global variable |
|
0 commit comments