@@ -33,11 +33,11 @@ if run_cmd! {
33
33
## run_fun! --> FunResult
34
34
``` rust
35
35
let version = run_fun! (" rustc --version" )? ;
36
- info! (" Your rust version is {}" , version . trim () );
36
+ info! (" Your rust version is {}" , version );
37
37
38
38
// with pipes
39
39
let n = run_fun! (" echo the quick brown fox jumped over the lazy dog | wc -w" )? ;
40
- info! (" There are {} words in above sentence" , n . trim () );
40
+ info! (" There are {} words in above sentence" , n );
41
41
```
42
42
43
43
## Run pipe commands in the builder style
@@ -105,7 +105,7 @@ FATAL: Command exit unexpectedly: disk is full
105
105
## Complete Example
106
106
107
107
``` rust
108
- use cmd_lib :: {info, warn, output, run_cmd, run_fun, CmdResult , FunResult };
108
+ use cmd_lib :: {info, warn, run_cmd, run_fun, CmdResult , FunResult };
109
109
110
110
fn foo () -> CmdResult {
111
111
let dir = " /var/tmp" ;
@@ -120,16 +120,18 @@ fn foo() -> CmdResult {
120
120
}
121
121
122
122
fn get_year () -> FunResult {
123
- let year = run_fun! (" date +%Y" )? ;
124
- output! (" {}" , year . trim ())
123
+ run_fun! (" date +%Y" )
125
124
}
126
125
127
126
fn main () -> CmdResult {
127
+ run_cmd! (lcd / tmp ; ls | wc - l ;)? ;
128
+ run_cmd! (" pwd" )? ;
129
+
128
130
let name = " rust" ;
129
131
run_cmd! (" echo hello, {}" , name )? ;
130
132
131
133
let result = run_fun! (" du -ah . | sort -hr | head -n 5" )? ;
132
- info! (" Top 5 directories:\ n {}" , result . trim () );
134
+ info! (" Top 5 directories:\ n {}" , result );
133
135
134
136
if foo (). is_err () {
135
137
warn! (" Failed to run foo()" );
@@ -147,14 +149,21 @@ fn main() -> CmdResult {
147
149
148
150
output:
149
151
``` bash
152
+ INFO: Set local current_dir: " /tmp"
153
+ INFO: Running " ls | wc -l (cd: /tmp)" ...
154
+ 42
155
+ INFO: Running " pwd" ...
156
+ /home/tao/src/rust-shell-script/rust_cmd_lib
150
157
INFO: Running " echo hello, rust" ...
151
158
hello, rust
152
159
INFO: Running " du -ah . | sort -hr | head -n 5" ...
153
160
INFO: Top 5 directories:
154
- 24K .
155
- 16K ./lib.rs
156
- 4.0K ./main.rs
157
- INFO: Set process current_dir: " /var/tmp"
161
+ 488M .
162
+ 485M ./target
163
+ 286M ./target/debug
164
+ 170M ./target/debug/incremental
165
+ 163M ./target/package
166
+ INFO: Set env current_dir: " /var/tmp"
158
167
INFO: Running " sleep 3" ...
159
168
INFO: Running " ls nofile" ...
160
169
ls: cannot access ' nofile' : No such file or directory
0 commit comments