Add a --full mode to ps (#1507)

* Add a --full mode to ps

* Use a slightly older heim
This commit is contained in:
Jonathan Turner
2020-03-20 20:53:49 +13:00
committed by GitHub
parent afa963fd50
commit b5ea522f0e
11 changed files with 236 additions and 496 deletions

676
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -57,7 +57,7 @@ nu-test-support = { version = "0.11.0", path = "./crates/nu-test-support" }
[build-dependencies]
toml = "0.5.6"
serde = { version = "1.0.104", features = ["derive"] }
serde = { version = "1.0.105", features = ["derive"] }
nu-build = { version = "0.11.0", path = "./crates/nu-build" }
[features]

View File

@ -22,9 +22,9 @@ nu-test-support = { version = "0.11.0", path = "../nu-test-support" }
ansi_term = "0.12.1"
app_dirs = "1.2.1"
async-stream = "0.2"
base64 = "0.11"
base64 = "0.12.0"
bigdecimal = { version = "0.1.0", features = ["serde"] }
bson = { version = "0.14.0", features = ["decimal128"] }
bson = { version = "0.14.1", features = ["decimal128"] }
byte-unit = "3.0.3"
bytes = "0.5.4"
calamine = "0.16"
@ -41,7 +41,7 @@ futures = { version = "0.3", features = ["compat", "io-compat"] }
futures-util = "0.3.4"
futures_codec = "0.4"
getset = "0.1.0"
git2 = { version = "0.11.0", default_features = false }
git2 = { version = "0.13.0", default_features = false }
glob = "0.3.0"
hex = "0.4"
htmlescape = "0.3.1"
@ -66,9 +66,9 @@ ptree = {version = "0.2" }
query_interface = "0.3.5"
rand = "0.7"
regex = "1"
roxmltree = "0.9.1"
roxmltree = "0.10.0"
rustyline = "6.0.0"
serde = { version = "1.0.104", features = ["derive"] }
serde = { version = "1.0.105", features = ["derive"] }
serde-hjson = "0.9.1"
serde_bytes = "0.11.3"
serde_ini = "0.2.0"
@ -89,7 +89,7 @@ unicode-xid = "0.2.0"
which = "3.1.1"
clipboard = { version = "0.5", optional = true }
starship = { version = "0.37.0", optional = true }
starship = { version = "0.38.0", optional = true }
[target.'cfg(unix)'.dependencies]
users = "0.9"

View File

@ -11,7 +11,7 @@ doctest = false
[dependencies]
ansi_term = "0.12.1"
crossterm = { version = "0.14.2" }
crossterm = { version = "0.16.0" }
nu-plugin = { path = "../nu-plugin", version = "0.11.0" }
nu-protocol = { path = "../nu-protocol", version = "0.11.0" }
nu-source = { path = "../nu-source", version = "0.11.0" }

View File

@ -17,10 +17,9 @@ nu-errors = { path = "../nu-errors", version = "0.11.0" }
futures = { version = "0.3", features = ["compat", "io-compat"] }
futures-timer = "3.0.1"
pin-utils = "0.1.0-alpha.4"
[dependencies.heim]
version = "0.0.9"
version = "0.0.10"
default-features = false
features = ["process", "runtime-polyfill"]

View File

@ -9,11 +9,16 @@ impl Plugin for Ps {
fn config(&mut self) -> Result<Signature, ShellError> {
Ok(Signature::build("ps")
.desc("View information about system processes.")
.switch(
"full",
"list all available columns for each entry",
Some('f'),
)
.filter())
}
fn begin_filter(&mut self, callinfo: CallInfo) -> Result<Vec<ReturnValue>, ShellError> {
Ok(block_on(ps(callinfo.name_tag))
Ok(block_on(ps(callinfo.name_tag, callinfo.args.has("full")))
.into_iter()
.map(ReturnSuccess::value)
.collect())

View File

@ -27,8 +27,8 @@ async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio, proc
Ok((process, usage_2 - usage_1, memory))
}
pub async fn ps(tag: Tag) -> Vec<Value> {
let processes = process::processes()
pub async fn ps(tag: Tag, full: bool) -> Vec<Value> {
let mut processes = process::processes()
.map_ok(|process| {
// Note that there is no `.await` here,
// as we want to pass the returned future
@ -36,7 +36,6 @@ pub async fn ps(tag: Tag) -> Vec<Value> {
usage(process)
})
.try_buffer_unordered(usize::MAX);
pin_utils::pin_mut!(processes);
let mut output = vec![];
while let Some(res) = processes.next().await {
@ -58,6 +57,22 @@ pub async fn ps(tag: Tag) -> Vec<Value> {
"virtual",
UntaggedValue::bytes(memory.vms().get::<information::byte>()),
);
if full {
if let Ok(parent_pid) = process.parent_pid().await {
dict.insert_untagged("parent", UntaggedValue::int(parent_pid))
}
if let Ok(exe) = process.exe().await {
dict.insert_untagged("exe", UntaggedValue::string(exe.to_string_lossy()))
}
if let Ok(command) = process.command().await {
dict.insert_untagged(
"command",
UntaggedValue::string(command.to_os_string().to_string_lossy()),
);
}
}
output.push(dict.into_value());
}
}

View File

@ -20,7 +20,7 @@ battery = "0.7.5"
futures-util = "0.3.1"
[dependencies.heim]
version = "0.0.9"
version = "0.0.10"
default-features = false
features = ["host", "cpu", "memory", "disk", "net", "sensors", "runtime-polyfill"]

View File

@ -1,3 +1,5 @@
#![type_length_limit = "2474736"]
mod nu;
mod sys;

View File

@ -134,6 +134,7 @@ async fn host(tag: Tag) -> Value {
async fn disks(tag: Tag) -> Option<UntaggedValue> {
let mut output = vec![];
let mut partitions = disk::partitions_physical();
while let Some(part) = partitions.next().await {
if let Ok(part) = part {
let mut dict = TaggedDictBuilder::with_capacity(&tag, 6);
@ -228,6 +229,7 @@ async fn temp(tag: Tag) -> Option<UntaggedValue> {
let mut output = vec![];
let mut sensors = sensors::temperatures();
while let Some(sensor) = sensors.next().await {
if let Ok(sensor) = sensor {
let mut dict = TaggedDictBuilder::new(&tag);
@ -272,6 +274,7 @@ async fn temp(tag: Tag) -> Option<UntaggedValue> {
async fn net(tag: Tag) -> Option<UntaggedValue> {
let mut output = vec![];
let mut io_counters = net::io_counters();
while let Some(nic) = io_counters.next().await {
if let Ok(nic) = nic {
let mut network_idx = TaggedDictBuilder::with_capacity(&tag, 3);

View File

@ -15,7 +15,7 @@ nu-protocol = { path = "../nu-protocol", version = "0.11.0" }
nu-source = { path = "../nu-source", version = "0.11.0" }
nu-errors = { path = "../nu-errors", version = "0.11.0" }
crossterm = "0.14.2"
crossterm = "0.16.0"
syntect = "3.2.0"
onig_sys = "~69.1.0"
ansi_term = "0.12.1"