mirror of
https://github.com/uutils/coreutils
synced 2025-01-07 10:49:09 +00:00
split: refactor handle_obsolete() function
This commit is contained in:
parent
2f35989ac3
commit
e79753c1cf
1 changed files with 40 additions and 33 deletions
|
@ -72,10 +72,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
/// `split -x300e -22 file` would mean `split -x -e -l 22 file` (last obsolete lines option wins)
|
/// `split -x300e -22 file` would mean `split -x -e -l 22 file` (last obsolete lines option wins)
|
||||||
/// following GNU `split` behavior
|
/// following GNU `split` behavior
|
||||||
fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
||||||
let mut v: Vec<String> = vec![];
|
|
||||||
let mut obs_lines = None;
|
let mut obs_lines = None;
|
||||||
for arg in args.iter() {
|
let filtered_args = args
|
||||||
let slice = &arg;
|
.iter()
|
||||||
|
.filter_map(|slice| {
|
||||||
if slice.starts_with('-') && !slice.starts_with("--") {
|
if slice.starts_with('-') && !slice.starts_with("--") {
|
||||||
// start of the short option string
|
// start of the short option string
|
||||||
// extract numeric part and filter it out
|
// extract numeric part and filter it out
|
||||||
|
@ -92,23 +92,30 @@ fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if filtered_slice.get(1).is_some() {
|
if obs_lines_extracted.is_empty() {
|
||||||
// there were some short options in front of obsolete lines number
|
// no obsolete lines value found/extracted
|
||||||
// i.e. '-xd100' or similar
|
Some(slice.to_owned())
|
||||||
// preserve it
|
} else {
|
||||||
v.push(filtered_slice.iter().collect());
|
|
||||||
}
|
|
||||||
if !obs_lines_extracted.is_empty() {
|
|
||||||
// obsolete lines value was extracted
|
// obsolete lines value was extracted
|
||||||
obs_lines = Some(obs_lines_extracted.iter().collect());
|
obs_lines = Some(obs_lines_extracted.iter().collect());
|
||||||
|
if filtered_slice.get(1).is_some() {
|
||||||
|
// there were some short options in front of or after obsolete lines value
|
||||||
|
// i.e. '-xd100' or '-100de' or similar, which after extraction of obsolete lines value
|
||||||
|
// would look like '-xd' or '-de' or similar
|
||||||
|
// preserve it
|
||||||
|
Some(filtered_slice.iter().collect())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// not a short option
|
// not a short option
|
||||||
// preserve it
|
// preserve it
|
||||||
v.push(arg.to_owned());
|
Some(slice.to_owned())
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
(v, obs_lines)
|
.collect();
|
||||||
|
(filtered_args, obs_lines)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app() -> Command {
|
pub fn uu_app() -> Command {
|
||||||
|
|
Loading…
Reference in a new issue