diff --git a/src/lib/builtins/mod.rs b/src/lib/builtins/mod.rs index 84acc4665b104d7daad4281c08d59d09c459bb28..d4e26d975f4d3ce9697c80e597da47006c88e61f 100644 --- a/src/lib/builtins/mod.rs +++ b/src/lib/builtins/mod.rs @@ -30,7 +30,7 @@ use self::{ use std::{ borrow::Cow, - io::{self, BufRead, Write}, + io::{self, BufRead}, path::PathBuf, }; @@ -689,25 +689,14 @@ pub fn builtin_disown(args: &[small::String], shell: &mut Shell) -> Status { } pub fn builtin_help(args: &[small::String], shell: &mut Shell) -> Status { - let builtins = shell.builtins(); - let stdout = io::stdout(); - let mut stdout = stdout.lock(); if let Some(command) = args.get(1) { - if let Some(help) = builtins.get_help(command) { - let _ = stdout.write_all(help.as_bytes()); - let _ = stdout.write_all(b"\n"); + if let Some(help) = shell.builtins().get_help(command) { + println!("{}", help); } else { - let _ = stdout.write_all(b"Command helper not found [run 'help']..."); - let _ = stdout.write_all(b"\n"); + println!("Command helper not found [run 'help']..."); } } else { - let commands = builtins.keys(); - - let mut buffer: Vec<u8> = Vec::new(); - for command in commands { - let _ = writeln!(buffer, "{}", command); - } - let _ = stdout.write_all(&buffer); + println!("{}", shell.builtins().keys().join("")); } Status::SUCCESS } @@ -743,16 +732,14 @@ pub fn builtin_matches(args: &[small::String], _: &mut Shell) -> Status { return Status::SUCCESS; } if args[1..].len() != 2 { - let stderr = io::stderr(); - let mut stderr = stderr.lock(); - let _ = stderr.write_all(b"match takes two arguments\n"); + eprintln!("match takes two arguments"); return Status::BAD_ARG; } let input = &args[1]; let re = match Regex::new(&args[2]) { Ok(r) => r, Err(e) => { - return Status::error(format!("couldn't compile input regex {}: {}\n", args[2], e)); + return Status::error(format!("couldn't compile input regex {}: {}", args[2], e)); } }; diff --git a/src/lib/shell/status.rs b/src/lib/shell/status.rs index b10532703003fce6f3846a70e952171422c69048..70cc8ed002a50daa9d06613de060518b83042173 100644 --- a/src/lib/shell/status.rs +++ b/src/lib/shell/status.rs @@ -17,7 +17,10 @@ impl Status { pub fn from_bool(b: bool) -> Self { Status(!b as i32) } pub fn error<T: AsRef<str>>(err: T) -> Self { - eprintln!("{}", err.as_ref()); + let err = err.as_ref(); + if !err.is_empty() { + eprintln!("{}", err); + } Status(1) }