Skip to content

Commit 2576e1f

Browse files
Merge #60 #61 #62
60: Cleanup examples r=matthiasbeyer a=matthiasbeyer Clean the examples up. 61: Format README r=matthiasbeyer a=matthiasbeyer 62: Remove unnecessary boilerplate from doc examples r=matthiasbeyer a=matthiasbeyer Co-authored-by: Matthias Beyer <[email protected]>
4 parents d89b7ef + 49798a3 + e2cdb92 + 941581d commit 2576e1f

File tree

7 files changed

+30
-56
lines changed

7 files changed

+30
-56
lines changed

README.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,28 @@
44
[![Released API docs](https://docs.rs/rexpect/badge.svg)](https://docs.rs/rexpect)
55
[![Master API docs](https://img.shields.io/badge/docs-master-2f343b.svg)](http://philippkeller.github.io/rexpect)
66

7-
8-
Spawn, control, and respond to expected patterns of child applications and processes, enabling the automation of interactions and testing. Components include:
9-
- **session**: start a new process and interact with it; primary module of rexpect.
10-
- **reader**: non-blocking reader, which supports waiting for strings, regex, and EOF.
7+
Spawn, control, and respond to expected patterns of child applications and
8+
processes, enabling the automation of interactions and testing. Components
9+
include:
10+
11+
- **session**: start a new process and interact with it; primary module of
12+
rexpect.
13+
- **reader**: non-blocking reader, which supports waiting for strings, regex,
14+
and EOF.
1115
- **process**: spawn a process in a pty.
1216

13-
The goal is to offer a similar set of functionality as [pexpect](https://pexpect.readthedocs.io/en/stable/overview.html).
17+
The goal is to offer a similar set of functionality as
18+
[pexpect](https://pexpect.readthedocs.io/en/stable/overview.html).
1419

1520
## Maintainers wanted
1621

17-
I have created rexpect as a project to learn rust and linux. But now due to some reasons I haven't used Rust in the past 2 years, so I can't keep up with the latest features/crate dependencies
22+
I have created rexpect as a project to learn rust and linux. But now due to some
23+
reasons I haven't used Rust in the past 2 years, so I can't keep up with the
24+
latest features/crate dependencies
1825

19-
It has become hard now to judge pull requests. If you would be willing to either take over this repo entirely or join in as a maintainer to help evaluate PR please contact me.
26+
It has become hard now to judge pull requests. If you would be willing to either
27+
take over this repo entirely or join in as a maintainer to help evaluate PR
28+
please contact me.
2029

2130
## Examples
2231

@@ -55,24 +64,21 @@ fn do_ftp() -> Result<()> {
5564
Ok(())
5665
}
5766

58-
5967
fn main() {
6068
do_ftp().unwrap_or_else(|e| panic!("ftp job failed with {}", e));
6169
}
6270
```
6371

6472
### Example with bash and reading from programs
6573

66-
6774
```rust
6875
extern crate rexpect;
6976
use rexpect::spawn_bash;
7077
use rexpect::errors::*;
7178

72-
7379
fn do_bash() -> Result<()> {
7480
let mut p = spawn_bash(Some(2000))?;
75-
81+
7682
// case 1: wait until program is done
7783
p.send_line("hostname")?;
7884
let hostname = p.read_line()?;
@@ -102,7 +108,6 @@ fn do_bash() -> Result<()> {
102108
fn main() {
103109
do_bash().unwrap_or_else(|e| panic!("bash job failed with {}", e));
104110
}
105-
106111
```
107112

108113
### Example with bash and job control
@@ -122,7 +127,6 @@ extern crate rexpect;
122127
use rexpect::spawn_bash;
123128
use rexpect::errors::*;
124129

125-
126130
fn do_bash_jobcontrol() -> Result<()> {
127131
let mut p = spawn_bash(Some(1000))?;
128132
p.execute("ping 8.8.8.8", "bytes of data")?;
@@ -157,7 +161,9 @@ rust stable, beta and nightly on both Linux or Mac.
157161
## Design decisions
158162

159163
- use error handling of [error-chain](https://github.com/brson/error-chain)
160-
- use [nix](https://github.com/nix-rust/nix) (and avoid libc wherever possible) to keep the code safe and clean
161-
- sadly, `expect` is used in rust too prominently to unwrap `Option`s and `Result`s, use `exp_*` instead
164+
- use [nix](https://github.com/nix-rust/nix) (and avoid libc wherever possible)
165+
to keep the code safe and clean
166+
- sadly, `expect` is used in rust too prominently to unwrap `Option`s and
167+
`Result`s, use `exp_*` instead
162168

163169
Licensed under [MIT License](LICENSE)

examples/bash.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate rexpect;
22
use rexpect::error::Error;
33
use rexpect::spawn_bash;
44

5-
fn run() -> Result<(), Error> {
5+
fn main() -> Result<(), Error> {
66
let mut p = spawn_bash(Some(1000))?;
77
p.execute("ping 8.8.8.8", "bytes")?;
88
p.send_control('z')?;
@@ -18,7 +18,3 @@ fn run() -> Result<(), Error> {
1818
p.exp_string("packet loss")?;
1919
Ok(())
2020
}
21-
22-
fn main() {
23-
run().unwrap_or_else(|e| panic!("bash process failed with {}", e));
24-
}

examples/bash_read.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ extern crate rexpect;
22
use rexpect::error::Error;
33
use rexpect::spawn_bash;
44

5-
fn run() -> Result<(), Error> {
5+
fn main() -> Result<(), Error> {
66
let mut p = spawn_bash(Some(2000))?;
77

88
// case 1: wait until program is done
@@ -33,7 +33,3 @@ fn run() -> Result<(), Error> {
3333
p.send_control('c')?;
3434
Ok(())
3535
}
36-
37-
fn main() {
38-
run().unwrap_or_else(|e| panic!("bash process failed with {}", e));
39-
}

examples/exit_code.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rexpect::spawn;
88
/// cat exited with code 0, all good!
99
/// cat exited with code 1
1010
/// Output (stdout and stderr): cat: /this/does/not/exist: No such file or directory
11-
fn exit_code_fun() -> Result<(), Error> {
11+
fn main() -> Result<(), Error> {
1212
let p = spawn("cat /etc/passwd", Some(2000))?;
1313
match p.process.wait() {
1414
Ok(wait::WaitStatus::Exited(_, 0)) => println!("cat exited with code 0, all good!"),
@@ -29,7 +29,3 @@ fn exit_code_fun() -> Result<(), Error> {
2929

3030
Ok(())
3131
}
32-
33-
fn main() {
34-
exit_code_fun().unwrap_or_else(|e| panic!("cat function failed with {}", e));
35-
}

examples/ftp.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extern crate rexpect;
33
use rexpect::error::Error;
44
use rexpect::spawn;
55

6-
fn do_ftp() -> Result<(), Error> {
6+
fn main() -> Result<(), Error> {
77
let mut p = spawn("ftp speedtest.tele2.net", Some(2000))?;
88
p.exp_regex("Name \\(.*\\):")?;
99
p.send_line("anonymous")?;
@@ -18,7 +18,3 @@ fn do_ftp() -> Result<(), Error> {
1818
p.exp_eof()?;
1919
Ok(())
2020
}
21-
22-
fn main() {
23-
do_ftp().unwrap_or_else(|e| panic!("ftp job failed with {}", e));
24-
}

examples/repl.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn ed_session() -> Result<PtyReplSession, Error> {
2525
Ok(ed)
2626
}
2727

28-
fn do_ed_repl() -> Result<(), Error> {
28+
fn main() -> Result<(), Error> {
2929
let mut ed = ed_session()?;
3030
ed.send_line("a")?;
3131
ed.send_line("ed is the best editor evar")?;
@@ -37,7 +37,3 @@ fn do_ed_repl() -> Result<(), Error> {
3737
ed.exp_eof()?;
3838
Ok(())
3939
}
40-
41-
fn main() {
42-
do_ed_repl().unwrap_or_else(|e| panic!("ed session failed with {}", e));
43-
}

src/lib.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
//! # Basic example
1616
//!
1717
//! ```no_run
18-
//!
1918
//! extern crate rexpect;
2019
//!
2120
//! use rexpect::spawn;
22-
//! use rexpect::error::*;
21+
//! use rexpect::error::Error;
2322
//!
24-
//! fn do_ftp() -> Result<()> {
23+
//! fn main() -> Result<(), Error> {
2524
//! let mut p = spawn("ftp speedtest.tele2.net", Some(2000))?;
2625
//! p.exp_regex("Name \\(.*\\):")?;
2726
//! p.send_line("anonymous")?;
@@ -36,11 +35,6 @@
3635
//! p.exp_eof()?;
3736
//! Ok(())
3837
//! }
39-
//!
40-
//!
41-
//! fn main() {
42-
//! do_ftp().unwrap_or_else(|e| panic!("ftp job failed with {}", e));
43-
//! }
4438
//! ```
4539
//!
4640
//! # Example with bash
@@ -55,10 +49,9 @@
5549
//! ```no_run
5650
//! extern crate rexpect;
5751
//! use rexpect::spawn_bash;
58-
//! use rexpect::error::*;
52+
//! use rexpect::error::Error;
5953
//!
60-
//!
61-
//! fn run() -> Result<()> {
54+
//! fn main() -> Result<(), Error> {
6255
//! let mut p = spawn_bash(Some(30_000))?;
6356
//! p.execute("ping 8.8.8.8", "bytes of data")?;
6457
//! p.send_control('z')?;
@@ -71,11 +64,6 @@
7164
//! p.exp_string("packet loss")?;
7265
//! Ok(())
7366
//! }
74-
//!
75-
//! fn main() {
76-
//! run().unwrap_or_else(|e| panic!("bash process failed with {}", e));
77-
//! }
78-
//!
7967
//! ```
8068
8169
pub mod error;

0 commit comments

Comments
 (0)