nushell/src/commands/ps.rs

52 lines
1.1 KiB
Rust
Raw Normal View History

use crate::commands::WholeStreamCommand;
2019-08-11 03:41:21 +02:00
use crate::errors::ShellError;
use crate::object::process::process_dict;
use crate::prelude::*;
2019-08-21 09:41:18 +02:00
#[allow(unused)]
use sysinfo::{RefreshKind, SystemExt};
2019-08-11 03:41:21 +02:00
pub struct PS;
impl WholeStreamCommand for PS {
fn run(
&self,
args: CommandArgs,
registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
ps(args, registry)
}
fn name(&self) -> &str {
"ps"
}
fn signature(&self) -> Signature {
Signature::build("ps")
}
}
fn ps(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
2019-08-21 09:41:18 +02:00
let system;
#[cfg(not(windows))]
{
system = sysinfo::System::new();
}
#[cfg(windows)]
{
let mut sy = sysinfo::System::new_with_specifics(RefreshKind::new().with_processes());
sy.refresh_processes();
system = sy;
}
2019-08-11 03:41:21 +02:00
let list = system.get_process_list();
let list = list
.into_iter()
.map(|(_, process)| process_dict(process, Tag::unknown_origin(args.call_info.name_span)))
.collect::<VecDeque<_>>();
Ok(list.from_input_stream())
}