Skip to content

Commit

Permalink
clean up with new rustc 1.74 APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-guo committed Nov 24, 2023
1 parent 787e35d commit f065865
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn main(
/// ```
/// # use cmd_lib::*;
/// fn my_cmd(env: &mut CmdEnv) -> CmdResult {
/// let msg = format!("msg from foo(), args: {:?}\n", env.args());
/// let msg = format!("msg from foo(), args: {:?}\n", env.get_args());
/// writeln!(env.stderr(), "{}", msg)?;
/// writeln!(env.stdout(), "bar")
/// }
Expand Down
20 changes: 9 additions & 11 deletions src/child.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::info;
use crate::{process, CmdResult, FunResult};
use os_pipe::PipeReader;
use std::io::{BufRead, BufReader, Error, ErrorKind, Read, Result};
use std::io::{BufRead, BufReader, Error, Read, Result};
use std::process::{Child, ExitStatus};
use std::thread::JoinHandle;

Expand Down Expand Up @@ -247,10 +247,9 @@ impl CmdChildHandle {
}
}
Err(e) => {
return Err(Error::new(
ErrorKind::Other,
format!("Running [{cmd}] thread joined with error: {e:?}"),
))
return Err(Error::other(format!(
"Running [{cmd}] thread joined with error: {e:?}"
)))
}
}
}
Expand All @@ -261,9 +260,9 @@ impl CmdChildHandle {

fn status_to_io_error(status: ExitStatus, cmd: &str) -> Error {
if let Some(code) = status.code() {
Error::new(ErrorKind::Other, format!("{cmd}; status code: {code}"))
Error::other(format!("{cmd}; status code: {code}"))
} else {
Error::new(ErrorKind::Other, format!("{cmd}; terminated by {status}"))
Error::other(format!("{cmd}; terminated by {status}"))
}
}

Expand Down Expand Up @@ -327,10 +326,9 @@ impl StderrThread {
match thread.join() {
Err(e) => {
let cmd = &self.cmd;
return Err(Error::new(
ErrorKind::Other,
format!("Running [{cmd}] stderr thread joined with error: {e:?}",),
));
return Err(Error::other(format!(
"Running [{cmd}] stderr thread joined with error: {e:?}"
)));
}
Ok(output) => return Ok(output),
}
Expand Down
10 changes: 4 additions & 6 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::collections::HashMap;
use std::ffi::{OsStr, OsString};
use std::fmt;
use std::fs::{File, OpenOptions};
use std::io::{Error, ErrorKind, Read, Result, Write};
use std::io::{Error, Read, Result, Write};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::Mutex;
Expand Down Expand Up @@ -463,16 +463,14 @@ impl Cmd {

fn run_cd_cmd(&self, current_dir: &mut PathBuf) -> CmdResult {
if self.args.len() == 1 {
return Err(Error::new(ErrorKind::Other, "{CD_CMD}: missing directory"));
return Err(Error::other("{CD_CMD}: missing directory"));
} else if self.args.len() > 2 {
let err_msg = format!("{CD_CMD}: too many arguments");
return Err(Error::new(ErrorKind::Other, err_msg));
return Err(Error::other(format!("{CD_CMD}: too many arguments")));
}

let dir = current_dir.join(&self.args[1]);
if !dir.is_dir() {
let err_msg = format!("{CD_CMD}: No such file or directory");
return Err(Error::new(ErrorKind::Other, err_msg));
return Err(Error::other(format!("{CD_CMD}: No such file or directory")));
}

dir.access(AccessMode::EXECUTE)?;
Expand Down

0 comments on commit f065865

Please sign in to comment.