1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-17 04:06:18 +00:00

od: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-29 23:20:33 +02:00
parent c99d89152a
commit cdde016501
3 changed files with 36 additions and 50 deletions

View file

@ -16,7 +16,7 @@ path = "src/od.rs"
[dependencies] [dependencies]
byteorder = "1.3.2" byteorder = "1.3.2"
clap = { version = "3.2", features = ["wrap_help", "cargo"] } clap = { version = "4.0", features = ["wrap_help", "cargo"] }
half = "2.1" half = "2.1"
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }

View file

@ -43,7 +43,8 @@ use crate::parse_nrofbytes::parse_number_of_bytes;
use crate::partialreader::*; use crate::partialreader::*;
use crate::peekreader::*; use crate::peekreader::*;
use crate::prn_char::format_ascii_dump; use crate::prn_char::format_ascii_dump;
use clap::{crate_version, AppSettings, Arg, ArgMatches, Command, ValueSource}; use clap::ArgAction;
use clap::{crate_version, parser::ValueSource, Arg, ArgMatches, Command};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::format_usage; use uucore::format_usage;
@ -195,7 +196,7 @@ impl OdOptions {
line_bytes = min_bytes; line_bytes = min_bytes;
} }
let output_duplicates = matches.contains_id(options::OUTPUT_DUPLICATES); let output_duplicates = matches.get_flag(options::OUTPUT_DUPLICATES);
let read_bytes = match matches.get_one::<String>(options::READ_BYTES) { let read_bytes = match matches.get_one::<String>(options::READ_BYTES) {
None => None, None => None,
@ -290,7 +291,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
odfunc(&mut input_offset, &mut input_decoder, &output_info) odfunc(&mut input_offset, &mut input_decoder, &output_info)
} }
pub fn uu_app<'a>() -> Command<'a> { pub fn uu_app() -> Command {
Command::new(uucore::util_name()) Command::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
@ -299,11 +300,13 @@ pub fn uu_app<'a>() -> Command<'a> {
.trailing_var_arg(true) .trailing_var_arg(true)
.dont_delimit_trailing_values(true) .dont_delimit_trailing_values(true)
.infer_long_args(true) .infer_long_args(true)
.setting(AppSettings::DeriveDisplayOrder) .args_override_self(true)
.disable_help_flag(true)
.arg( .arg(
Arg::new(options::HELP) Arg::new(options::HELP)
.long(options::HELP) .long(options::HELP)
.help("Print help information.") .help("Print help information.")
.action(ArgAction::Help)
) )
.arg( .arg(
Arg::new(options::ADDRESS_RADIX) Arg::new(options::ADDRESS_RADIX)
@ -348,142 +351,123 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new("a") Arg::new("a")
.short('a') .short('a')
.help("named characters, ignoring high-order bit") .help("named characters, ignoring high-order bit")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("b") Arg::new("b")
.short('b') .short('b')
.help("octal bytes") .help("octal bytes")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("c") Arg::new("c")
.short('c') .short('c')
.help("ASCII characters or backslash escapes") .help("ASCII characters or backslash escapes")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("d") Arg::new("d")
.short('d') .short('d')
.help("unsigned decimal 2-byte units") .help("unsigned decimal 2-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("D") Arg::new("D")
.short('D') .short('D')
.help("unsigned decimal 4-byte units") .help("unsigned decimal 4-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("o") Arg::new("o")
.short('o') .short('o')
.help("octal 2-byte units") .help("octal 2-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("I") Arg::new("I")
.short('I') .short('I')
.help("decimal 8-byte units") .help("decimal 8-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("L") Arg::new("L")
.short('L') .short('L')
.help("decimal 8-byte units") .help("decimal 8-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("i") Arg::new("i")
.short('i') .short('i')
.help("decimal 4-byte units") .help("decimal 4-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("l") Arg::new("l")
.short('l') .short('l')
.help("decimal 8-byte units") .help("decimal 8-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("x") Arg::new("x")
.short('x') .short('x')
.help("hexadecimal 2-byte units") .help("hexadecimal 2-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("h") Arg::new("h")
.short('h') .short('h')
.help("hexadecimal 2-byte units") .help("hexadecimal 2-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("O") Arg::new("O")
.short('O') .short('O')
.help("octal 4-byte units") .help("octal 4-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue)
.takes_value(false),
) )
.arg( .arg(
Arg::new("s") Arg::new("s")
.short('s') .short('s')
.help("decimal 2-byte units") .help("decimal 2-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("X") Arg::new("X")
.short('X') .short('X')
.help("hexadecimal 4-byte units") .help("hexadecimal 4-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("H") Arg::new("H")
.short('H') .short('H')
.help("hexadecimal 4-byte units") .help("hexadecimal 4-byte units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("e") Arg::new("e")
.short('e') .short('e')
.help("floating point double precision (64-bit) units") .help("floating point double precision (64-bit) units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("f") Arg::new("f")
.short('f') .short('f')
.help("floating point double precision (32-bit) units") .help("floating point double precision (32-bit) units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new("F") Arg::new("F")
.short('F') .short('F')
.help("floating point double precision (64-bit) units") .help("floating point double precision (64-bit) units")
.multiple_occurrences(true) .action(ArgAction::SetTrue),
.takes_value(false),
) )
.arg( .arg(
Arg::new(options::FORMAT) Arg::new(options::FORMAT)
.short('t') .short('t')
.long("format") .long("format")
.help("select output format or formats") .help("select output format or formats")
.multiple_occurrences(true) .action(ArgAction::Append)
.number_of_values(1) .num_args(1)
.value_name("TYPE"), .value_name("TYPE"),
) )
.arg( .arg(
@ -491,7 +475,7 @@ pub fn uu_app<'a>() -> Command<'a> {
.short('v') .short('v')
.long(options::OUTPUT_DUPLICATES) .long(options::OUTPUT_DUPLICATES)
.help("do not use * to mark line suppression") .help("do not use * to mark line suppression")
.takes_value(false), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::WIDTH) Arg::new(options::WIDTH)
@ -502,18 +486,19 @@ pub fn uu_app<'a>() -> Command<'a> {
specified.", specified.",
) )
.default_missing_value("32") .default_missing_value("32")
.value_name("BYTES"), .value_name("BYTES")
.num_args(..=1),
) )
.arg( .arg(
Arg::new(options::TRADITIONAL) Arg::new(options::TRADITIONAL)
.long(options::TRADITIONAL) .long(options::TRADITIONAL)
.help("compatibility mode with one input, offset and label.") .help("compatibility mode with one input, offset and label.")
.takes_value(false), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::FILENAME) Arg::new(options::FILENAME)
.hide(true) .hide(true)
.multiple_occurrences(true) .action(ArgAction::Append)
.value_hint(clap::ValueHint::FilePath), .value_hint(clap::ValueHint::FilePath),
) )
} }

View file

@ -18,7 +18,8 @@ impl CommandLineOpts for ArgMatches {
} }
fn opts_present(&self, opts: &[&str]) -> bool { fn opts_present(&self, opts: &[&str]) -> bool {
opts.iter().any(|opt| self.contains_id(opt)) opts.iter()
.any(|opt| self.value_source(opt) == Some(clap::parser::ValueSource::CommandLine))
} }
} }