diff --git a/src/main.rs b/src/main.rs index a1fd4c1..6f128fe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,19 @@ +use std::io::Read; + fn main() { let args: Vec = std::env::args().collect(); - if args.len() < 2 { - eprintln!("Missing arguments: ."); - std::process::exit(1); - } - - let ip_string = &args[1]; + let mut input_buf = String::new(); + let ip_string = if args.len() < 2 || args[1] == "-" { + if std::io::stdin().read_to_string(&mut input_buf).is_ok() { + &input_buf + } else { + eprintln!("Missing arguments: ."); + std::process::exit(1); + } + } else { + &args[1] + }; println!( "Result: \n{}", @@ -14,7 +21,7 @@ fn main() { Ok(x) => { int_to_ip(x) } - Err(_) => ip_to_int(ip_string).to_string(), + Err(_) => ip_to_int(ip_string.trim()).to_string(), } ); }