1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

od: clap 3

This commit is contained in:
Terts Diepraam 2022-01-11 14:22:16 +01:00
parent 7cebb2563b
commit 9efd6654f8
3 changed files with 100 additions and 95 deletions

View file

@ -16,7 +16,7 @@ path = "src/od.rs"
[dependencies] [dependencies]
byteorder = "1.3.2" byteorder = "1.3.2"
clap = { version = "2.33", features = ["wrap_help"] } clap = { version = "3.0", features = ["wrap_help", "cargo"] }
half = "1.6" half = "1.6"
libc = "0.2.42" libc = "0.2.42"
uucore = { version=">=0.0.10", package="uucore", path="../../uucore" } uucore = { version=">=0.0.10", package="uucore", path="../../uucore" }

View file

@ -42,7 +42,7 @@ 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::{self, crate_version, AppSettings, Arg, ArgMatches}; use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError}; use uucore::error::{UResult, USimpleError};
use uucore::parse_size::ParseSizeError; use uucore::parse_size::ParseSizeError;
@ -286,229 +286,227 @@ 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() -> clap::App<'static, 'static> { pub fn uu_app<'a>() -> App<'a> {
clap::App::new(uucore::util_name()) App::new(uucore::util_name())
.version(crate_version!()) .version(crate_version!())
.about(ABOUT) .about(ABOUT)
.usage(USAGE) .override_usage(USAGE)
.after_help(LONG_HELP) .after_help(LONG_HELP)
.setting(
AppSettings::TrailingVarArg |
AppSettings::DontDelimitTrailingValues |
AppSettings::DeriveDisplayOrder
)
.arg( .arg(
Arg::with_name(options::ADDRESS_RADIX) Arg::new(options::ADDRESS_RADIX)
.short("A") .short('A')
.long(options::ADDRESS_RADIX) .long(options::ADDRESS_RADIX)
.help("Select the base in which file offsets are printed.") .help("Select the base in which file offsets are printed.")
.value_name("RADIX"), .value_name("RADIX"),
) )
.arg( .arg(
Arg::with_name(options::SKIP_BYTES) Arg::new(options::SKIP_BYTES)
.short("j") .short('j')
.long(options::SKIP_BYTES) .long(options::SKIP_BYTES)
.help("Skip bytes input bytes before formatting and writing.") .help("Skip bytes input bytes before formatting and writing.")
.value_name("BYTES"), .value_name("BYTES"),
) )
.arg( .arg(
Arg::with_name(options::READ_BYTES) Arg::new(options::READ_BYTES)
.short("N") .short('N')
.long(options::READ_BYTES) .long(options::READ_BYTES)
.help("limit dump to BYTES input bytes") .help("limit dump to BYTES input bytes")
.value_name("BYTES"), .value_name("BYTES"),
) )
.arg( .arg(
Arg::with_name(options::ENDIAN) Arg::new(options::ENDIAN)
.long(options::ENDIAN) .long(options::ENDIAN)
.help("byte order to use for multi-byte formats") .help("byte order to use for multi-byte formats")
.possible_values(&["big", "little"]) .possible_values(&["big", "little"])
.value_name("big|little"), .value_name("big|little"),
) )
.arg( .arg(
Arg::with_name(options::STRINGS) Arg::new(options::STRINGS)
.short("S") .short('S')
.long(options::STRINGS) .long(options::STRINGS)
.help( .help(
"NotImplemented: output strings of at least BYTES graphic chars. 3 is assumed when \ "NotImplemented: output strings of at least BYTES graphic chars. 3 is assumed when \
BYTES is not specified.", BYTES is not specified.",
) )
.default_value("3") .default_missing_value("3")
.value_name("BYTES"), .value_name("BYTES"),
) )
.arg( .arg(
Arg::with_name("a") Arg::new("a")
.short("a") .short('a')
.help("named characters, ignoring high-order bit") .help("named characters, ignoring high-order bit")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("b") Arg::new("b")
.short("b") .short('b')
.help("octal bytes") .help("octal bytes")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("c") Arg::new("c")
.short("c") .short('c')
.help("ASCII characters or backslash escapes") .help("ASCII characters or backslash escapes")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("d") Arg::new("d")
.short("d") .short('d')
.help("unsigned decimal 2-byte units") .help("unsigned decimal 2-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("D") Arg::new("D")
.short("D") .short('D')
.help("unsigned decimal 4-byte units") .help("unsigned decimal 4-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("o") Arg::new("o")
.short("o") .short('o')
.help("octal 2-byte units") .help("octal 2-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("I") Arg::new("I")
.short("I") .short('I')
.help("decimal 8-byte units") .help("decimal 8-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("L") Arg::new("L")
.short("L") .short('L')
.help("decimal 8-byte units") .help("decimal 8-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("i") Arg::new("i")
.short("i") .short('i')
.help("decimal 4-byte units") .help("decimal 4-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("l") Arg::new("l")
.short("l") .short('l')
.help("decimal 8-byte units") .help("decimal 8-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("x") Arg::new("x")
.short("x") .short('x')
.help("hexadecimal 2-byte units") .help("hexadecimal 2-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("h") Arg::new("h")
.short("h") .short('h')
.help("hexadecimal 2-byte units") .help("hexadecimal 2-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("O") Arg::new("O")
.short("O") .short('O')
.help("octal 4-byte units") .help("octal 4-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("s") Arg::new("s")
.short("s") .short('s')
.help("decimal 2-byte units") .help("decimal 2-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("X") Arg::new("X")
.short("X") .short('X')
.help("hexadecimal 4-byte units") .help("hexadecimal 4-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("H") Arg::new("H")
.short("H") .short('H')
.help("hexadecimal 4-byte units") .help("hexadecimal 4-byte units")
.multiple(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("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(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("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(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name("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(true) .multiple_occurrences(true)
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name(options::FORMAT) Arg::new(options::FORMAT)
.short("t") .short('t')
.long(options::FORMAT) .long("format")
.help("select output format or formats") .help("select output format or formats")
.multiple(true) .multiple_occurrences(true)
.number_of_values(1) .number_of_values(1)
.value_name("TYPE"), .value_name("TYPE"),
) )
.arg( .arg(
Arg::with_name(options::OUTPUT_DUPLICATES) Arg::new(options::OUTPUT_DUPLICATES)
.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) .takes_value(false),
.possible_values(&["big", "little"]),
) )
.arg( .arg(
Arg::with_name(options::WIDTH) Arg::new(options::WIDTH)
.short("w") .short('w')
.long(options::WIDTH) .long(options::WIDTH)
.help( .help(
"output BYTES bytes per output line. 32 is implied when BYTES is not \ "output BYTES bytes per output line. 32 is implied when BYTES is not \
specified.", specified.",
) )
.default_value("32") .default_missing_value("32")
.value_name("BYTES"), .value_name("BYTES"),
) )
.arg( .arg(
Arg::with_name(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), .takes_value(false),
) )
.arg( .arg(
Arg::with_name(options::FILENAME) Arg::new(options::FILENAME)
.hidden(true) .hide(true)
.multiple(true), .multiple_occurrences(true),
) )
.settings(&[
AppSettings::TrailingVarArg,
AppSettings::DontDelimitTrailingValues,
AppSettings::DisableVersion,
AppSettings::DeriveDisplayOrder,
])
} }
/// Loops through the input line by line, calling print_bytes to take care of the output. /// Loops through the input line by line, calling print_bytes to take care of the output.

View file

@ -10,7 +10,7 @@ pub trait CommandLineOpts {
} }
/// Implementation for `getopts` /// Implementation for `getopts`
impl<'a> CommandLineOpts for ArgMatches<'a> { impl<'a> CommandLineOpts for ArgMatches {
fn inputs(&self) -> Vec<&str> { fn inputs(&self) -> Vec<&str> {
self.values_of(options::FILENAME) self.values_of(options::FILENAME)
.map(|values| values.collect()) .map(|values| values.collect())
@ -53,7 +53,14 @@ pub fn parse_inputs(matches: &dyn CommandLineOpts) -> Result<CommandLineInputs,
// fall-through if no (valid) offset is found // fall-through if no (valid) offset is found
if input_strings.len() == 1 || input_strings.len() == 2 { if input_strings.len() == 1 || input_strings.len() == 2 {
// if any of the options -A, -j, -N, -t, -v or -w are present there is no offset // if any of the options -A, -j, -N, -t, -v or -w are present there is no offset
if !matches.opts_present(&["A", "j", "N", "t", "v", "w"]) { if !matches.opts_present(&[
options::ADDRESS_RADIX,
options::READ_BYTES,
options::READ_BYTES,
options::FORMAT,
options::OUTPUT_DUPLICATES,
options::WIDTH,
]) {
// test if the last input can be parsed as an offset. // test if the last input can be parsed as an offset.
let offset = parse_offset_operand(input_strings[input_strings.len() - 1]); let offset = parse_offset_operand(input_strings[input_strings.len() - 1]);
if let Ok(n) = offset { if let Ok(n) = offset {