diff --git a/src/hash.rs b/src/hash.rs index a097f5e..f4c3873 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -29,10 +29,10 @@ pub struct PreparedImage<'a> { * Wraps the various perceptual hashes */ pub struct PerceptualHashes<'a> { - orig_path: &'a str, - ahash: u64, - dhash: u64, - phash: u64 + pub orig_path: &'a str, + pub ahash: u64, + pub dhash: u64, + pub phash: u64 } /** diff --git a/src/lib.rs b/src/lib.rs index a344cee..6b2e675 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,25 +7,6 @@ use std::path::Path; mod hash; -pub fn hello(mut result: String) -> String { - let helloworld = "Hello, World!\n"; - result.push_str(helloworld); - let n = 1u8; - let ns = format!("1: {:b}\n", n); - let n2 = 2u8; - let n2s = format!("2: {:b}\n", n2); - result.push_str(&ns); - result.push_str(&n2s); - let mut endian = "Big Endian\n"; - if cfg!(target_endian = "big") { - result.push_str(endian); - } else { - endian = "Little Endian\n"; - result.push_str(endian); - } - result -} - pub fn get_phashes(path: &Path) -> hash::PerceptualHashes { hash::get_perceptual_hashes(path, 8) } diff --git a/src/main.rs b/src/main.rs index 35db5b7..8db5f0e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,73 @@ // This file may not be copied, modified, or distributed except according to those terms. extern crate pihash; +extern crate rustc_serialize; +extern crate docopt; + +use std::path::Path; +use docopt::Docopt; + +// The usage description +const USAGE: &'static str = " +Perceptual Image Hashing (pihash) + +Usage: + pihash [options] ... + pihash (--help | --version) + +Options: + -h, --help Show this screen. + -V, --version Print version. + -a, --ahash Include an ahash calculation. + -d, --dhash Include an dhash calculation. + -p, --phash Include an phash calculation. +"; + +#[derive(Debug, RustcDecodable)] +struct Args { + flag_ahash: bool, + flag_dhash: bool, + flag_phash: bool, + arg_path: Vec, +} fn main() { - let mut string = String::new(); - string = pihash::hello(string); - println!("{}",string); + let args: Args = Docopt::new(USAGE) + .and_then(|d| d.decode()) + .unwrap_or_else(|e| e.exit()); + //println!("{:?}", args); + // All flags set or, no flags set + if (args.flag_ahash && args.flag_dhash && args.flag_phash) + || (!args.flag_ahash && !args.flag_dhash && !args.flag_phash) { + for path in args.arg_path { + let image_path = Path::new(&path); + let hashes = pihash::get_phashes(&image_path); + let hash_result = format!(r#" + file: {} + ahash: {} + dhash: {} + phash: {} + "#, hashes.orig_path, hashes.ahash, hashes.dhash, hashes.phash); + println!("{}", hash_result); + } + //Otherwise process only specific hashes + } else { + for path in args.arg_path { + println!("file: {}", path); + let image_path = Path::new(&path); + if args.flag_ahash { + let ahash = pihash::get_ahash(&image_path); + println!("ahash: {}", ahash); + } + if args.flag_dhash { + let dhash = pihash::get_dhash(&image_path); + println!("dhash: {}", dhash); + } + if args.flag_phash { + let phash = pihash::get_phash(&image_path); + println!("phash: {}", phash); + } + println!(""); + } + } }