1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-03 06:27:45 +00:00

ptx: update to clap 4

This commit is contained in:
Terts Diepraam 2022-09-30 16:14:31 +02:00
parent aad802616b
commit 62b963a353
2 changed files with 27 additions and 33 deletions

View file

@ -15,7 +15,7 @@ edition = "2021"
path = "src/ptx.rs" path = "src/ptx.rs"
[dependencies] [dependencies]
clap = { version = "3.2", features = ["wrap_help", "cargo"] } clap = { version = "4.0", features = ["wrap_help", "cargo"] }
regex = "1.6.0" regex = "1.6.0"
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" } uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }

View file

@ -7,7 +7,7 @@
// spell-checker:ignore (ToDOs) corasick memchr Roff trunc oset iset CHARCLASS // spell-checker:ignore (ToDOs) corasick memchr Roff trunc oset iset CHARCLASS
use clap::{crate_version, Arg, Command}; use clap::{crate_version, Arg, ArgAction, Command};
use regex::Regex; use regex::Regex;
use std::cmp; use std::cmp;
use std::collections::{BTreeSet, HashMap, HashSet}; use std::collections::{BTreeSet, HashMap, HashSet};
@ -230,7 +230,7 @@ impl Display for PtxError {
fn get_config(matches: &clap::ArgMatches) -> UResult<Config> { fn get_config(matches: &clap::ArgMatches) -> UResult<Config> {
let mut config: Config = Default::default(); let mut config: Config = Default::default();
let err_msg = "parsing options failed"; let err_msg = "parsing options failed";
if matches.contains_id(options::TRADITIONAL) { if matches.get_flag(options::TRADITIONAL) {
config.gnu_ext = false; config.gnu_ext = false;
config.format = OutFormat::Roff; config.format = OutFormat::Roff;
config.context_regex = "[^ \t\n]+".to_owned(); config.context_regex = "[^ \t\n]+".to_owned();
@ -240,10 +240,10 @@ fn get_config(matches: &clap::ArgMatches) -> UResult<Config> {
if matches.contains_id(options::SENTENCE_REGEXP) { if matches.contains_id(options::SENTENCE_REGEXP) {
return Err(PtxError::NotImplemented("-S").into()); return Err(PtxError::NotImplemented("-S").into());
} }
config.auto_ref = matches.contains_id(options::AUTO_REFERENCE); config.auto_ref = matches.get_flag(options::AUTO_REFERENCE);
config.input_ref = matches.contains_id(options::REFERENCES); config.input_ref = matches.get_flag(options::REFERENCES);
config.right_ref &= matches.contains_id(options::RIGHT_SIDE_REFS); config.right_ref &= matches.get_flag(options::RIGHT_SIDE_REFS);
config.ignore_case = matches.contains_id(options::IGNORE_CASE); config.ignore_case = matches.get_flag(options::IGNORE_CASE);
if matches.contains_id(options::MACRO_NAME) { if matches.contains_id(options::MACRO_NAME) {
config.macro_name = matches config.macro_name = matches
.get_one::<String>(options::MACRO_NAME) .get_one::<String>(options::MACRO_NAME)
@ -270,10 +270,10 @@ fn get_config(matches: &clap::ArgMatches) -> UResult<Config> {
.parse() .parse()
.map_err(PtxError::ParseError)?; .map_err(PtxError::ParseError)?;
} }
if matches.contains_id(options::FORMAT_ROFF) { if matches.get_flag(options::FORMAT_ROFF) {
config.format = OutFormat::Roff; config.format = OutFormat::Roff;
} }
if matches.contains_id(options::FORMAT_TEX) { if matches.get_flag(options::FORMAT_TEX) {
config.format = OutFormat::Tex; config.format = OutFormat::Tex;
} }
Ok(config) Ok(config)
@ -745,7 +745,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
write_traditional_output(&config, &file_map, &word_set, &output_file) write_traditional_output(&config, &file_map, &word_set, &output_file)
} }
pub fn uu_app<'a>() -> Command<'a> { pub fn uu_app() -> Command {
Command::new(uucore::util_name()) Command::new(uucore::util_name())
.name(NAME) .name(NAME)
.about(ABOUT) .about(ABOUT)
@ -755,7 +755,7 @@ pub fn uu_app<'a>() -> Command<'a> {
.arg( .arg(
Arg::new(options::FILE) Arg::new(options::FILE)
.hide(true) .hide(true)
.multiple_occurrences(true) .action(ArgAction::Append)
.value_hint(clap::ValueHint::FilePath), .value_hint(clap::ValueHint::FilePath),
) )
.arg( .arg(
@ -763,64 +763,63 @@ pub fn uu_app<'a>() -> Command<'a> {
.short('A') .short('A')
.long(options::AUTO_REFERENCE) .long(options::AUTO_REFERENCE)
.help("output automatically generated references") .help("output automatically generated references")
.takes_value(false), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::TRADITIONAL) Arg::new(options::TRADITIONAL)
.short('G') .short('G')
.long(options::TRADITIONAL) .long(options::TRADITIONAL)
.help("behave more like System V 'ptx'"), .help("behave more like System V 'ptx'")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::FLAG_TRUNCATION) Arg::new(options::FLAG_TRUNCATION)
.short('F') .short('F')
.long(options::FLAG_TRUNCATION) .long(options::FLAG_TRUNCATION)
.help("use STRING for flagging line truncations") .help("use STRING for flagging line truncations")
.value_name("STRING") .value_name("STRING"),
.takes_value(true),
) )
.arg( .arg(
Arg::new(options::MACRO_NAME) Arg::new(options::MACRO_NAME)
.short('M') .short('M')
.long(options::MACRO_NAME) .long(options::MACRO_NAME)
.help("macro name to use instead of 'xx'") .help("macro name to use instead of 'xx'")
.value_name("STRING") .value_name("STRING"),
.takes_value(true),
) )
.arg( .arg(
Arg::new(options::FORMAT_ROFF) Arg::new(options::FORMAT_ROFF)
.short('O') .short('O')
.long(options::FORMAT_ROFF) .long(options::FORMAT_ROFF)
.help("generate output as roff directives"), .help("generate output as roff directives")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::RIGHT_SIDE_REFS) Arg::new(options::RIGHT_SIDE_REFS)
.short('R') .short('R')
.long(options::RIGHT_SIDE_REFS) .long(options::RIGHT_SIDE_REFS)
.help("put references at right, not counted in -w") .help("put references at right, not counted in -w")
.takes_value(false), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::SENTENCE_REGEXP) Arg::new(options::SENTENCE_REGEXP)
.short('S') .short('S')
.long(options::SENTENCE_REGEXP) .long(options::SENTENCE_REGEXP)
.help("for end of lines or end of sentences") .help("for end of lines or end of sentences")
.value_name("REGEXP") .value_name("REGEXP"),
.takes_value(true),
) )
.arg( .arg(
Arg::new(options::FORMAT_TEX) Arg::new(options::FORMAT_TEX)
.short('T') .short('T')
.long(options::FORMAT_TEX) .long(options::FORMAT_TEX)
.help("generate output as TeX directives"), .help("generate output as TeX directives")
.action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::WORD_REGEXP) Arg::new(options::WORD_REGEXP)
.short('W') .short('W')
.long(options::WORD_REGEXP) .long(options::WORD_REGEXP)
.help("use REGEXP to match each keyword") .help("use REGEXP to match each keyword")
.value_name("REGEXP") .value_name("REGEXP"),
.takes_value(true),
) )
.arg( .arg(
Arg::new(options::BREAK_FILE) Arg::new(options::BREAK_FILE)
@ -828,7 +827,6 @@ pub fn uu_app<'a>() -> Command<'a> {
.long(options::BREAK_FILE) .long(options::BREAK_FILE)
.help("word break characters in this FILE") .help("word break characters in this FILE")
.value_name("FILE") .value_name("FILE")
.takes_value(true)
.value_hint(clap::ValueHint::FilePath), .value_hint(clap::ValueHint::FilePath),
) )
.arg( .arg(
@ -836,15 +834,14 @@ pub fn uu_app<'a>() -> Command<'a> {
.short('f') .short('f')
.long(options::IGNORE_CASE) .long(options::IGNORE_CASE)
.help("fold lower case to upper case for sorting") .help("fold lower case to upper case for sorting")
.takes_value(false), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::GAP_SIZE) Arg::new(options::GAP_SIZE)
.short('g') .short('g')
.long(options::GAP_SIZE) .long(options::GAP_SIZE)
.help("gap size in columns between output fields") .help("gap size in columns between output fields")
.value_name("NUMBER") .value_name("NUMBER"),
.takes_value(true),
) )
.arg( .arg(
Arg::new(options::IGNORE_FILE) Arg::new(options::IGNORE_FILE)
@ -852,7 +849,6 @@ pub fn uu_app<'a>() -> Command<'a> {
.long(options::IGNORE_FILE) .long(options::IGNORE_FILE)
.help("read ignore word list from FILE") .help("read ignore word list from FILE")
.value_name("FILE") .value_name("FILE")
.takes_value(true)
.value_hint(clap::ValueHint::FilePath), .value_hint(clap::ValueHint::FilePath),
) )
.arg( .arg(
@ -861,7 +857,6 @@ pub fn uu_app<'a>() -> Command<'a> {
.long(options::ONLY_FILE) .long(options::ONLY_FILE)
.help("read only word list from this FILE") .help("read only word list from this FILE")
.value_name("FILE") .value_name("FILE")
.takes_value(true)
.value_hint(clap::ValueHint::FilePath), .value_hint(clap::ValueHint::FilePath),
) )
.arg( .arg(
@ -870,14 +865,13 @@ pub fn uu_app<'a>() -> Command<'a> {
.long(options::REFERENCES) .long(options::REFERENCES)
.help("first field of each line is a reference") .help("first field of each line is a reference")
.value_name("FILE") .value_name("FILE")
.takes_value(false), .action(ArgAction::SetTrue),
) )
.arg( .arg(
Arg::new(options::WIDTH) Arg::new(options::WIDTH)
.short('w') .short('w')
.long(options::WIDTH) .long(options::WIDTH)
.help("output width in columns, reference excluded") .help("output width in columns, reference excluded")
.value_name("NUMBER") .value_name("NUMBER"),
.takes_value(true),
) )
} }