mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2026-01-17 02:31:02 +00:00
dd: clap 3
This commit is contained in:
parent
f5797275b7
commit
11bfb5c73f
5 changed files with 38 additions and 38 deletions
|
|
@ -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" }
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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::<File>::new(&matches).unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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::<ConvFlag>("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::<ConvFlag>("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::<ConvFlag>("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::<Flag>("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::<Flag>("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::<Flag>("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::<Flag>("oflag", &matches).unwrap();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue