From 06d6b48154330777bff9772805d26c8a008274e4 Mon Sep 17 00:00:00 2001 From: Nathan Fiedler Date: Wed, 11 Jan 2023 20:56:12 -0800 Subject: [PATCH] fix: update clap and fix example --- CHANGELOG.md | 4 ++++ Cargo.toml | 4 ++-- examples/dedupe.rs | 32 ++++++++++---------------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af062df..7af85e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). This file follows the convention described at [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). +## [1.0.7] - 2023-01-11 +### Added +- dristic: expose hash on chunk struct. + ## [1.0.6] - 2021-01-08 ### Added - rickvanprim: implement `size_hint()` for FastCDC struct. diff --git a/Cargo.toml b/Cargo.toml index e674bb7..722b60e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fastcdc" -version = "1.0.6" +version = "1.0.7" authors = ["Nathan Fiedler "] edition = "2018" description = "FastCDC (content defined chunking) in pure Rust." @@ -16,4 +16,4 @@ exclude = [ [dev-dependencies] memmap = "0.7.0" crypto-hash = "0.3.4" -clap = "3.0.5" +clap = { version = "4.0.32", features = ["cargo"] } diff --git a/examples/dedupe.rs b/examples/dedupe.rs index 66d6a42..fbb825a 100644 --- a/examples/dedupe.rs +++ b/examples/dedupe.rs @@ -1,32 +1,20 @@ // -// Copyright (c) 2020 Nathan Fiedler +// Copyright (c) 2023 Nathan Fiedler // -use clap::{App, Arg}; +use clap::{arg, command, value_parser, Arg}; use crypto_hash::{hex_digest, Algorithm}; use fastcdc::*; use memmap::MmapOptions; use std::fs::File; -use std::str::FromStr; fn main() { - fn is_integer(v: &str) -> Result<(), String> { - if u64::from_str(&v).is_ok() { - return Ok(()); - } - Err(String::from( - "The size must be a valid unsigned 64-bit integer.", - )) - } - let matches = App::new("Example of using fastcdc crate.") + let matches = command!("Example of using fastcdc crate.") .about("Splits a (large) file and computes checksums.") .arg( - Arg::new("size") - .short('s') - .long("size") - .value_name("SIZE") - .help("The desired average size of the chunks.") - .takes_value(true) - .validator(is_integer), + arg!( + -s --size "The desired average size of the chunks." + ) + .value_parser(value_parser!(u64)), ) .arg( Arg::new("INPUT") @@ -35,9 +23,9 @@ fn main() { .index(1), ) .get_matches(); - let size = matches.value_of("size").unwrap_or("131072"); - let avg_size = u64::from_str(size).unwrap() as usize; - let filename = matches.value_of("INPUT").unwrap(); + let size = matches.get_one::("size").unwrap_or(&131072); + let avg_size = *size as usize; + let filename = matches.get_one::("INPUT").unwrap(); let file = File::open(filename).expect("cannot open file!"); let mmap = unsafe { MmapOptions::new().map(&file).expect("cannot create mmap?") }; let min_size = avg_size / 2;