nushell/src/commands/ps.rs

32 lines
724 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::{ShellObject, Value};
use derive_new::new;
use sysinfo::SystemExt;
#[derive(new)]
pub struct Ps {
system: sysinfo::System,
}
impl crate::Command for Ps {
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> {
self.system.refresh_all();
let list = self.system.get_process_list();
let list = list
.into_iter()
.map(|(_, process)| Value::Object(Box::new(Process::new(process.clone()))))
.take(5)
.collect();
Ok(Value::List(list))
}
}