nushell/src/commands/ls.rs

30 lines
740 B
Rust
Raw Normal View History

2019-05-10 18:59:12 +02:00
use crate::errors::ShellError;
use crate::object::process::Process;
use crate::object::{DirEntry, ShellObject, Value};
use derive_new::new;
use sysinfo::SystemExt;
#[derive(new)]
pub struct Ls;
impl crate::Command for Ls {
fn run(
&mut self,
2019-05-11 09:00:33 +02:00
_args: Vec<String>,
2019-05-10 18:59:12 +02:00
_host: &dyn crate::Host,
env: &mut crate::Environment,
) -> Result<Value, ShellError> {
let entries =
std::fs::read_dir(env.cwd()).map_err((|e| ShellError::new(format!("{:?}", e))))?;
let mut shell_entries = vec![];
for entry in entries {
let value = Value::object(DirEntry::new(entry?)?);
shell_entries.push(value)
}
Ok(Value::list(shell_entries))
}
}