diff --git a/src/lib.rs b/src/lib.rs index 39dc43b..45dc5e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,15 @@ pub enum Os { } impl Os { + + pub fn from_name(name: &str) -> Option { + match name.to_lowercase().as_ref() { + "archlinux" | "arch linux" => Some(Os::ArchLinux), + "ubuntu" => Some(Os::Ubuntu), + _ => None, + } + } + pub fn detect() -> Option { let lsb_release = lsb_release().unwrap(); @@ -27,7 +36,6 @@ impl Os { _ => None, } - } pub fn ascii_logo(self) -> &'static str { diff --git a/src/logos/ubuntu.rs b/src/logos/ubuntu.rs index 29eac35..f980184 100644 --- a/src/logos/ubuntu.rs +++ b/src/logos/ubuntu.rs @@ -1,5 +1,4 @@ -pub const ASCII_LOGO: &'static str = " \ -\n \x1B[31;1m./+o+-\x1B[0m \ +pub const ASCII_LOGO: &'static str = " \x1B[31;1m./+o+-\x1B[0m \ \n \x1B[1myyyyy-\x1B[0m \x1B[31;1m-yyyyyy+\x1B[0m \ \n \x1B[1m://+//////\x1B[31;1m-yyyyyyo\x1B[0m \ \n \x1B[33;1m.++ \x1B[0;1m.:/++++++/-\x1B[31;1m.+sss/`\x1B[0m \ diff --git a/src/main.rs b/src/main.rs index cbcc3fd..b94fa59 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use std::env::{args, var}; +use std::process::exit; use std::fs::File; use std::io::Read; @@ -10,7 +11,35 @@ pub fn main() { let mut hostname_file = File::open("/etc/hostname").unwrap(); hostname_file.read_to_string(&mut hostname).unwrap(); - let os = Os::detect().unwrap(); + let mut os = Os::detect().unwrap(); + + let mut iterator = args().skip(1); + + loop { + + let arg = match iterator.next() { + Some(arg) => arg, + None => break, + }; + + if arg == "-d" { + os = match iterator.next().map(|x| Os::from_name(&x)) { + Some(Some(os)) => os, + Some(None) => { + eprintln!("\x1B[31;1merror:\x1B[0m distribution not recognized"); + exit(1); + }, + None => { + eprintln!("\x1B[31;1merror:\x1B[0m argument -d expect distribution as parameter"); + exit(1); + }, + }; + + continue; + }; + } + + let style = os.style(); let unstyle = os.unstyle(); @@ -28,13 +57,29 @@ pub fn main() { uptime, ]; - for arg in args().skip(1) { + + let mut iterator = args().skip(1); + + loop { + + let arg = match iterator.next() { + Some(arg) => arg, + None => break, + }; + + if arg == "-d" { + iterator.next(); + continue; + }; + let split = arg.split(":").collect::>(); + if split.len() != 2 { eprintln!("\x1B[33;1mwarning:\x1B[0m argument must be formatted like \"key:value\""); continue; } info.push(format!("{style}{}:{unstyle} {}\n", split[0], split[1], style = style, unstyle = unstyle)); + } let mut logo_iterator = os.ascii_logo().lines();