mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
tail: update to clap 4
This commit is contained in:
parent
0611bd6fda
commit
c8536c0985
2 changed files with 31 additions and 30 deletions
|
@ -16,7 +16,7 @@ edition = "2021"
|
||||||
path = "src/tail.rs"
|
path = "src/tail.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "3.2", features = ["wrap_help", "cargo"] }
|
clap = { version = "4.0", features = ["wrap_help", "cargo"] }
|
||||||
libc = "0.2.135"
|
libc = "0.2.135"
|
||||||
memchr = "2.5.0"
|
memchr = "2.5.0"
|
||||||
notify = { version = "=5.0.0", features=["macos_kqueue"]}
|
notify = { version = "=5.0.0", features=["macos_kqueue"]}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
use crate::paths::Input;
|
use crate::paths::Input;
|
||||||
use crate::{parse, platform, Quotable};
|
use crate::{parse, platform, Quotable};
|
||||||
use clap::{Arg, ArgMatches, Command, ValueSource};
|
use clap::{parser::ValueSource, Arg, ArgAction, ArgMatches, Command};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -62,7 +62,7 @@ pub enum FilterMode {
|
||||||
|
|
||||||
impl FilterMode {
|
impl FilterMode {
|
||||||
fn from(matches: &ArgMatches) -> UResult<Self> {
|
fn from(matches: &ArgMatches) -> UResult<Self> {
|
||||||
let zero_term = matches.contains_id(options::ZERO_TERM);
|
let zero_term = matches.get_flag(options::ZERO_TERM);
|
||||||
let mode = if let Some(arg) = matches.get_one::<String>(options::BYTES) {
|
let mode = if let Some(arg) = matches.get_one::<String>(options::BYTES) {
|
||||||
match parse_num(arg) {
|
match parse_num(arg) {
|
||||||
Ok(signum) => Self::Bytes(signum),
|
Ok(signum) => Self::Bytes(signum),
|
||||||
|
@ -134,7 +134,7 @@ impl Settings {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
settings.follow = if matches.contains_id(options::FOLLOW_RETRY) {
|
settings.follow = if matches.get_flag(options::FOLLOW_RETRY) {
|
||||||
Some(FollowMode::Name)
|
Some(FollowMode::Name)
|
||||||
} else if matches.value_source(options::FOLLOW) != Some(ValueSource::CommandLine) {
|
} else if matches.value_source(options::FOLLOW) != Some(ValueSource::CommandLine) {
|
||||||
None
|
None
|
||||||
|
@ -146,7 +146,7 @@ impl Settings {
|
||||||
};
|
};
|
||||||
|
|
||||||
settings.retry =
|
settings.retry =
|
||||||
matches.contains_id(options::RETRY) || matches.contains_id(options::FOLLOW_RETRY);
|
matches.get_flag(options::RETRY) || matches.get_flag(options::FOLLOW_RETRY);
|
||||||
|
|
||||||
if settings.retry && settings.follow.is_none() {
|
if settings.retry && settings.follow.is_none() {
|
||||||
show_warning!("--retry ignored; --retry is useful only when following");
|
show_warning!("--retry ignored; --retry is useful only when following");
|
||||||
|
@ -164,7 +164,7 @@ impl Settings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.use_polling = matches.contains_id(options::USE_POLLING);
|
settings.use_polling = matches.get_flag(options::USE_POLLING);
|
||||||
|
|
||||||
if let Some(s) = matches.get_one::<String>(options::MAX_UNCHANGED_STATS) {
|
if let Some(s) = matches.get_one::<String>(options::MAX_UNCHANGED_STATS) {
|
||||||
settings.max_unchanged_stats = match s.parse::<u32>() {
|
settings.max_unchanged_stats = match s.parse::<u32>() {
|
||||||
|
@ -233,12 +233,12 @@ impl Settings {
|
||||||
inputs.push_front(Input::default());
|
inputs.push_front(Input::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.verbose = (matches.contains_id(options::verbosity::VERBOSE) || inputs.len() > 1)
|
settings.verbose = (matches.get_flag(options::verbosity::VERBOSE) || inputs.len() > 1)
|
||||||
&& !matches.contains_id(options::verbosity::QUIET);
|
&& !matches.get_flag(options::verbosity::QUIET);
|
||||||
|
|
||||||
settings.inputs = inputs;
|
settings.inputs = inputs;
|
||||||
|
|
||||||
settings.presume_input_pipe = matches.contains_id(options::PRESUME_INPUT_PIPE);
|
settings.presume_input_pipe = matches.get_flag(options::PRESUME_INPUT_PIPE);
|
||||||
|
|
||||||
Ok(settings)
|
Ok(settings)
|
||||||
}
|
}
|
||||||
|
@ -315,7 +315,7 @@ pub fn parse_args(args: impl uucore::Args) -> UResult<Settings> {
|
||||||
Settings::from(&matches)
|
Settings::from(&matches)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app<'a>() -> Command<'a> {
|
pub fn uu_app() -> Command {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub static POLLING_HELP: &str = "Disable 'inotify' support and use polling instead";
|
pub static POLLING_HELP: &str = "Disable 'inotify' support and use polling instead";
|
||||||
#[cfg(all(unix, not(target_os = "linux")))]
|
#[cfg(all(unix, not(target_os = "linux")))]
|
||||||
|
@ -333,7 +333,6 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
Arg::new(options::BYTES)
|
Arg::new(options::BYTES)
|
||||||
.short('c')
|
.short('c')
|
||||||
.long(options::BYTES)
|
.long(options::BYTES)
|
||||||
.takes_value(true)
|
|
||||||
.allow_hyphen_values(true)
|
.allow_hyphen_values(true)
|
||||||
.overrides_with_all(&[options::BYTES, options::LINES])
|
.overrides_with_all(&[options::BYTES, options::LINES])
|
||||||
.help("Number of bytes to print"),
|
.help("Number of bytes to print"),
|
||||||
|
@ -343,9 +342,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.short('f')
|
.short('f')
|
||||||
.long(options::FOLLOW)
|
.long(options::FOLLOW)
|
||||||
.default_value("descriptor")
|
.default_value("descriptor")
|
||||||
.takes_value(true)
|
.num_args(0..=1)
|
||||||
.min_values(0)
|
|
||||||
.max_values(1)
|
|
||||||
.require_equals(true)
|
.require_equals(true)
|
||||||
.value_parser(["descriptor", "name"])
|
.value_parser(["descriptor", "name"])
|
||||||
.help("Print the file as it grows"),
|
.help("Print the file as it grows"),
|
||||||
|
@ -354,7 +351,6 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
Arg::new(options::LINES)
|
Arg::new(options::LINES)
|
||||||
.short('n')
|
.short('n')
|
||||||
.long(options::LINES)
|
.long(options::LINES)
|
||||||
.takes_value(true)
|
|
||||||
.allow_hyphen_values(true)
|
.allow_hyphen_values(true)
|
||||||
.overrides_with_all(&[options::BYTES, options::LINES])
|
.overrides_with_all(&[options::BYTES, options::LINES])
|
||||||
.help("Number of lines to print"),
|
.help("Number of lines to print"),
|
||||||
|
@ -362,7 +358,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::PID)
|
Arg::new(options::PID)
|
||||||
.long(options::PID)
|
.long(options::PID)
|
||||||
.takes_value(true)
|
.value_name("PID")
|
||||||
.help("With -f, terminate after process ID, PID dies"),
|
.help("With -f, terminate after process ID, PID dies"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
@ -371,18 +367,19 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.long(options::verbosity::QUIET)
|
.long(options::verbosity::QUIET)
|
||||||
.visible_alias("silent")
|
.visible_alias("silent")
|
||||||
.overrides_with_all(&[options::verbosity::QUIET, options::verbosity::VERBOSE])
|
.overrides_with_all(&[options::verbosity::QUIET, options::verbosity::VERBOSE])
|
||||||
.help("Never output headers giving file names"),
|
.help("Never output headers giving file names")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::SLEEP_INT)
|
Arg::new(options::SLEEP_INT)
|
||||||
.short('s')
|
.short('s')
|
||||||
.takes_value(true)
|
.value_name("N")
|
||||||
.long(options::SLEEP_INT)
|
.long(options::SLEEP_INT)
|
||||||
.help("Number of seconds to sleep between polling the file when running with -f"),
|
.help("Number of seconds to sleep between polling the file when running with -f"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::MAX_UNCHANGED_STATS)
|
Arg::new(options::MAX_UNCHANGED_STATS)
|
||||||
.takes_value(true)
|
.value_name("N")
|
||||||
.long(options::MAX_UNCHANGED_STATS)
|
.long(options::MAX_UNCHANGED_STATS)
|
||||||
.help(
|
.help(
|
||||||
"Reopen a FILE which has not changed size after N (default 5) iterations \
|
"Reopen a FILE which has not changed size after N (default 5) iterations \
|
||||||
|
@ -396,44 +393,48 @@ pub fn uu_app<'a>() -> Command<'a> {
|
||||||
.short('v')
|
.short('v')
|
||||||
.long(options::verbosity::VERBOSE)
|
.long(options::verbosity::VERBOSE)
|
||||||
.overrides_with_all(&[options::verbosity::QUIET, options::verbosity::VERBOSE])
|
.overrides_with_all(&[options::verbosity::QUIET, options::verbosity::VERBOSE])
|
||||||
.help("Always output headers giving file names"),
|
.help("Always output headers giving file names")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::ZERO_TERM)
|
Arg::new(options::ZERO_TERM)
|
||||||
.short('z')
|
.short('z')
|
||||||
.long(options::ZERO_TERM)
|
.long(options::ZERO_TERM)
|
||||||
.help("Line delimiter is NUL, not newline"),
|
.help("Line delimiter is NUL, not newline")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::USE_POLLING)
|
Arg::new(options::USE_POLLING)
|
||||||
.alias(options::DISABLE_INOTIFY_TERM) // NOTE: Used by GNU's test suite
|
.alias(options::DISABLE_INOTIFY_TERM) // NOTE: Used by GNU's test suite
|
||||||
.alias("dis") // NOTE: Used by GNU's test suite
|
.alias("dis") // NOTE: Used by GNU's test suite
|
||||||
.long(options::USE_POLLING)
|
.long(options::USE_POLLING)
|
||||||
.help(POLLING_HELP),
|
.help(POLLING_HELP)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::RETRY)
|
Arg::new(options::RETRY)
|
||||||
.long(options::RETRY)
|
.long(options::RETRY)
|
||||||
.help("Keep trying to open a file if it is inaccessible"),
|
.help("Keep trying to open a file if it is inaccessible")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::FOLLOW_RETRY)
|
Arg::new(options::FOLLOW_RETRY)
|
||||||
.short('F')
|
.short('F')
|
||||||
.help("Same as --follow=name --retry")
|
.help("Same as --follow=name --retry")
|
||||||
.overrides_with_all(&[options::RETRY, options::FOLLOW]),
|
.overrides_with_all(&[options::RETRY, options::FOLLOW])
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::PRESUME_INPUT_PIPE)
|
Arg::new(options::PRESUME_INPUT_PIPE)
|
||||||
.long(options::PRESUME_INPUT_PIPE)
|
.long("presume-input-pipe")
|
||||||
.alias(options::PRESUME_INPUT_PIPE)
|
.alias(options::PRESUME_INPUT_PIPE)
|
||||||
.hide(true),
|
.hide(true)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::ARG_FILES)
|
Arg::new(options::ARG_FILES)
|
||||||
.multiple_occurrences(true)
|
.action(ArgAction::Append)
|
||||||
.takes_value(true)
|
.num_args(1..)
|
||||||
.min_values(1)
|
|
||||||
.value_hint(clap::ValueHint::FilePath),
|
.value_hint(clap::ValueHint::FilePath),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue