Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cleanup examples #60

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions examples/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate rexpect;
use rexpect::error::Error;
use rexpect::spawn_bash;

fn run() -> Result<(), Error> {
fn main() -> Result<(), Error> {
let mut p = spawn_bash(Some(1000))?;
p.execute("ping 8.8.8.8", "bytes")?;
p.send_control('z')?;
Expand All @@ -18,7 +18,3 @@ fn run() -> Result<(), Error> {
p.exp_string("packet loss")?;
Ok(())
}

fn main() {
run().unwrap_or_else(|e| panic!("bash process failed with {}", e));
}
6 changes: 1 addition & 5 deletions examples/bash_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate rexpect;
use rexpect::error::Error;
use rexpect::spawn_bash;

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

// case 1: wait until program is done
Expand Down Expand Up @@ -33,7 +33,3 @@ fn run() -> Result<(), Error> {
p.send_control('c')?;
Ok(())
}

fn main() {
run().unwrap_or_else(|e| panic!("bash process failed with {}", e));
}
6 changes: 1 addition & 5 deletions examples/exit_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rexpect::spawn;
/// cat exited with code 0, all good!
/// cat exited with code 1
/// Output (stdout and stderr): cat: /this/does/not/exist: No such file or directory
fn exit_code_fun() -> Result<(), Error> {
fn main() -> Result<(), Error> {
let p = spawn("cat /etc/passwd", Some(2000))?;
match p.process.wait() {
Ok(wait::WaitStatus::Exited(_, 0)) => println!("cat exited with code 0, all good!"),
Expand All @@ -29,7 +29,3 @@ fn exit_code_fun() -> Result<(), Error> {

Ok(())
}

fn main() {
exit_code_fun().unwrap_or_else(|e| panic!("cat function failed with {}", e));
}
6 changes: 1 addition & 5 deletions examples/ftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate rexpect;
use rexpect::error::Error;
use rexpect::spawn;

fn do_ftp() -> Result<(), Error> {
fn main() -> Result<(), Error> {
let mut p = spawn("ftp speedtest.tele2.net", Some(2000))?;
p.exp_regex("Name \\(.*\\):")?;
p.send_line("anonymous")?;
Expand All @@ -18,7 +18,3 @@ fn do_ftp() -> Result<(), Error> {
p.exp_eof()?;
Ok(())
}

fn main() {
do_ftp().unwrap_or_else(|e| panic!("ftp job failed with {}", e));
}
6 changes: 1 addition & 5 deletions examples/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn ed_session() -> Result<PtyReplSession, Error> {
Ok(ed)
}

fn do_ed_repl() -> Result<(), Error> {
fn main() -> Result<(), Error> {
let mut ed = ed_session()?;
ed.send_line("a")?;
ed.send_line("ed is the best editor evar")?;
Expand All @@ -37,7 +37,3 @@ fn do_ed_repl() -> Result<(), Error> {
ed.exp_eof()?;
Ok(())
}

fn main() {
do_ed_repl().unwrap_or_else(|e| panic!("ed session failed with {}", e));
}