Fix Windows build issue

This commit is contained in:
Jonathan Turner 2019-06-19 17:09:22 +12:00
parent 3f718a20be
commit 10654d425f

View File

@ -1,7 +1,7 @@
use crate::errors::ShellError; use crate::errors::ShellError;
use crate::object::{Value, Primitive};
use crate::object::Dictionary;
use crate::object::base::OF64; use crate::object::base::OF64;
use crate::object::Dictionary;
use crate::object::{Primitive, Value};
use crate::prelude::*; use crate::prelude::*;
use sys_info::*; use sys_info::*;
@ -10,59 +10,128 @@ pub fn sysinfo(_args: CommandArgs) -> Result<OutputStream, ShellError> {
if let (Ok(name), Ok(version)) = (os_type(), os_release()) { if let (Ok(name), Ok(version)) = (os_type(), os_release()) {
let mut os_idx = indexmap::IndexMap::new(); let mut os_idx = indexmap::IndexMap::new();
os_idx.insert("name".to_string(), Value::Primitive(Primitive::String(name))); os_idx.insert(
os_idx.insert("version".to_string(), Value::Primitive(Primitive::String(version))); "name".to_string(),
Value::Primitive(Primitive::String(name)),
);
os_idx.insert(
"version".to_string(),
Value::Primitive(Primitive::String(version)),
);
idx.insert("os".to_string(), Value::Object(Dictionary::from(os_idx))); idx.insert("os".to_string(), Value::Object(Dictionary::from(os_idx)));
} }
if let (Ok(num_cpu), Ok(cpu_speed)) = (cpu_num(), cpu_speed()) { if let (Ok(num_cpu), Ok(cpu_speed)) = (cpu_num(), cpu_speed()) {
let mut cpu_idx = indexmap::IndexMap::new(); let mut cpu_idx = indexmap::IndexMap::new();
cpu_idx.insert("num".to_string(), Value::Primitive(Primitive::Int(num_cpu as i64))); cpu_idx.insert(
cpu_idx.insert("speed".to_string(), Value::Primitive(Primitive::Int(cpu_speed as i64))); "num".to_string(),
Value::Primitive(Primitive::Int(num_cpu as i64)),
);
cpu_idx.insert(
"speed".to_string(),
Value::Primitive(Primitive::Int(cpu_speed as i64)),
);
idx.insert("cpu".to_string(), Value::Object(Dictionary::from(cpu_idx))); idx.insert("cpu".to_string(), Value::Object(Dictionary::from(cpu_idx)));
} }
if let Ok(x) = loadavg() { if let Ok(x) = loadavg() {
let mut load_idx = indexmap::IndexMap::new(); let mut load_idx = indexmap::IndexMap::new();
load_idx.insert("1min".to_string(), Value::Primitive(Primitive::Float(OF64::from(x.one)))); load_idx.insert(
load_idx.insert("5min".to_string(), Value::Primitive(Primitive::Float(OF64::from(x.five)))); "1min".to_string(),
load_idx.insert("15min".to_string(), Value::Primitive(Primitive::Float(OF64::from(x.fifteen)))); Value::Primitive(Primitive::Float(OF64::from(x.one))),
);
load_idx.insert(
"5min".to_string(),
Value::Primitive(Primitive::Float(OF64::from(x.five))),
);
load_idx.insert(
"15min".to_string(),
Value::Primitive(Primitive::Float(OF64::from(x.fifteen))),
);
idx.insert("load avg".to_string(), Value::Object(Dictionary::from(load_idx))); idx.insert(
"load avg".to_string(),
Value::Object(Dictionary::from(load_idx)),
);
} }
if let Ok(x) = mem_info() { if let Ok(x) = mem_info() {
let mut mem_idx = indexmap::IndexMap::new(); let mut mem_idx = indexmap::IndexMap::new();
mem_idx.insert("total".to_string(), Value::Primitive(Primitive::Bytes(x.total as u128 * 1024))); mem_idx.insert(
mem_idx.insert("free".to_string(), Value::Primitive(Primitive::Bytes(x.free as u128 * 1024))); "total".to_string(),
mem_idx.insert("avail".to_string(), Value::Primitive(Primitive::Bytes(x.avail as u128 * 1024))); Value::Primitive(Primitive::Bytes(x.total as u128 * 1024)),
mem_idx.insert("buffers".to_string(), Value::Primitive(Primitive::Bytes(x.buffers as u128 * 1024))); );
mem_idx.insert("cached".to_string(), Value::Primitive(Primitive::Bytes(x.cached as u128 * 1024))); mem_idx.insert(
mem_idx.insert("swap total".to_string(), Value::Primitive(Primitive::Bytes(x.swap_total as u128 * 1024))); "free".to_string(),
mem_idx.insert("swap free".to_string(), Value::Primitive(Primitive::Bytes(x.swap_free as u128 * 1024))); Value::Primitive(Primitive::Bytes(x.free as u128 * 1024)),
);
mem_idx.insert(
"avail".to_string(),
Value::Primitive(Primitive::Bytes(x.avail as u128 * 1024)),
);
mem_idx.insert(
"buffers".to_string(),
Value::Primitive(Primitive::Bytes(x.buffers as u128 * 1024)),
);
mem_idx.insert(
"cached".to_string(),
Value::Primitive(Primitive::Bytes(x.cached as u128 * 1024)),
);
mem_idx.insert(
"swap total".to_string(),
Value::Primitive(Primitive::Bytes(x.swap_total as u128 * 1024)),
);
mem_idx.insert(
"swap free".to_string(),
Value::Primitive(Primitive::Bytes(x.swap_free as u128 * 1024)),
);
idx.insert("mem".to_string(), Value::Object(Dictionary::from(mem_idx))); idx.insert("mem".to_string(), Value::Object(Dictionary::from(mem_idx)));
} }
if let Ok(x) = disk_info() { if let Ok(x) = disk_info() {
let mut disk_idx = indexmap::IndexMap::new(); let mut disk_idx = indexmap::IndexMap::new();
disk_idx.insert("total".to_string(), Value::Primitive(Primitive::Bytes(x.total as u128 * 1024))); disk_idx.insert(
disk_idx.insert("free".to_string(), Value::Primitive(Primitive::Bytes(x.free as u128 * 1024))); "total".to_string(),
Value::Primitive(Primitive::Bytes(x.total as u128 * 1024)),
);
disk_idx.insert(
"free".to_string(),
Value::Primitive(Primitive::Bytes(x.free as u128 * 1024)),
);
} }
if let Ok(x) = hostname() { if let Ok(x) = hostname() {
idx.insert("hostname".to_string(), Value::Primitive(Primitive::String(x))); idx.insert(
"hostname".to_string(),
Value::Primitive(Primitive::String(x)),
);
} }
#[cfg(not(windows))]
{
if let Ok(x) = boottime() { if let Ok(x) = boottime() {
let mut boottime_idx = indexmap::IndexMap::new(); let mut boottime_idx = indexmap::IndexMap::new();
boottime_idx.insert("days".to_string(), Value::Primitive(Primitive::Int(x.tv_sec / (24 * 3600)))); boottime_idx.insert(
boottime_idx.insert("hours".to_string(), Value::Primitive(Primitive::Int((x.tv_sec / 3600) % 24))); "days".to_string(),
boottime_idx.insert("mins".to_string(), Value::Primitive(Primitive::Int((x.tv_sec / 60) % 60))); Value::Primitive(Primitive::Int(x.tv_sec / (24 * 3600))),
);
boottime_idx.insert(
"hours".to_string(),
Value::Primitive(Primitive::Int((x.tv_sec / 3600) % 24)),
);
boottime_idx.insert(
"mins".to_string(),
Value::Primitive(Primitive::Int((x.tv_sec / 60) % 60)),
);
idx.insert("uptime".to_string(), Value::Object(Dictionary::from(boottime_idx))); idx.insert(
"uptime".to_string(),
Value::Object(Dictionary::from(boottime_idx)),
);
}
} }
let mut stream = VecDeque::new(); let mut stream = VecDeque::new();