fix some misalignment errors (#2959)

This commit is contained in:
Darren Schroeder 2021-01-22 12:39:09 -06:00 committed by GitHub
parent 71b99edd48
commit a3be6affa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 15 deletions

View File

@ -10,12 +10,12 @@ version = "0.25.2"
doctest = false
[dependencies]
nu-errors = {path = "../nu-errors", version = "0.25.2"}
nu-plugin = {path = "../nu-plugin", version = "0.25.2"}
nu-protocol = {path = "../nu-protocol", version = "0.25.2"}
nu-source = {path = "../nu-source", version = "0.25.2"}
nu-errors = { path = "../nu-errors", version = "0.25.2" }
nu-plugin = { path = "../nu-plugin", version = "0.25.2" }
nu-protocol = { path = "../nu-protocol", version = "0.25.2" }
nu-source = { path = "../nu-source", version = "0.25.2" }
futures = {version = "0.3.5", features = ["compat", "io-compat"]}
futures = { version = "0.3.5", features = ["compat", "io-compat"] }
futures-util = "0.3.5"
num-bigint = "0.3.0"
sysinfo = "0.15.9"

View File

@ -19,11 +19,15 @@ pub fn disks(sys: &mut System, tag: Tag) -> Option<UntaggedValue> {
let mut dict = TaggedDictBuilder::new(&tag);
dict.insert_untagged(
"device",
UntaggedValue::string(disk.get_name().to_string_lossy()),
UntaggedValue::string(trim_cstyle_null(
disk.get_name().to_string_lossy().to_string(),
)),
);
dict.insert_untagged(
"type",
UntaggedValue::string(String::from_utf8_lossy(disk.get_file_system())),
UntaggedValue::string(trim_cstyle_null(
String::from_utf8_lossy(disk.get_file_system()).to_string(),
)),
);
dict.insert_untagged("mount", UntaggedValue::filepath(disk.get_mount_point()));
dict.insert_untagged("total", UntaggedValue::filesize(disk.get_total_space()));
@ -43,7 +47,10 @@ pub fn net(sys: &mut System, tag: Tag) -> Option<UntaggedValue> {
let mut output = vec![];
for (iface, data) in sys.get_networks() {
let mut dict = TaggedDictBuilder::new(&tag);
dict.insert_untagged("name", UntaggedValue::string(iface));
dict.insert_untagged(
"name",
UntaggedValue::string(trim_cstyle_null(iface.to_string())),
);
dict.insert_untagged(
"sent",
UntaggedValue::filesize(data.get_total_transmitted()),
@ -65,8 +72,14 @@ pub fn cpu(sys: &mut System, tag: Tag) -> Option<UntaggedValue> {
let mut output = vec![];
for cpu in sys.get_processors() {
let mut dict = TaggedDictBuilder::new(&tag);
dict.insert_untagged("name", UntaggedValue::string(cpu.get_name()));
dict.insert_untagged("brand", UntaggedValue::string(cpu.get_brand()));
dict.insert_untagged(
"name",
UntaggedValue::string(trim_cstyle_null(cpu.get_name().to_string())),
);
dict.insert_untagged(
"brand",
UntaggedValue::string(trim_cstyle_null(cpu.get_brand().to_string())),
);
dict.insert_untagged("freq", UntaggedValue::int(cpu.get_frequency()));
output.push(dict.into_value());
@ -100,13 +113,16 @@ pub fn host(sys: &mut System, tag: Tag) -> Option<UntaggedValue> {
let mut dict = TaggedDictBuilder::new(&tag);
if let Some(name) = sys.get_name() {
dict.insert_untagged("name", UntaggedValue::string(name));
dict.insert_untagged("name", UntaggedValue::string(trim_cstyle_null(name)));
}
if let Some(version) = sys.get_version() {
dict.insert_untagged("version", UntaggedValue::string(version));
dict.insert_untagged("version", UntaggedValue::string(trim_cstyle_null(version)));
}
if let Some(hostname) = sys.get_host_name() {
dict.insert_untagged("hostname", UntaggedValue::string(hostname));
dict.insert_untagged(
"hostname",
UntaggedValue::string(trim_cstyle_null(hostname)),
);
}
dict.insert_untagged(
"uptime",
@ -116,11 +132,15 @@ pub fn host(sys: &mut System, tag: Tag) -> Option<UntaggedValue> {
let mut users = vec![];
for user in sys.get_users() {
let mut user_dict = TaggedDictBuilder::new(&tag);
user_dict.insert_untagged("name", UntaggedValue::string(user.get_name()));
user_dict.insert_untagged(
"name",
UntaggedValue::string(trim_cstyle_null(user.get_name().to_string())),
);
let mut groups = vec![];
for group in user.get_groups() {
groups.push(UntaggedValue::string(group).into_value(&tag));
groups
.push(UntaggedValue::string(trim_cstyle_null(group.to_string())).into_value(&tag));
}
user_dict.insert_untagged("groups", UntaggedValue::Table(groups));
@ -193,3 +213,7 @@ pub async fn sysinfo(tag: Tag) -> Vec<Value> {
vec![sysinfo.into_value()]
}
pub fn trim_cstyle_null(s: String) -> String {
s.trim_matches(char::from(0)).to_string()
}