pub fn get_args() -> HashMap<String, String> {
let mut map = HashMap::new();
+ let mut first = true;
for arg in std::env::args() {
- if arg.starts_with("--netdev=") {
+ if first {
+ first = false;
+ continue;
+ } else if arg.starts_with("--netdev=") {
let (_, back) = arg.split_at(9);
map.insert("netdev".into(), back.into());
} else if arg.starts_with("--interval-sec=") {
map.insert("interval-sec".into(), back.into());
} else if arg.starts_with("--help") || arg.starts_with("-h") {
map.insert("help".into(), "".into());
+ } else {
+ let mut stderr_handle = io::stderr().lock();
+ stderr_handle
+ .write_all(format!("WARNING: Got invalid arg \"{}\"!\n", arg).as_bytes())
+ .ok();
}
}
}
}
- let mut used = total - available;
+ let mut used: f64 = (total - available) as f64;
let mut is_used_mega = false;
if total == 0 {
Ok("0".into())
} else {
- if total > 1024 {
- total /= 1024;
+ let mut total = total as f64;
+
+ if total > 1024.0 {
+ total /= 1024.0;
is_total_mega = true;
}
- if used > 1024 {
- used /= 1024;
+ if used > 1024.0 {
+ used /= 1024.0;
is_used_mega = true;
}
- let mut output = format!("{} ", used);
+ let mut output: String;
if is_used_mega {
+ output = format!("{:.2} ", used);
output.push_str("MiB / ");
} else {
+ output = format!("{:.0} ", used);
output.push_str("KiB / ");
}
- write!(&mut output, "{} ", total)?;
if is_total_mega {
+ write!(&mut output, "{:.2} ", total)?;
output.push_str("MiB");
} else {
+ write!(&mut output, "{:.0} ", total)?;
output.push_str("KiB");
}