|
126 | 126 | //! ```
|
127 | 127 | //!
|
128 | 128 | //! ### Abstraction without overhead
|
| 129 | +//! |
129 | 130 | //! Since all the macros' lexical analysis and syntactic analysis happen at compile time, it can
|
130 | 131 | //! basically generate code the same as calling `std::process` APIs manually. It also includes
|
131 | 132 | //! command type checking, so most of the errors can be found at compile time instead of at
|
132 |
| -//! runtime. |
| 133 | +//! runtime. With tools like `rust-analyzer`, it can give you real-time feedback for broken |
| 134 | +//! commands being used. |
| 135 | +//! |
| 136 | +//! You can use `cargo expand` to check the generated code. |
133 | 137 | //!
|
134 | 138 | //! ### Intuitive parameters passing
|
135 | 139 | //! When passing parameters to `run_cmd!` and `run_fun!` macros, if they are not part to rust
|
|
177 | 181 | //! Right now piping and stdin, stdout, stderr redirection are supported. Most parts are the same as in
|
178 | 182 | //! [bash scripts](https://www.gnu.org/software/bash/manual/html_node/Redirections.html#Redirections).
|
179 | 183 | //!
|
| 184 | +//! ### logging |
| 185 | +//! |
| 186 | +//! This library provides convenient macros and builtin commands for logging. It also automatically logs |
| 187 | +//! command execution failures, along with messages which were printed to stderr originally. |
| 188 | +//! |
| 189 | +//! ```no_run |
| 190 | +//! # use cmd_lib::*; |
| 191 | +//! let dir: &str = "folder with spaces"; |
| 192 | +//! assert!(run_cmd!(mkdir /tmp/$dir; ls /tmp/$dir).is_ok()); |
| 193 | +//! assert!(run_cmd!(mkdir /tmp/"$dir"; ls /tmp/"$dir"; rmdir /tmp/"$dir").is_err()); |
| 194 | +//! // output: |
| 195 | +//! // INFO - mkdir: cannot create directory ‘/tmp/folder with spaces’: File exists |
| 196 | +//! // ERROR - Running ["mkdir", "/tmp/folder with spaces"] failed, Error: ["mkdir", "/tmp/folder with spaces"] exited with error; status code: 1 |
| 197 | +//! ``` |
| 198 | +//! |
| 199 | +//! It is using rust [log crate](https://crates.io/crates/log), and you can use your actual favorite logging |
| 200 | +//! implementation. |
| 201 | +//! |
180 | 202 | //! ### Builtin commands
|
181 | 203 | //! #### cd
|
182 | 204 | //! cd: set process current directory, which is always enabled
|
@@ -302,7 +324,9 @@ pub use cmd_lib_macros::{
|
302 | 324 | cmd_debug, cmd_die, cmd_echo, cmd_error, cmd_info, cmd_trace, cmd_warn, export_cmd, run_cmd,
|
303 | 325 | run_fun, spawn, spawn_with_output, use_builtin_cmd, use_custom_cmd,
|
304 | 326 | };
|
| 327 | +/// Return type for run_fun!() macro |
305 | 328 | pub type FunResult = std::io::Result<String>;
|
| 329 | +/// Return type for run_cmd!() macro |
306 | 330 | pub type CmdResult = std::io::Result<()>;
|
307 | 331 | pub use builtins::{
|
308 | 332 | builtin_cat, builtin_debug, builtin_die, builtin_echo, builtin_error, builtin_info,
|
|
0 commit comments