mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
remove cut-specific macros
This commit is contained in:
+5
-22
@@ -466,12 +466,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
delim = "=";
|
||||
}
|
||||
if delim.chars().count() > 1 {
|
||||
Err(msg_opt_invalid_should_be!(
|
||||
"empty or 1 character long",
|
||||
"a value 2 characters or longer",
|
||||
"--delimiter",
|
||||
"-d"
|
||||
))
|
||||
Err("invalid input: The '--delimiter' ('-d') option expects empty or 1 character long, but was provided a value 2 characters or longer".into())
|
||||
} else {
|
||||
let delim = if delim.is_empty() {
|
||||
"\0".to_owned()
|
||||
@@ -503,13 +498,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
})
|
||||
}
|
||||
(ref b, ref c, ref f) if b.is_some() || c.is_some() || f.is_some() => Err(
|
||||
msg_expects_no_more_than_one_of!("--fields (-f)", "--chars (-c)", "--bytes (-b)"),
|
||||
"invalid usage: expects no more than one of --fields (-f), --chars (-c) or --bytes (-b)".into()
|
||||
),
|
||||
_ => Err(msg_expects_one_of!(
|
||||
"--fields (-f)",
|
||||
"--chars (-c)",
|
||||
"--bytes (-b)"
|
||||
)),
|
||||
_ => Err("invalid usage: expects one of --fields (-f), --chars (-c) or --bytes (-b)".into()),
|
||||
};
|
||||
|
||||
let mode_parse = match mode_parse {
|
||||
@@ -518,20 +509,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
Mode::Bytes(_, _) | Mode::Characters(_, _)
|
||||
if matches.is_present(options::DELIMITER) =>
|
||||
{
|
||||
Err(msg_opt_only_usable_if!(
|
||||
"printing a sequence of fields",
|
||||
"--delimiter",
|
||||
"-d"
|
||||
))
|
||||
Err("invalid input: The '--delimiter' ('-d') option only usable if printing a sequence of fields".into())
|
||||
}
|
||||
Mode::Bytes(_, _) | Mode::Characters(_, _)
|
||||
if matches.is_present(options::ONLY_DELIMITED) =>
|
||||
{
|
||||
Err(msg_opt_only_usable_if!(
|
||||
"printing a sequence of fields",
|
||||
"--only-delimited",
|
||||
"-s"
|
||||
))
|
||||
Err("invalid input: The '--only-delimited' ('-s') option only usable if printing a sequence of fields".into())
|
||||
}
|
||||
_ => Ok(mode),
|
||||
},
|
||||
|
||||
@@ -274,104 +274,3 @@ macro_rules! crash_if_err(
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
//-- message templates
|
||||
|
||||
//-- message templates : (join utility sub-macros)
|
||||
|
||||
// used only by "cut"
|
||||
#[macro_export]
|
||||
macro_rules! snippet_list_join_oxford_comma {
|
||||
($conjunction:expr, $valOne:expr, $valTwo:expr) => (
|
||||
format!("{}, {} {}", $valOne, $conjunction, $valTwo)
|
||||
);
|
||||
($conjunction:expr, $valOne:expr, $valTwo:expr $(, $remaining_values:expr)*) => (
|
||||
format!("{}, {}", $valOne, $crate::snippet_list_join_oxford_comma!($conjunction, $valTwo $(, $remaining_values)*))
|
||||
);
|
||||
}
|
||||
|
||||
// used only by "cut"
|
||||
#[macro_export]
|
||||
macro_rules! snippet_list_join {
|
||||
($conjunction:expr, $valOne:expr, $valTwo:expr) => (
|
||||
format!("{} {} {}", $valOne, $conjunction, $valTwo)
|
||||
);
|
||||
($conjunction:expr, $valOne:expr, $valTwo:expr $(, $remaining_values:expr)*) => (
|
||||
format!("{}, {}", $valOne, $crate::snippet_list_join_oxford_comma!($conjunction, $valTwo $(, $remaining_values)*))
|
||||
);
|
||||
}
|
||||
|
||||
//-- message templates : invalid input
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_invalid_input {
|
||||
($reason: expr) => {
|
||||
format!("invalid input: {}", $reason)
|
||||
};
|
||||
}
|
||||
|
||||
// -- message templates : invalid input : flag
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! msg_invalid_opt_use {
|
||||
($about:expr, $flag:expr) => {
|
||||
$crate::msg_invalid_input!(format!("The '{}' option {}", $flag, $about))
|
||||
};
|
||||
($about:expr, $long_flag:expr, $short_flag:expr) => {
|
||||
$crate::msg_invalid_input!(format!(
|
||||
"The '{}' ('{}') option {}",
|
||||
$long_flag, $short_flag, $about
|
||||
))
|
||||
};
|
||||
}
|
||||
|
||||
// Only used by "cut"
|
||||
#[macro_export]
|
||||
macro_rules! msg_opt_only_usable_if {
|
||||
($clause:expr, $flag:expr) => {
|
||||
$crate::msg_invalid_opt_use!(format!("only usable if {}", $clause), $flag)
|
||||
};
|
||||
($clause:expr, $long_flag:expr, $short_flag:expr) => {
|
||||
$crate::msg_invalid_opt_use!(
|
||||
format!("only usable if {}", $clause),
|
||||
$long_flag,
|
||||
$short_flag
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
// Used only by "cut"
|
||||
#[macro_export]
|
||||
macro_rules! msg_opt_invalid_should_be {
|
||||
($expects:expr, $received:expr, $flag:expr) => {
|
||||
$crate::msg_invalid_opt_use!(
|
||||
format!("expects {}, but was provided {}", $expects, $received),
|
||||
$flag
|
||||
)
|
||||
};
|
||||
($expects:expr, $received:expr, $long_flag:expr, $short_flag:expr) => {
|
||||
$crate::msg_invalid_opt_use!(
|
||||
format!("expects {}, but was provided {}", $expects, $received),
|
||||
$long_flag,
|
||||
$short_flag
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
// -- message templates : invalid input : input combinations
|
||||
|
||||
// UNUSED!
|
||||
#[macro_export]
|
||||
macro_rules! msg_expects_one_of {
|
||||
($valOne:expr $(, $remaining_values:expr)*) => (
|
||||
$crate::msg_invalid_input!(format!("expects one of {}", $crate::snippet_list_join!("or", $valOne $(, $remaining_values)*)))
|
||||
);
|
||||
}
|
||||
|
||||
// Used only by "cut"
|
||||
#[macro_export]
|
||||
macro_rules! msg_expects_no_more_than_one_of {
|
||||
($valOne:expr $(, $remaining_values:expr)*) => (
|
||||
$crate::msg_invalid_input!(format!("expects no more than one of {}", $crate::snippet_list_join!("or", $valOne $(, $remaining_values)*))) ;
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user