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