From 11bfb5c73f8751981fe06b1d27b84efd03542244 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Tue, 11 Jan 2022 13:21:21 +0100 Subject: [PATCH] dd: clap 3 --- src/uu/dd/Cargo.toml | 2 +- src/uu/dd/src/dd.rs | 32 ++++++++--------- src/uu/dd/src/dd_unit_tests/sanity_tests.rs | 2 +- src/uu/dd/src/parseargs.rs | 2 +- src/uu/dd/src/parseargs/unit_tests.rs | 38 ++++++++++----------- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/uu/dd/Cargo.toml b/src/uu/dd/Cargo.toml index 968996b28..d370c5642 100644 --- a/src/uu/dd/Cargo.toml +++ b/src/uu/dd/Cargo.toml @@ -16,7 +16,7 @@ path = "src/dd.rs" [dependencies] byte-unit = "4.0" -clap = { version = "2.33", features = [ "wrap_help" ] } +clap = { version = "3.0", features = ["wrap_help", "cargo"] } gcd = "2.0" libc = "0.2" uucore = { version=">=0.0.8", package="uucore", path="../../uucore" } diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 644d7abb0..3e8cd19c4 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -36,7 +36,7 @@ use std::thread; use std::time; use byte_unit::Byte; -use clap::{self, crate_version}; +use clap::{crate_version, App, Arg, ArgMatches}; use gcd::Gcd; #[cfg(target_os = "linux")] use signal_hook::consts::signal; @@ -932,12 +932,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } } -pub fn uu_app() -> clap::App<'static, 'static> { - clap::App::new(uucore::util_name()) +pub fn uu_app<'a>() -> App<'a> { + App::new(uucore::util_name()) .version(crate_version!()) .about(ABOUT) .arg( - clap::Arg::with_name(options::INFILE) + Arg::new(options::INFILE) .long(options::INFILE) .takes_value(true) .require_equals(true) @@ -945,7 +945,7 @@ pub fn uu_app() -> clap::App<'static, 'static> { .help("(alternatively if=FILE) specifies the file used for input. When not specified, stdin is used instead") ) .arg( - clap::Arg::with_name(options::OUTFILE) + Arg::new(options::OUTFILE) .long(options::OUTFILE) .takes_value(true) .require_equals(true) @@ -953,7 +953,7 @@ pub fn uu_app() -> clap::App<'static, 'static> { .help("(alternatively of=FILE) specifies the file used for output. When not specified, stdout is used instead") ) .arg( - clap::Arg::with_name(options::IBS) + Arg::new(options::IBS) .long(options::IBS) .takes_value(true) .require_equals(true) @@ -961,7 +961,7 @@ pub fn uu_app() -> clap::App<'static, 'static> { .help("(alternatively ibs=N) specifies the size of buffer used for reads (default: 512). Multiplier strings permitted.") ) .arg( - clap::Arg::with_name(options::OBS) + Arg::new(options::OBS) .long(options::OBS) .takes_value(true) .require_equals(true) @@ -969,7 +969,7 @@ pub fn uu_app() -> clap::App<'static, 'static> { .help("(alternatively obs=N) specifies the size of buffer used for writes (default: 512). Multiplier strings permitted.") ) .arg( - clap::Arg::with_name(options::BS) + Arg::new(options::BS) .long(options::BS) .takes_value(true) .require_equals(true) @@ -977,7 +977,7 @@ pub fn uu_app() -> clap::App<'static, 'static> { .help("(alternatively bs=N) specifies ibs=N and obs=N (default: 512). If ibs or obs are also specified, bs=N takes precedence. Multiplier strings permitted.") ) .arg( - clap::Arg::with_name(options::CBS) + Arg::new(options::CBS) .long(options::CBS) .takes_value(true) .require_equals(true) @@ -985,7 +985,7 @@ pub fn uu_app() -> clap::App<'static, 'static> { .help("(alternatively cbs=BYTES) specifies the 'conversion block size' in bytes. Applies to the conv=block, and conv=unblock operations. Multiplier strings permitted.") ) .arg( - clap::Arg::with_name(options::SKIP) + Arg::new(options::SKIP) .long(options::SKIP) .takes_value(true) .require_equals(true) @@ -993,7 +993,7 @@ pub fn uu_app() -> clap::App<'static, 'static> { .help("(alternatively skip=N) causes N ibs-sized records of input to be skipped before beginning copy/convert operations. See iflag=count_bytes if skipping N bytes is preferred. Multiplier strings permitted.") ) .arg( - clap::Arg::with_name(options::SEEK) + Arg::new(options::SEEK) .long(options::SEEK) .takes_value(true) .require_equals(true) @@ -1001,7 +1001,7 @@ pub fn uu_app() -> clap::App<'static, 'static> { .help("(alternatively seek=N) seeks N obs-sized records into output before beginning copy/convert operations. See oflag=seek_bytes if seeking N bytes is preferred. Multiplier strings permitted.") ) .arg( - clap::Arg::with_name(options::COUNT) + Arg::new(options::COUNT) .long(options::COUNT) .takes_value(true) .require_equals(true) @@ -1009,7 +1009,7 @@ pub fn uu_app() -> clap::App<'static, 'static> { .help("(alternatively count=N) stop reading input after N ibs-sized read operations rather than proceeding until EOF. See iflag=count_bytes if stopping after N bytes is preferred. Multiplier strings permitted.") ) .arg( - clap::Arg::with_name(options::STATUS) + Arg::new(options::STATUS) .long(options::STATUS) .takes_value(true) .require_equals(true) @@ -1033,7 +1033,7 @@ Printing performance stats is also triggered by the INFO signal (where supported ") ) .arg( - clap::Arg::with_name(options::CONV) + Arg::new(options::CONV) .long(options::CONV) .takes_value(true) .require_equals(true) @@ -1070,7 +1070,7 @@ Conversion Flags: ") ) .arg( - clap::Arg::with_name(options::IFLAG) + Arg::new(options::IFLAG) .long(options::IFLAG) .takes_value(true) .require_equals(true) @@ -1096,7 +1096,7 @@ General-Flags ") ) .arg( - clap::Arg::with_name(options::OFLAG) + Arg::new(options::OFLAG) .long(options::OFLAG) .takes_value(true) .require_equals(true) diff --git a/src/uu/dd/src/dd_unit_tests/sanity_tests.rs b/src/uu/dd/src/dd_unit_tests/sanity_tests.rs index edf25fe5d..f58d68c48 100644 --- a/src/uu/dd/src/dd_unit_tests/sanity_tests.rs +++ b/src/uu/dd/src/dd_unit_tests/sanity_tests.rs @@ -311,6 +311,6 @@ fn test_nocreat_causes_failure_when_ofile_doesnt_exist() { String::from("--of=not-a-real.file"), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let _ = Output::::new(&matches).unwrap(); } diff --git a/src/uu/dd/src/parseargs.rs b/src/uu/dd/src/parseargs.rs index ef2d5f356..06cdeff25 100644 --- a/src/uu/dd/src/parseargs.rs +++ b/src/uu/dd/src/parseargs.rs @@ -13,7 +13,7 @@ use super::*; use std::error::Error; use uucore::error::UError; -pub type Matches = clap::ArgMatches<'static>; +pub type Matches = ArgMatches; /// Parser Errors describe errors with parser input #[derive(Debug, PartialEq)] diff --git a/src/uu/dd/src/parseargs/unit_tests.rs b/src/uu/dd/src/parseargs/unit_tests.rs index 21900ee49..3ee949805 100644 --- a/src/uu/dd/src/parseargs/unit_tests.rs +++ b/src/uu/dd/src/parseargs/unit_tests.rs @@ -25,7 +25,7 @@ fn unimplemented_flags_should_error_non_linux() { format!("--iflag={}", flag), format!("--oflag={}", flag), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); if parse_iflags(&matches).is_ok() { succeeded.push(format!("iflag={}", flag)); @@ -53,7 +53,7 @@ fn unimplemented_flags_should_error() { format!("--iflag={}", flag), format!("--oflag={}", flag), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); if parse_iflags(&matches).is_ok() { succeeded.push(format!("iflag={}", flag)) @@ -78,7 +78,7 @@ fn test_status_level_absent() { String::from("--of=bar.file"), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let st = parse_status_level(&matches).unwrap(); assert_eq!(st, None); @@ -93,7 +93,7 @@ fn test_status_level_none() { String::from("--of=bar.file"), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let st = parse_status_level(&matches).unwrap().unwrap(); assert_eq!(st, StatusLevel::None); @@ -121,7 +121,7 @@ fn test_all_top_level_args_no_leading_dashes() { .into_iter() .fold(Vec::new(), append_dashes_if_not_present); - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); assert_eq!(100, parse_ibs(&matches).unwrap()); assert_eq!(100, parse_obs(&matches).unwrap()); @@ -205,7 +205,7 @@ fn test_all_top_level_args_with_leading_dashes() { .into_iter() .fold(Vec::new(), append_dashes_if_not_present); - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); assert_eq!(100, parse_ibs(&matches).unwrap()); assert_eq!(100, parse_obs(&matches).unwrap()); @@ -276,7 +276,7 @@ fn test_status_level_progress() { String::from("--status=progress"), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let st = parse_status_level(&matches).unwrap().unwrap(); assert_eq!(st, StatusLevel::Progress); @@ -291,7 +291,7 @@ fn test_status_level_noxfer() { String::from("--of=bar.file"), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let st = parse_status_level(&matches).unwrap().unwrap(); assert_eq!(st, StatusLevel::Noxfer); @@ -304,7 +304,7 @@ fn test_status_level_noxfer() { fn icf_ctable_error() { let args = vec![String::from("dd"), String::from("--conv=ascii,ebcdic,ibm")]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let _ = parse_conv_flag_input(&matches).unwrap(); } @@ -314,7 +314,7 @@ fn icf_ctable_error() { fn icf_case_error() { let args = vec![String::from("dd"), String::from("--conv=ucase,lcase")]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let _ = parse_conv_flag_input(&matches).unwrap(); } @@ -324,7 +324,7 @@ fn icf_case_error() { fn icf_block_error() { let args = vec![String::from("dd"), String::from("--conv=block,unblock")]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let _ = parse_conv_flag_input(&matches).unwrap(); } @@ -334,7 +334,7 @@ fn icf_block_error() { fn icf_creat_error() { let args = vec![String::from("dd"), String::from("--conv=excl,nocreat")]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let _ = parse_conv_flag_output(&matches).unwrap(); } @@ -344,7 +344,7 @@ fn parse_icf_token_ibm() { let exp = vec![ConvFlag::FmtAtoI]; let args = vec![String::from("dd"), String::from("--conv=ibm")]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let act = parse_flag_list::("conv", &matches).unwrap(); @@ -362,7 +362,7 @@ fn parse_icf_tokens_elu() { String::from("dd"), String::from("--conv=ebcdic,lcase,unblock"), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let act = parse_flag_list::("conv", &matches).unwrap(); assert_eq!(exp.len(), act.len()); @@ -393,7 +393,7 @@ fn parse_icf_tokens_remaining() { String::from("dd"), String::from("--conv=ascii,ucase,block,sparse,swab,sync,noerror,excl,nocreat,notrunc,noerror,fdatasync,fsync"), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let act = parse_flag_list::("conv", &matches).unwrap(); @@ -417,7 +417,7 @@ fn parse_iflag_tokens() { String::from("dd"), String::from("--iflag=fullblock,count_bytes,skip_bytes,append,seek_bytes"), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let act = parse_flag_list::("iflag", &matches).unwrap(); @@ -441,7 +441,7 @@ fn parse_oflag_tokens() { String::from("dd"), String::from("--oflag=fullblock,count_bytes,skip_bytes,append,seek_bytes"), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let act = parse_flag_list::("oflag", &matches).unwrap(); @@ -469,7 +469,7 @@ fn parse_iflag_tokens_linux() { String::from("dd"), String::from("--iflag=direct,directory,dsync,sync,nonblock,noatime,noctty,nofollow"), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let act = parse_flag_list::("iflag", &matches).unwrap(); @@ -497,7 +497,7 @@ fn parse_oflag_tokens_linux() { String::from("dd"), String::from("--oflag=direct,directory,dsync,sync,nonblock,noatime,noctty,nofollow"), ]; - let matches = uu_app().get_matches_from_safe(args).unwrap(); + let matches = uu_app().try_get_matches_from(args).unwrap(); let act = parse_flag_list::("oflag", &matches).unwrap();