ls should use file names, not abs paths

main
Jordan Orelli 8 months ago
parent e71c3f89f7
commit af181b372c

@ -11,8 +11,13 @@ impl Call for Ls {
let cwd = env::current_dir()?; let cwd = env::current_dir()?;
let dir = fs::read_dir(&cwd)?; let dir = fs::read_dir(&cwd)?;
for child in dir { for child in dir {
let child = child?; let child_path = child?.path();
_ = write!(ctx.stdout, "{}\n", child.path().display()); let fname = child_path
.file_name()
.ok_or_else(|| ExecError::new("no file name"))?
.to_str()
.ok_or_else(|| ExecError::new("non-unicode file name"))?;
_ = write!(ctx.stdout, "{}\n", fname);
} }
Ok(Value::None) Ok(Value::None)
} }

@ -126,6 +126,10 @@ impl ExecError {
pub fn type_error<S: Into<String>>(msg: S) -> Self { pub fn type_error<S: Into<String>>(msg: S) -> Self {
Self::ValueTypeError(msg.into()) Self::ValueTypeError(msg.into())
} }
pub fn new<S: Into<String>>(msg: S) -> Self {
Self::Misc(msg.into())
}
} }
impl Error { impl Error {

Loading…
Cancel
Save