diff --git a/src/uu/cksum/Cargo.toml b/src/uu/cksum/Cargo.toml index ef3ec8b46..b7ac630f0 100644 --- a/src/uu/cksum/Cargo.toml +++ b/src/uu/cksum/Cargo.toml @@ -15,6 +15,7 @@ edition = "2018" path = "src/cksum.rs" [dependencies] +clap = "2.33" libc = "0.2.42" uucore = { version=">=0.0.7", package="uucore", path="../../uucore" } uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" } diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index e1c75fffc..bc71a2d97 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -10,6 +10,7 @@ #[macro_use] extern crate uucore; +use clap::{App, Arg}; use std::fs::File; use std::io::{self, stdin, BufReader, Read}; use std::path::Path; @@ -18,9 +19,10 @@ use std::path::Path; const CRC_TABLE_LEN: usize = 256; const CRC_TABLE: [u32; CRC_TABLE_LEN] = generate_crc_table(); +const VERSION: &str = env!("CARGO_PKG_VERSION"); +const NAME: &str = "cksum"; const SYNTAX: &str = "[OPTIONS] [FILE]..."; const SUMMARY: &str = "Print CRC and size for each file"; -const LONG_HELP: &str = ""; // this is basically a hack to get "loops" to work on Rust 1.33. Once we update to Rust 1.46 or // greater, we can just use while loops @@ -160,10 +162,25 @@ fn cksum(fname: &str) -> io::Result<(u32, usize)> { } } -pub fn uumain(args: impl uucore::Args) -> i32 { - let matches = app!(SYNTAX, SUMMARY, LONG_HELP).parse(args.collect_str()); +mod options { + pub static FILE: &str = "file"; +} - let files = matches.free; +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); + + let matches = App::new(executable!()) + .name(NAME) + .version(VERSION) + .about(SUMMARY) + .usage(SYNTAX) + .arg(Arg::with_name(options::FILE).hidden(true).multiple(true)) + .get_matches_from(args); + + let files: Vec = match matches.values_of(options::FILE) { + Some(v) => v.clone().map(|v| v.to_owned()).collect(), + None => vec![], + }; if files.is_empty() { match cksum("-") {