nushell/src/commands/ps.rs

26 lines
653 B
Rust
Raw Normal View History

2019-05-10 16:59:12 +00:00
use crate::errors::ShellError;
use crate::object::process::process_dict;
2019-05-15 22:23:36 +00:00
use crate::object::Value;
use crate::prelude::*;
2019-05-10 16:59:12 +00:00
use derive_new::new;
use sysinfo::SystemExt;
#[derive(new)]
2019-05-15 16:12:38 +00:00
pub struct Ps;
2019-05-10 16:59:12 +00:00
impl crate::Command for Ps {
2019-05-16 00:21:46 +00:00
fn run(&self, _args: CommandArgs<'caller>) -> Result<VecDeque<ReturnValue>, ShellError> {
2019-05-15 16:12:38 +00:00
let mut system = sysinfo::System::new();
2019-05-11 08:08:21 +00:00
system.refresh_all();
2019-05-10 16:59:12 +00:00
2019-05-11 08:08:21 +00:00
let list = system.get_process_list();
2019-05-10 16:59:12 +00:00
let list = list
.into_iter()
.map(|(_, process)| ReturnValue::Value(Value::Object(process_dict(process))))
.collect::<VecDeque<_>>();
2019-05-10 16:59:12 +00:00
Ok(list)
2019-05-10 16:59:12 +00:00
}
}