swaybar_info/src/args.rs

45 lines
1.4 KiB
Rust
Raw Normal View History

2022-07-09 08:33:19 +00:00
use std::collections::HashMap;
use std::io;
use std::io::Write;
2022-07-09 08:33:19 +00:00
pub fn get_args() -> HashMap<String, String> {
let mut map = HashMap::new();
let mut first = true;
2022-07-09 08:33:19 +00:00
for arg in std::env::args() {
if first {
first = false;
continue;
} else if arg.starts_with("--netdev=") {
2022-07-09 08:33:19 +00:00
let (_, back) = arg.split_at(9);
map.insert("netdev".into(), back.into());
2022-07-09 09:18:12 +00:00
} else if arg.starts_with("--interval-sec=") {
let (_, back) = arg.split_at(15);
map.insert("interval-sec".into(), back.into());
} else if arg == "--help" || arg == "-h" {
2022-07-09 09:18:12 +00:00
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();
2022-07-09 08:33:19 +00:00
}
}
map
}
2022-07-09 09:18:12 +00:00
pub fn print_usage() {
let mut stderr_handle = io::stderr().lock();
stderr_handle.write_all(b"Usage:\n").ok();
stderr_handle
.write_all(b" -h | --help\t\t\tPrints help\n")
.ok();
stderr_handle
.write_all(b" --netdev=<device_name>\tCheck network traffic on specified device\n")
.ok();
stderr_handle
.write_all(b" --interval-sec=<seconds>\tOutput at intervals of <seconds> (default 5)\n")
.ok();
2022-07-09 09:18:12 +00:00
}