mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 23:32:39 +00:00
cat: update to clap 4
This commit is contained in:
parent
649dab36f1
commit
717402b46a
2 changed files with 28 additions and 19 deletions
|
@ -15,7 +15,7 @@ edition = "2021"
|
||||||
path = "src/cat.rs"
|
path = "src/cat.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "3.2", features = ["wrap_help", "cargo"] }
|
clap = { version = "4.0", features = ["wrap_help", "cargo"] }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
atty = "0.2"
|
atty = "0.2"
|
||||||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["fs", "pipes"] }
|
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["fs", "pipes"] }
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// spell-checker:ignore (ToDO) nonprint nonblank nonprinting
|
// spell-checker:ignore (ToDO) nonprint nonblank nonprinting
|
||||||
|
|
||||||
// last synced with: cat (GNU coreutils) 8.13
|
// last synced with: cat (GNU coreutils) 8.13
|
||||||
use clap::{crate_version, Arg, Command};
|
use clap::{crate_version, Arg, ArgAction, Command};
|
||||||
use std::fs::{metadata, File};
|
use std::fs::{metadata, File};
|
||||||
use std::io::{self, Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
@ -185,9 +185,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
|
||||||
let matches = uu_app().try_get_matches_from(args)?;
|
let matches = uu_app().try_get_matches_from(args)?;
|
||||||
|
|
||||||
let number_mode = if matches.contains_id(options::NUMBER_NONBLANK) {
|
let number_mode = if matches.get_flag(options::NUMBER_NONBLANK) {
|
||||||
NumberingMode::NonEmpty
|
NumberingMode::NonEmpty
|
||||||
} else if matches.contains_id(options::NUMBER) {
|
} else if matches.get_flag(options::NUMBER) {
|
||||||
NumberingMode::All
|
NumberingMode::All
|
||||||
} else {
|
} else {
|
||||||
NumberingMode::None
|
NumberingMode::None
|
||||||
|
@ -200,7 +200,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
options::SHOW_NONPRINTING.to_owned(),
|
options::SHOW_NONPRINTING.to_owned(),
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.any(|v| matches.contains_id(v));
|
.any(|v| matches.get_flag(v));
|
||||||
|
|
||||||
let show_ends = vec![
|
let show_ends = vec![
|
||||||
options::SHOW_ENDS.to_owned(),
|
options::SHOW_ENDS.to_owned(),
|
||||||
|
@ -208,7 +208,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
options::SHOW_NONPRINTING_ENDS.to_owned(),
|
options::SHOW_NONPRINTING_ENDS.to_owned(),
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.any(|v| matches.contains_id(v));
|
.any(|v| matches.get_flag(v));
|
||||||
|
|
||||||
let show_tabs = vec![
|
let show_tabs = vec![
|
||||||
options::SHOW_ALL.to_owned(),
|
options::SHOW_ALL.to_owned(),
|
||||||
|
@ -216,9 +216,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
options::SHOW_NONPRINTING_TABS.to_owned(),
|
options::SHOW_NONPRINTING_TABS.to_owned(),
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
.any(|v| matches.contains_id(v));
|
.any(|v| matches.get_flag(v));
|
||||||
|
|
||||||
let squeeze_blank = matches.contains_id(options::SQUEEZE_BLANK);
|
let squeeze_blank = matches.get_flag(options::SQUEEZE_BLANK);
|
||||||
let files: Vec<String> = match matches.get_many::<String>(options::FILE) {
|
let files: Vec<String> = match matches.get_many::<String>(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_owned()],
|
None => vec!["-".to_owned()],
|
||||||
|
@ -234,7 +234,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
cat_files(&files, &options)
|
cat_files(&files, &options)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
|
@ -244,62 +244,71 @@ 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(clap::ArgAction::Append)
|
||||||
.value_hint(clap::ValueHint::FilePath),
|
.value_hint(clap::ValueHint::FilePath),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::SHOW_ALL)
|
Arg::new(options::SHOW_ALL)
|
||||||
.short('A')
|
.short('A')
|
||||||
.long(options::SHOW_ALL)
|
.long(options::SHOW_ALL)
|
||||||
.help("equivalent to -vET"),
|
.help("equivalent to -vET")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::NUMBER_NONBLANK)
|
Arg::new(options::NUMBER_NONBLANK)
|
||||||
.short('b')
|
.short('b')
|
||||||
.long(options::NUMBER_NONBLANK)
|
.long(options::NUMBER_NONBLANK)
|
||||||
.help("number nonempty output lines, overrides -n")
|
.help("number nonempty output lines, overrides -n")
|
||||||
.overrides_with(options::NUMBER),
|
.overrides_with(options::NUMBER)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::SHOW_NONPRINTING_ENDS)
|
Arg::new(options::SHOW_NONPRINTING_ENDS)
|
||||||
.short('e')
|
.short('e')
|
||||||
.help("equivalent to -vE"),
|
.help("equivalent to -vE")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::SHOW_ENDS)
|
Arg::new(options::SHOW_ENDS)
|
||||||
.short('E')
|
.short('E')
|
||||||
.long(options::SHOW_ENDS)
|
.long(options::SHOW_ENDS)
|
||||||
.help("display $ at end of each line"),
|
.help("display $ at end of each line")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::NUMBER)
|
Arg::new(options::NUMBER)
|
||||||
.short('n')
|
.short('n')
|
||||||
.long(options::NUMBER)
|
.long(options::NUMBER)
|
||||||
.help("number all output lines"),
|
.help("number all output lines")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::SQUEEZE_BLANK)
|
Arg::new(options::SQUEEZE_BLANK)
|
||||||
.short('s')
|
.short('s')
|
||||||
.long(options::SQUEEZE_BLANK)
|
.long(options::SQUEEZE_BLANK)
|
||||||
.help("suppress repeated empty output lines"),
|
.help("suppress repeated empty output lines")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::SHOW_NONPRINTING_TABS)
|
Arg::new(options::SHOW_NONPRINTING_TABS)
|
||||||
.short('t')
|
.short('t')
|
||||||
.long(options::SHOW_NONPRINTING_TABS)
|
.long(options::SHOW_NONPRINTING_TABS)
|
||||||
.help("equivalent to -vT"),
|
.help("equivalent to -vT")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::SHOW_TABS)
|
Arg::new(options::SHOW_TABS)
|
||||||
.short('T')
|
.short('T')
|
||||||
.long(options::SHOW_TABS)
|
.long(options::SHOW_TABS)
|
||||||
.help("display TAB characters at ^I"),
|
.help("display TAB characters at ^I")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::SHOW_NONPRINTING)
|
Arg::new(options::SHOW_NONPRINTING)
|
||||||
.short('v')
|
.short('v')
|
||||||
.long(options::SHOW_NONPRINTING)
|
.long(options::SHOW_NONPRINTING)
|
||||||
.help("use ^ and M- notation, except for LF (\\n) and TAB (\\t)"),
|
.help("use ^ and M- notation, except for LF (\\n) and TAB (\\t)")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue