فهرست منبع

vanityaddr: Parse usize for nthreads with clap.

parazyd 4 سال پیش
والد
کامیت
7c1b1524ce
1فایلهای تغییر یافته به همراه8 افزوده شده و 14 حذف شده
  1. 8 14
      bin/vanityaddr/src/main.rs

+ 8 - 14
bin/vanityaddr/src/main.rs

@@ -23,8 +23,8 @@ struct Args {
     case_sensitive: bool,
 
     /// Number of threads to use (defaults to number of available CPUs)
-    #[clap(short)]
-    threads: Option<String>,
+    #[clap(short, parse(try_from_str))]
+    threads: Option<usize>,
 }
 
 struct DrkAddr {
@@ -61,6 +61,11 @@ impl DrkAddr {
 fn main() {
     let args = Args::parse();
 
+    if args.prefix.is_empty() {
+        eprintln!("Error: No prefix given to search.");
+        exit(1);
+    }
+
     for (idx, prefix) in args.prefix.iter().enumerate() {
         if !prefix.starts_with('1') {
             eprintln!("Error: Address prefix at index {} must start with \"1\".", idx);
@@ -80,18 +85,7 @@ fn main() {
     }
 
     // Threadpool
-    let num_threads = if args.threads.is_some() {
-        match args.threads.unwrap().parse::<usize>() {
-            Ok(v) => v,
-            Err(e) => {
-                eprintln!("Error: Invalid thread number: {}", e);
-                exit(1);
-            }
-        }
-    } else {
-        num_cpus::get()
-    };
-
+    let num_threads = if args.threads.is_some() { args.threads.unwrap() } else { num_cpus::get() };
     let rayon_pool = rayon::ThreadPoolBuilder::new().num_threads(num_threads).build().unwrap();
 
     // Something fancy