From 776d824814ab54d296990444a334a2032a9e97a2 Mon Sep 17 00:00:00 2001 From: bencelaszlo Date: Tue, 26 Mar 2024 21:44:42 +0100 Subject: [PATCH] change: update clap and rand --- Cargo.lock | 339 ++++++++++++++++++++++++++++++++++++----------- Cargo.toml | 28 ++-- src/generator.rs | 17 +-- src/main.rs | 106 ++++++++------- 4 files changed, 330 insertions(+), 160 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 482a516..0af3c95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,30 +12,59 @@ dependencies = [ ] [[package]] -name = "ansi_term" -version = "0.11.0" +name = "anstream" +version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" dependencies = [ - "winapi", + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", ] [[package]] -name = "approx" -version = "0.1.1" +name = "anstyle" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] -name = "atty" -version = "0.2.13" +name = "anstyle-parse" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" dependencies = [ - "libc", - "winapi", + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", ] +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "approx" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94" + [[package]] name = "autocfg" version = "0.1.6" @@ -44,9 +73,9 @@ checksum = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875" [[package]] name = "bitflags" -version = "1.2.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a606a02debe2813760609f57a64a2ffd27d9fdf5b2f133eaca0b248dd92cdd2" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "bytemuck" @@ -54,21 +83,11 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" -[[package]] -name = "c2-chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" -dependencies = [ - "lazy_static", - "ppv-lite86", -] - [[package]] name = "cfg-if" -version = "0.1.10" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cgmath" @@ -83,19 +102,38 @@ dependencies = [ [[package]] name = "clap" -version = "2.33.0" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ - "ansi_term", - "atty", - "bitflags", + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", "strsim", - "textwrap", - "unicode-width", - "vec_map", + "terminal_size", ] +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "colored" version = "1.8.0" @@ -106,6 +144,16 @@ dependencies = [ "winconsole", ] +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -114,9 +162,9 @@ checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" [[package]] name = "getrandom" -version = "0.1.12" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "473a1265acc8ff1e808cd0a1af8cee3c2ee5200916058a2ca113c29f2d903571" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", @@ -137,9 +185,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.62" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "memchr" @@ -167,9 +221,9 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.5" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "rand" @@ -186,25 +240,23 @@ dependencies = [ [[package]] name = "rand" -version = "0.7.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "getrandom", "libc", "rand_chacha", - "rand_core 0.5.1", - "rand_hc", + "rand_core 0.6.4", ] [[package]] name = "rand_chacha" -version = "0.2.1" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "c2-chacha", - "rand_core 0.5.1", + "ppv-lite86", + "rand_core 0.6.4", ] [[package]] @@ -224,22 +276,13 @@ checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" [[package]] name = "rand_core" -version = "0.5.1" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", -] - [[package]] name = "randoom" version = "0.4.0" @@ -247,7 +290,7 @@ dependencies = [ "clap", "colored", "num-traits 0.2.8", - "rand 0.7.2", + "rand 0.8.5", "regex", "serde", "serde_json", @@ -288,6 +331,19 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "rustix" +version = "0.38.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "ryu" version = "1.0.0" @@ -313,36 +369,31 @@ dependencies = [ [[package]] name = "strsim" -version = "0.8.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" [[package]] -name = "textwrap" -version = "0.11.0" +name = "terminal_size" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" dependencies = [ - "unicode-width", + "rustix", + "windows-sys 0.48.0", ] [[package]] -name = "unicode-width" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20" - -[[package]] -name = "vec_map" -version = "0.8.2" +name = "utf8parse" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "wasi" -version = "0.7.0" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "winapi" @@ -377,3 +428,135 @@ dependencies = [ "rgb", "winapi", ] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.4", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" diff --git a/Cargo.toml b/Cargo.toml index 8664426..763a656 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,23 +4,11 @@ version = "0.4.0" authors = ["bencelaszlo "] edition = "2021" -[dependencies.clap] -clap = { version = "4.5.4", default-features = false,features = ["suggestions", "color", "wrap_help"] } - -[dependencies.rand] -version = "0.7.2" - -[dependencies.colored] -version = "1.8.0" - -[dependencies.serde] -version = "1.0.101" - -[dependencies.serde_json] -version = "1.0.40" - -[dependencies.num-traits] -version = "0.2.8" - -[dependencies.regex] -version = "1.5.5" +[dependencies] +clap = { version = "4.5.4", default-features = false, features = ["suggestions", "color", "wrap_help", "std"] } +rand = { version = "0.8.5" } +colored = { version = "1.8.0" } +serde = { version = "1.0.101" } +serde_json = { version = "1.0.40" } +num-traits = { version = "0.2.8" } +regex = { version = "1.5.5" } diff --git a/src/generator.rs b/src/generator.rs index cf9324c..ea2d89e 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -1,11 +1,12 @@ extern crate rand; + use rand::Rng; use colored::Colorize; extern crate num_traits; -pub fn number_generator( +pub fn number_generator( n: usize, lower_limit: T, higher_limit: T, @@ -20,7 +21,7 @@ where let mut rng = rand::thread_rng(); for i in 0..n { - let generated_value: T = rng.gen_range(lower_limit, higher_limit); + let generated_value: T = rng.gen_range(lower_limit..higher_limit); if verbose_mode { print!( "\r--> {} / {}", @@ -39,7 +40,7 @@ pub fn bool_generator(n: usize, verbose_mode: bool) -> Vec { let mut rng = rand::thread_rng(); for i in 0..n { - let temp_num_value = rng.gen_range(0, 2); + let temp_num_value = rng.gen_range(0..2); let bool_value: bool; if temp_num_value == 0 { bool_value = false; @@ -115,7 +116,7 @@ pub fn char_generator( let mut rng = rand::thread_rng(); while generated_values.len() != n { - let temp_data: &[u8] = &[rng.gen_range(0, 255) as u8]; + let temp_data: &[u8] = &[rng.gen_range(0..255) as u8]; if numbers_mode && special_characters_mode { if !is_control_char(temp_data[0]) { @@ -186,7 +187,7 @@ pub fn string_generator( let mut rng = rand::thread_rng(); for i in 0..n { - let string_length: usize = rng.gen_range(min_length, max_length); + let string_length: usize = rng.gen_range(min_length..max_length); let generated_chars: Vec = char_generator( string_length, special_characters_mode, @@ -211,9 +212,9 @@ pub fn color_generator(n: usize, verbose_mode: bool) -> Vec { let mut rng = rand::thread_rng(); for i in 0..n { - let red_component_numeric: usize = rng.gen_range(0, 255); - let green_component_numeric: usize = rng.gen_range(0, 255); - let blue_component_numeric: usize = rng.gen_range(0, 255); + let red_component_numeric: usize = rng.gen_range(0..255); + let green_component_numeric: usize = rng.gen_range(0..255); + let blue_component_numeric: usize = rng.gen_range(0..255); let mut red_component: String = format!("{:x}", red_component_numeric); let mut green_component: String = format!("{:x}", green_component_numeric); diff --git a/src/main.rs b/src/main.rs index 2f86409..d247400 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ mod io; extern crate rand; extern crate clap; -use clap::{App, AppSettings, Arg}; +use clap::{Arg, ArgAction, Command}; extern crate colored; use colored::*; @@ -31,84 +31,85 @@ fn print_in_verbose_mode(verbose_mode: bool, text: &str, text_color: &str) { } fn main() -> std::io::Result<()> { - let app = App::new("randoom") - .setting(AppSettings::ColorAuto) - .setting(AppSettings::AllowNegativeNumbers) - .version("0.3.0") - .author("Bence László ") + let matches = Command::new("randoom") + .version("0.4.0") + .author("Bence László ") .about("Generate random numbers, texts, JSONs and colors.") - .arg(Arg::with_name("verbose") + .arg(Arg::new("verbose") .help("Verbose mode. Print more detail to the terminal.") - .short("v") + .short('v') .long("verbose") - .takes_value(false) + .action(ArgAction::SetTrue) .required(false)) - .arg(Arg::with_name("datatype") + .arg(Arg::new("datatype") .help("Choose the type of the generated data. Possible options: f32, f64, u32, u64, usize, i32, i64, isize, rgb.") - .short("t") + .short('t') .long("datatype") - .takes_value(true) + .action(ArgAction::Set) + .num_args(1) .required(true)) - .arg(Arg::with_name("number") + .arg(Arg::new("number") .help("Number of data to be generated.") - .short("n") + .short('n') .long("number") - .takes_value(true) + .num_args(1) .required(true)) - .arg(Arg::with_name("lower_limit") + .arg(Arg::new("lower_limit") .help("Lower limit for numbers.") - .short("l") .long("lower") - .takes_value(true) + .value_name("FILE") + .action(ArgAction::Set) + .num_args(1) .required(false)) - .arg(Arg::with_name("higher_limit") + .arg(Arg::new("higher_limit") .help("Higher limit for numbers.") - .short("h") .long("higher") - .takes_value(true) + .action(ArgAction::Set) + .num_args(1) .required(false)) - .arg(Arg::with_name("separator") + .arg(Arg::new("separator") .help("Separator character between individual values. Default value: \n (new line).") - .short("s") + .short('s') .long("separator") - .takes_value(true) - .required(false)) + .action(ArgAction::Set) + .num_args(1) + .required(false)) - .arg(Arg::with_name("special_character_mode") + .arg(Arg::new("special_character_mode") .help("Turn on special characters in character generator.") .long("special-character-mode") - .takes_value(false) + .action(ArgAction::SetTrue) .required(false)) - .arg(Arg::with_name("number_character_mode") + .arg(Arg::new("number_character_mode") .help("Turn on numbers in character generator.") .long("number-character-mode") - .takes_value(false) + .action(ArgAction::SetTrue) .required(false)) - .arg(Arg::with_name("string_min_length") + .arg(Arg::new("string_min_length") .help("Minimum length of random strings.") .long("string-min-length") - .takes_value(true) + .action(ArgAction::Set) .required(false)) - .arg(Arg::with_name("string_max_length") + .arg(Arg::new("string_max_length") .help("Maximum length of random strings.") .long("string-max-length") - .takes_value(true) + .action(ArgAction::Set) .required(false)) - .arg(Arg::with_name("output") + .arg(Arg::new("output") .help("Output filename. Default value: random_data.txt") - .short("o") + .short('o') .long("output") - .takes_value(true) + .action(ArgAction::Set) .required(false)) .get_matches(); @@ -124,20 +125,19 @@ fn main() -> std::io::Result<()> { "m".magenta().blink().underline().bold() ); - let mut option_verbose: bool = false; + let option_verbose: bool = matches.get_one::("verbose").unwrap().clone(); let mut option_datatype: String = "".to_string(); let mut option_number: usize = 0; let mut option_lower_limit: f64 = 0.0f64; let mut option_higher_limit: f64 = 1.0f64; let mut option_separator: char = "\n".parse().unwrap(); - let mut option_special_character_mode: bool = false; - let mut option_number_character_mode: bool = false; + let option_special_character_mode: bool = matches.get_one::("special_character_mode").unwrap().clone(); + let option_number_character_mode: bool = matches.get_one::("number_character_mode").unwrap().clone(); let mut option_string_min_length: usize = 0; let mut option_string_max_length: usize = 4; let mut option_output_filename: String = "./randoom_data.txt".to_string(); - if app.is_present("verbose") { - option_verbose = true; + if option_verbose { print_in_verbose_mode( option_verbose, "randoom will operate in verbose mode.", @@ -155,32 +155,31 @@ fn main() -> std::io::Result<()> { option_json = json.to_string(); }*/ - if let Some(datatype) = app.value_of("datatype") { + if let Some(datatype) = matches.get_one::("datatype") { print_in_verbose_mode(option_verbose, "\nChosen type: ", "white"); print_in_verbose_mode(option_verbose, datatype, "cyan"); option_datatype = datatype.to_string(); } - if let Some(number) = app.value_of("number") { - print_in_verbose_mode(option_verbose, "\nNumber: ", "white"); + if let Some(number) = matches.get_one::("number") { + print_in_verbose_mode(option_verbose, "\nNumber: ", "white"); print_in_verbose_mode(option_verbose, number, "cyan"); option_number = number.parse().unwrap(); } - if let Some(lower_limit) = app.value_of("lower_limit") { + if let Some(lower_limit) = matches.get_one::("lower_limit") { print_in_verbose_mode(option_verbose, "\nLower limit: ", "white"); print_in_verbose_mode(option_verbose, lower_limit, "cyan"); option_lower_limit = lower_limit.parse().unwrap(); } - if let Some(higher_limit) = app.value_of("higher_limit") { + if let Some(higher_limit) = matches.get_one::("higher_limit") { print_in_verbose_mode(option_verbose, "\nHigher limit: ", "white"); print_in_verbose_mode(option_verbose, higher_limit, "cyan"); option_higher_limit = higher_limit.parse().unwrap(); } - if app.is_present("special_character_mode") { - option_special_character_mode = true; + if option_special_character_mode { print_in_verbose_mode( option_verbose, "\nCharacter generator can generate special characters now, too.", @@ -188,8 +187,7 @@ fn main() -> std::io::Result<()> { ); } - if app.is_present("number_character_mode") { - option_number_character_mode = true; + if option_number_character_mode { print_in_verbose_mode( option_verbose, "\nCharacter generator can generate number characters now, too.", @@ -197,25 +195,25 @@ fn main() -> std::io::Result<()> { ); } - if let Some(string_min_length) = app.value_of("string_min_length") { + if let Some(string_min_length) = matches.get_one::("string_min_length") { print_in_verbose_mode(option_verbose, "\nminimum length: ", "white"); print_in_verbose_mode(option_verbose, string_min_length, "cyan"); option_string_min_length = string_min_length.parse().unwrap(); } - if let Some(string_max_length) = app.value_of("string_max_length") { + if let Some(string_max_length) = matches.get_one::("string_max_length") { print_in_verbose_mode(option_verbose, "\nmaximum length: ", "white"); print_in_verbose_mode(option_verbose, string_max_length, "cyan"); option_string_max_length = string_max_length.parse().unwrap(); } - if let Some(separator) = app.value_of("separator") { + if let Some(separator) = matches.get_one::("separator") { print_in_verbose_mode(option_verbose, "\nseparator:", "white"); print_in_verbose_mode(option_verbose, separator, "cyan"); option_separator = separator.parse().unwrap(); } - if let Some(output) = app.value_of("output") { + if let Some(output) = matches.get_one::("output") { print_in_verbose_mode(option_verbose, "\noutput filename: ", "white"); print_in_verbose_mode(option_verbose, output, "cyan"); option_output_filename = output.parse().unwrap();