Skip to content

Commit b743c97

Browse files
committed
Make docstring test pass
- Add misssing use - Add needed :? for object not implementing fmt - Add a few no_run & compile_fail when needed
1 parent d475ccd commit b743c97

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/lib.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ pub type CmdResult = Result<()>;
88

99
/// To print warning information to stderr, no return value
1010
/// ```rust
11+
/// #[macro_use]
12+
/// use cmd_lib::info;
13+
///
1114
/// info!("Running command xxx ...");
1215
/// ```
1316
#[macro_export]
@@ -19,6 +22,9 @@ macro_rules! info {
1922

2023
/// To print warning information to stderr, no return value
2124
/// ```rust
25+
/// #[macro_use]
26+
/// use cmd_lib::warn;
27+
///
2228
/// warn!("Running command failed");
2329
/// ```
2430
#[macro_export]
@@ -30,6 +36,9 @@ macro_rules! warn {
3036

3137
/// To print error information to stderr, no return value
3238
/// ```rust
39+
/// #[macro_use]
40+
/// use cmd_lib::err;
41+
///
3342
/// err!("Copying file failed");
3443
/// ```
3544
#[macro_export]
@@ -40,7 +49,11 @@ macro_rules! err {
4049
}
4150

4251
/// To print information to stderr, and exit current process with non-zero
43-
/// ```rust
52+
/// ```should_panic
53+
/// #[macro_use]
54+
/// use cmd_lib::die;
55+
///
56+
/// let reason = "system error";
4457
/// die!("command failed: {}", reason);
4558
/// ```
4659
#[macro_export]
@@ -53,7 +66,7 @@ macro_rules! die {
5366
}
5467

5568
/// To return FunResult
56-
/// ```rust
69+
/// ```compile_fail
5770
/// fn foo() -> FunResult
5871
/// ...
5972
/// output!("yes");
@@ -139,16 +152,18 @@ macro_rules! macro_str {
139152
}
140153

141154
/// ## run_fun! --> FunResult
142-
/// ```rust
143-
/// let version = run_fun!("rustc --version")?;
144-
/// info!("Your rust version is {}", version);
155+
/// ```no_run
156+
/// #[macro_use]
157+
/// use cmd_lib::{info, run_fun};
158+
/// let version = run_fun!("rustc --version");
159+
/// info!("Your rust version is {:?}", version);
145160
///
146161
/// // with pipes
147-
/// let n = run_fun!("echo the quick brown fox jumped over the lazy dog | wc -w")?;
148-
/// info!("There are {} words in above sentence", n);
162+
/// let n = run_fun!("echo the quick brown fox jumped over the lazy dog | wc -w");
163+
/// info!("There are {:?} words in above sentence", n);
149164
///
150165
/// // without string quotes
151-
/// let files = run_fun!(du -ah . | sort -hr | head -n 10)?;
166+
/// let files = run_fun!(du -ah . | sort -hr | head -n 10);
152167
/// ```
153168
#[macro_export]
154169
macro_rules! run_fun {
@@ -163,6 +178,9 @@ macro_rules! run_fun {
163178
///
164179
/// ## run_cmd! --> CmdResult
165180
/// ```rust
181+
/// #[macro_use]
182+
/// use cmd_lib::run_cmd;
183+
///
166184
/// let name = "rust";
167185
/// run_cmd!("echo hello, {}", name);
168186
///
@@ -175,11 +193,9 @@ macro_rules! run_fun {
175193
/// // or a group of commands
176194
/// // if any command fails, just return Err(...)
177195
/// run_cmd!{
178-
/// use file;
179-
///
180196
/// date;
181197
/// ls -l ${file};
182-
/// }
198+
/// };
183199
/// ```
184200
#[macro_export]
185201
macro_rules! run_cmd {
@@ -214,10 +230,12 @@ pub trait ProcessResult {
214230
///
215231
/// Pipe command could also lauched in builder style
216232
/// ```rust
233+
/// use cmd_lib::{Process,CmdResult};
234+
///
217235
/// Process::new("du -ah .")
218236
/// .pipe("sort -hr")
219237
/// .pipe("head -n 5")
220-
/// .wait::<CmdResult>()?
238+
/// .wait::<CmdResult>();
221239
/// ```
222240
///
223241
pub struct Process {

0 commit comments

Comments
 (0)