1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 13:07:46 +00:00

ptx: clap 3

This commit is contained in:
Terts Diepraam 2022-01-11 14:37:09 +01:00
parent b94809197f
commit 24dc4d9037
2 changed files with 44 additions and 40 deletions

View file

@ -15,7 +15,7 @@ edition = "2018"
path = "src/ptx.rs" path = "src/ptx.rs"
[dependencies] [dependencies]
clap = { version = "2.33", features = ["wrap_help"] } clap = { version = "3.0", features = ["wrap_help", "cargo"] }
aho-corasick = "0.7.3" aho-corasick = "0.7.3"
libc = "0.2.42" libc = "0.2.42"
memchr = "2.2.0" memchr = "2.2.0"

View file

@ -683,7 +683,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
// let mut opts = Options::new(); // let mut opts = Options::new();
let matches = uu_app().get_matches_from(args); let matches = uu_app().get_matches_from(args);
let input_files: Vec<String> = match &matches.values_of(options::FILE) { let mut input_files: Vec<String> = match &matches.values_of(options::FILE) {
Some(v) => v.clone().map(|v| v.to_owned()).collect(), Some(v) => v.clone().map(|v| v.to_owned()).collect(),
None => vec!["-".to_string()], None => vec!["-".to_string()],
}; };
@ -692,134 +692,138 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let word_filter = WordFilter::new(&matches, &config)?; let word_filter = WordFilter::new(&matches, &config)?;
let file_map = read_input(&input_files, &config).map_err_context(String::new)?; let file_map = read_input(&input_files, &config).map_err_context(String::new)?;
let word_set = create_word_set(&config, &word_filter, &file_map); let word_set = create_word_set(&config, &word_filter, &file_map);
let output_file = if !config.gnu_ext && matches.args.len() == 2 { let output_file = if !config.gnu_ext && input_files.len() == 2 {
matches.value_of(options::FILE).unwrap_or("-").to_string() input_files.pop().unwrap()
} else { } else {
"-".to_owned() "-".to_string()
}; };
write_traditional_output(&config, &file_map, &word_set, &output_file) write_traditional_output(&config, &file_map, &word_set, &output_file)
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app<'a>() -> App<'a> {
App::new(uucore::util_name()) App::new(uucore::util_name())
.name(NAME) .name(NAME)
.version(crate_version!()) .version(crate_version!())
.usage(BRIEF) .override_usage(BRIEF)
.arg(Arg::with_name(options::FILE).hidden(true).multiple(true))
.arg( .arg(
Arg::with_name(options::AUTO_REFERENCE) Arg::new(options::FILE)
.short("A") .hide(true)
.multiple_occurrences(true),
)
.arg(
Arg::new(options::AUTO_REFERENCE)
.short('A')
.long(options::AUTO_REFERENCE) .long(options::AUTO_REFERENCE)
.help("output automatically generated references") .help("output automatically generated references")
.takes_value(false), .takes_value(false),
) )
.arg( .arg(
Arg::with_name(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'"),
) )
.arg( .arg(
Arg::with_name(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), .takes_value(true),
) )
.arg( .arg(
Arg::with_name(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), .takes_value(true),
) )
.arg( .arg(
Arg::with_name(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"),
) )
.arg( .arg(
Arg::with_name(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), .takes_value(false),
) )
.arg( .arg(
Arg::with_name(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), .takes_value(true),
) )
.arg( .arg(
Arg::with_name(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"),
) )
.arg( .arg(
Arg::with_name(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), .takes_value(true),
) )
.arg( .arg(
Arg::with_name(options::BREAK_FILE) Arg::new(options::BREAK_FILE)
.short("b") .short('b')
.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), .takes_value(true),
) )
.arg( .arg(
Arg::with_name(options::IGNORE_CASE) Arg::new(options::IGNORE_CASE)
.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), .takes_value(false),
) )
.arg( .arg(
Arg::with_name(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), .takes_value(true),
) )
.arg( .arg(
Arg::with_name(options::IGNORE_FILE) Arg::new(options::IGNORE_FILE)
.short("i") .short('i')
.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), .takes_value(true),
) )
.arg( .arg(
Arg::with_name(options::ONLY_FILE) Arg::new(options::ONLY_FILE)
.short("o") .short('o')
.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), .takes_value(true),
) )
.arg( .arg(
Arg::with_name(options::REFERENCES) Arg::new(options::REFERENCES)
.short("r") .short('r')
.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), .takes_value(false),
) )
.arg( .arg(
Arg::with_name(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")