diff --git a/Cargo.lock b/Cargo.lock index c246206..e9690e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,7 +85,7 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "ip2d" -version = "0.3.0" +version = "0.4.0" dependencies = [ "clap", ] diff --git a/Cargo.toml b/Cargo.toml index c8387c0..77d551f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "ip2d" description = "A converter for IPv4 addresses" -version = "0.3.0" +version = "0.4.0" license = "MIT" authors = ["0xflotus <0xflotus@gmail.com>"] edition = "2021" diff --git a/src/main.rs b/src/main.rs index 1e2df90..c9406b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,18 @@ -use clap::{Command, Arg}; +use clap::{Arg, ArgAction, Command}; fn main() { let matches = Command::new("ip2d") .author("0xflotus") - .version("0.3.0") + .version("0.4.0") .about("A converter for IPv4 Addresses") .arg( Arg::new("ip") .help("Converts an IPv4 Address to an integer") - .required(false) - .index(1_usize), ) .arg( Arg::new("reverse") .short('r') .long("reverse") - .takes_value(true) .value_name("number") .help("Converts an integer to an IPv4 Address"), ) @@ -23,30 +20,28 @@ fn main() { Arg::new("hex") .short('x') .long("hex") - .takes_value(false) + .action(ArgAction::SetTrue) .help("Converts an IPv4 Address to a hex number"), ) .get_matches(); - if matches.is_present("reverse") { - if let Some(number) = matches.value_of("reverse") { - let num = number.parse::().unwrap(); - let vec: Vec = vec![0x18, 0x10, 0x8, 0x0] - .into_iter() - .map(|x| (num >> x) & 0xff) - .map(|x| x.to_string()) - .collect(); - println!("{}", vec.join(".")); - } + if let Some(number) = matches.get_one::("reverse") { + let num = number.parse::().unwrap(); + let vec: Vec = vec![0x18, 0x10, 0x8, 0x0] + .into_iter() + .map(|x| (num >> x) & 0xff) + .map(|x| x.to_string()) + .collect(); + println!("{}", vec.join(".")); return; } - if let Some(ip) = matches.value_of("ip") { + if let Some(ip) = matches.get_one::("ip") { let splitted = ip .split(".") .map(|x| x.parse::().unwrap()) .fold(0, |x, y| (x << 0x8) | y); - if matches.is_present("hex") { + if matches.get_flag("hex") { println!("{:#010x}", splitted); } else { println!("{}", splitted);