diff --git a/Cargo.toml b/Cargo.toml index ad439c6..adae82d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "picca" version = "0.5.0" edition = "2024" +autobins = true [dependencies] sha2 = "0.10.9" diff --git a/man/picca.1.md b/man/picca.1.md index b863b1f..e389e09 100644 --- a/man/picca.1.md +++ b/man/picca.1.md @@ -25,10 +25,10 @@ When conditions are suitable, being able to hash multiple files in parallel can With no FILE(s) specified, or when FILE is a dash (-), picca will read from standard input. -**-a, ––algorithm**=_ALGORITHM_ +**-a, ––algorithm** _ALGORITHM_ : Specify the algorithm for hashing. The default value is sha256. A list of supported algorithms can be found in the **ALGORITHMS** section. -**-c, ––check**=_CHECK_ +**-c, ––check** _CHECK_ : Read checksums from the specified file and verify them. This argument can be specified multiple times to read checksums from multiple files. **-d, ––debug** @@ -40,7 +40,7 @@ With no FILE(s) specified, or when FILE is a dash (-), picca will read from stan **-h, ––help** : Show command usage and available options -**-t, ––threads**=_THREADS_ +**-t, ––threads** _THREADS_ : Use at most, at any given time, this number of threads. By default, picca will detect the amount of processors on the system and use that as the thread count. Using 0 for this value results in the default behavior; this is the same as omitting this option. **-V, ––version** diff --git a/src/main.rs b/src/bin/picca.rs similarity index 92% rename from src/main.rs rename to src/bin/picca.rs index d61e180..0519a6c 100644 --- a/src/main.rs +++ b/src/bin/picca.rs @@ -7,8 +7,8 @@ use std::sync::atomic::{AtomicI32, Ordering}; use std::sync::{Arc, Mutex}; use std::thread::{self, JoinHandle, available_parallelism}; -mod common; -mod hashers; +use picca::message; +use picca::hashers; const ALGORITHMS: [&'static str; 44] = [ "ascon", @@ -156,7 +156,7 @@ fn hash(info: ThreadInfo) -> Result<(), String> { }; if !info.quiet && info.debug { - common::debug(format!( + message::debug(format!( "thread {} is hashing file '{}'", info.thread_id, filename.as_path().display() @@ -167,12 +167,12 @@ fn hash(info: ThreadInfo) -> Result<(), String> { let mut buffer = String::new(); match io::stdin().lock().read_to_string(&mut buffer) { Ok(_) => (), - Err(e) => common::error(format!("stdin: {}", e)), + Err(e) => message::error(format!("stdin: {}", e)), } stdin = Some(buffer) } else if filename.is_dir() { - common::error(format!("{}: Is a directory", filename.as_path().display())); + message::error(format!("{}: Is a directory", filename.as_path().display())); info.file_errors.fetch_add(1, Ordering::SeqCst); continue; } else { @@ -261,7 +261,7 @@ fn hash(info: ThreadInfo) -> Result<(), String> { } if !info.quiet && info.debug { - common::debug(format!("thread {} has ran out of work", info.thread_id)); + message::debug(format!("thread {} has ran out of work", info.thread_id)); } Ok(()) @@ -284,7 +284,7 @@ fn verify( for file in checksum_files { match read_to_string(&file) { Err(e) => { - common::error(format!("{}: {}", file.as_path().display(), e)); + message::error(format!("{}: {}", file.as_path().display(), e)); continue; }, Ok(f) => { @@ -296,7 +296,7 @@ fn verify( hash_map.insert(PathBuf::from(split[1].clone()), split[0].clone()); buffer.push_back(PathBuf::from(split[1].clone())); }, - _ => common::error(format!("malformed line: {}", line)), + _ => message::error(format!("malformed line: {}", line)), } } }, @@ -398,18 +398,25 @@ fn main() { }; if args.debug { - common::debug(format!( - "Starting picca using algorithm {} with a max of {} threads", - args.algorithm, cpus - )); + if env!("CARGO_BIN_NAME") != "picca" { + message::debug(format!( + "Starting picca using algorithm {} with a max of {} threads", + args.algorithm, cpus + )); + } else { + message::debug(format!( + "Starting {} with a max of {} threads", + env!("CARGO_BIN_NAME"), cpus + )); + } if docker { - common::debug(format!("Docker is detected")); + message::debug(format!("Docker is detected")); } } if UNSECURE_ALGORITHMS.contains(&args.algorithm.as_str()) { - common::warning(format!( + message::warning(format!( "{} is an unsecure hashing algorithm!", &args.algorithm )); @@ -452,11 +459,11 @@ fn main() { let fe = arc_fe.load(Ordering::SeqCst); let he = arc_he.load(Ordering::SeqCst); if fe != 0 { - common::warning(format!("{} listed files could not be read", fe)); + message::warning(format!("{} listed files could not be read", fe)); } if he != 0 { - common::warning(format!("{} computed checksums did NOT match", he)); + message::warning(format!("{} computed checksums did NOT match", he)); } if (he != 0 || fe != 0) && check_mode { diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d0743b5 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,2 @@ +pub mod message; +pub mod hashers; diff --git a/src/common.rs b/src/message.rs similarity index 100% rename from src/common.rs rename to src/message.rs