nushell/src/commands/ls.rs

19 lines
556 B
Rust
Raw Normal View History

2019-05-10 18:59:12 +02:00
use crate::errors::ShellError;
2019-05-16 00:23:36 +02:00
use crate::object::{dir_entry_dict, Value};
use crate::prelude::*;
2019-05-10 18:59:12 +02:00
pub fn ls(args: CommandArgs) -> Result<OutputStream, ShellError> {
let cwd = args.env.lock().unwrap().cwd().to_path_buf();
2019-05-11 10:08:21 +02:00
2019-05-22 09:12:03 +02:00
let entries = std::fs::read_dir(&cwd).map_err(|e| ShellError::string(format!("{:?}", e)))?;
2019-05-16 02:21:46 +02:00
2019-05-22 09:12:03 +02:00
let mut shell_entries = VecDeque::new();
2019-05-10 18:59:12 +02:00
2019-05-22 09:12:03 +02:00
for entry in entries {
let value = Value::Object(dir_entry_dict(&entry?)?);
shell_entries.push_back(ReturnValue::Value(value))
2019-05-10 18:59:12 +02:00
}
2019-05-22 09:12:03 +02:00
Ok(shell_entries.boxed())
2019-05-10 18:59:12 +02:00
}