2019-05-10 16:59:12 +00: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 07:00:33 +00:00
|
|
|
_args: Vec<String>,
|
2019-05-10 16:59:12 +00: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))
|
|
|
|
}
|
|
|
|
}
|