Skip to content

Commit

Permalink
doc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-guo committed Oct 20, 2023
1 parent 0548007 commit 2283955
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.

```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
Expand Down
4 changes: 2 additions & 2 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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>(())
/// ```
Expand Down
25 changes: 15 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! (
Expand All @@ -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.
//!
//! ```
//! ```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>(())
//! ```
//!
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2283955

Please sign in to comment.