From e089e56fa6e3bca5568f5cb9f1c3800d72b106ac Mon Sep 17 00:00:00 2001 From: Tao Guo Date: Fri, 20 Oct 2023 15:34:03 +0000 Subject: [PATCH] doc cleanup --- README.md | 18 +++++++++++------- macros/src/lib.rs | 6 +++--- src/lib.rs | 27 ++++++++++++++++----------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index aa10637..4dfa354 100644 --- a/README.md +++ b/README.md @@ -186,7 +186,7 @@ messages from process's stderr. #### Builtin commands ##### cd -cd: set process current directory, which can be used without importing. +cd: set process current directory. ```rust run_cmd! ( cd /tmp; @@ -202,19 +202,23 @@ working directory for the whole program. ##### ignore -Ignore errors for command execution, which can be used without importing. +Ignore errors for command execution. ##### echo -Print messages to stdout +Print messages to stdout. ##### error, warn, info, debug, trace -Print messages to logging (if provided) with different levels. +Print messages to logging with different logging levels. ```rust -run_cmd!(echo "This is from builtin command!")?; -run_cmd!(info "This is from builtin command!")?; -run_cmd!(warn "This is from builtin command!")?; +run_cmd!(error "This is an error message")?; +run_cmd!(warn "This is a warning message")?; +run_cmd!(info "This is an infomation message")?; +// output: +// [ERROR] This is an error message +// [WARN ] This is a warning message +// [INFO ] This is an infomation message ``` #### Macros to register your own commands diff --git a/macros/src/lib.rs b/macros/src/lib.rs index f6c6dab..987e224 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -2,7 +2,7 @@ use proc_macro2::{Span, TokenStream, TokenTree}; use proc_macro_error::{abort, proc_macro_error}; use quote::{quote, ToTokens}; -/// export the function as an command to be run by `run_cmd!` or `run_fun!` +/// Export the function as an command to be run by `run_cmd!` or `run_fun!` /// /// ``` /// # use cmd_lib::*; @@ -41,7 +41,7 @@ pub fn export_cmd( new_functions.into() } -/// import user registered custom command +/// Import user registered custom command /// ``` /// # use cmd_lib::*; /// #[export_cmd(my_cmd)] @@ -176,7 +176,7 @@ pub fn spawn(input: proc_macro::TokenStream) -> proc_macro::TokenStream { /// /// for (i, mut proc) in procs.into_iter().enumerate() { /// let bandwidth = proc.wait_with_output()?; -/// run_cmd!(info "thread $i bandwidth: $bandwidth MB/s")?; +/// log::info!("thread {i} bandwidth: {bandwidth} MB/s")?; /// } /// # Ok::<(), std::io::Error>(()) /// ``` diff --git a/src/lib.rs b/src/lib.rs index 83a672d..ff6e043 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -204,7 +204,7 @@ //! //! ### Builtin commands //! #### cd -//! cd: set process current directory, which can be used without importing. +//! cd: set process current directory. //! ```no_run //! # use cmd_lib::run_cmd; //! run_cmd! ( @@ -222,20 +222,24 @@ //! //! #### ignore //! -//! Ignore errors for command execution, which can be used without importing. +//! Ignore errors for command execution. //! //! #### echo -//! Print messages to stdout +//! Print messages to stdout. //! //! #### error, warn, info, debug, trace //! -//! Print messages to logging (if provided) with different levels. +//! Print messages to logging with different logging levels. //! -//! ``` +//! ```no_run //! # use cmd_lib::*; -//! run_cmd!(echo "This is from builtin command!")?; -//! run_cmd!(info "This is from builtin command!")?; -//! run_cmd!(warn "This is from builtin command!")?; +//! run_cmd!(error "This is an error message")?; +//! run_cmd!(warn "This is a warning message")?; +//! run_cmd!(info "This is an infomation message")?; +//! // output: +//! // [ERROR] This is an error message +//! // [WARN ] This is a warning message +//! // [INFO ] This is an infomation message //! # Ok::<(), std::io::Error>(()) //! ``` //! @@ -359,12 +363,13 @@ pub type CmdResult = std::io::Result<()>; pub use child::{CmdChildren, FunChildren}; #[doc(hidden)] pub use log; +#[doc(hidden)] pub use logger::try_init_default_logger; pub use main_error::MainError; pub use main_error::MainResult; -pub use process::{ - export_cmd, set_debug, set_pipefail, AsOsStr, Cmd, CmdEnv, CmdString, Cmds, GroupCmds, Redirect, -}; +#[doc(hidden)] +pub use process::{export_cmd, AsOsStr, Cmd, CmdString, Cmds, GroupCmds, Redirect}; +pub use process::{set_debug, set_pipefail, CmdEnv}; mod builtins; mod child;