@@ -8,6 +8,9 @@ pub type CmdResult = Result<()>;
8
8
9
9
/// To print warning information to stderr, no return value
10
10
/// ```rust
11
+ /// #[macro_use]
12
+ /// use cmd_lib::info;
13
+ ///
11
14
/// info!("Running command xxx ...");
12
15
/// ```
13
16
#[ macro_export]
@@ -19,6 +22,9 @@ macro_rules! info {
19
22
20
23
/// To print warning information to stderr, no return value
21
24
/// ```rust
25
+ /// #[macro_use]
26
+ /// use cmd_lib::warn;
27
+ ///
22
28
/// warn!("Running command failed");
23
29
/// ```
24
30
#[ macro_export]
@@ -30,6 +36,9 @@ macro_rules! warn {
30
36
31
37
/// To print error information to stderr, no return value
32
38
/// ```rust
39
+ /// #[macro_use]
40
+ /// use cmd_lib::err;
41
+ ///
33
42
/// err!("Copying file failed");
34
43
/// ```
35
44
#[ macro_export]
@@ -40,7 +49,11 @@ macro_rules! err {
40
49
}
41
50
42
51
/// 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";
44
57
/// die!("command failed: {}", reason);
45
58
/// ```
46
59
#[ macro_export]
@@ -53,7 +66,7 @@ macro_rules! die {
53
66
}
54
67
55
68
/// To return FunResult
56
- /// ```rust
69
+ /// ```compile_fail
57
70
/// fn foo() -> FunResult
58
71
/// ...
59
72
/// output!("yes");
@@ -139,16 +152,18 @@ macro_rules! macro_str {
139
152
}
140
153
141
154
/// ## 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);
145
160
///
146
161
/// // 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);
149
164
///
150
165
/// // 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);
152
167
/// ```
153
168
#[ macro_export]
154
169
macro_rules! run_fun {
@@ -163,6 +178,9 @@ macro_rules! run_fun {
163
178
///
164
179
/// ## run_cmd! --> CmdResult
165
180
/// ```rust
181
+ /// #[macro_use]
182
+ /// use cmd_lib::run_cmd;
183
+ ///
166
184
/// let name = "rust";
167
185
/// run_cmd!("echo hello, {}", name);
168
186
///
@@ -175,11 +193,9 @@ macro_rules! run_fun {
175
193
/// // or a group of commands
176
194
/// // if any command fails, just return Err(...)
177
195
/// run_cmd!{
178
- /// use file;
179
- ///
180
196
/// date;
181
197
/// ls -l ${file};
182
- /// }
198
+ /// };
183
199
/// ```
184
200
#[ macro_export]
185
201
macro_rules! run_cmd {
@@ -214,10 +230,12 @@ pub trait ProcessResult {
214
230
///
215
231
/// Pipe command could also lauched in builder style
216
232
/// ```rust
233
+ /// use cmd_lib::{Process,CmdResult};
234
+ ///
217
235
/// Process::new("du -ah .")
218
236
/// .pipe("sort -hr")
219
237
/// .pipe("head -n 5")
220
- /// .wait::<CmdResult>()?
238
+ /// .wait::<CmdResult>();
221
239
/// ```
222
240
///
223
241
pub struct Process {
@@ -299,7 +317,6 @@ fn run_full_cmd(process: &mut Process, pipe_last: bool) -> Result<(Child, String
299
317
full_cmd_str += & format ! ( " (cd: {})" , dir) ;
300
318
cmd. current_dir ( dir) ;
301
319
}
302
- info ! ( "Running \" {}\" ..." , full_cmd_str) ;
303
320
304
321
let mut last_proc = cmd
305
322
. args ( & first_cmd[ 1 ..] )
@@ -319,6 +336,7 @@ fn run_full_cmd(process: &mut Process, pipe_last: bool) -> Result<(Child, String
319
336
Stdio :: piped ( )
320
337
} )
321
338
. spawn ( ) ?;
339
+ last_proc. wait ( ) ;
322
340
last_proc = new_proc;
323
341
}
324
342
0 commit comments