mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Add additional-suffix option to split
This commit is contained in:
parent
2ff6b67077
commit
5a75905476
2 changed files with 32 additions and 3 deletions
|
@ -43,6 +43,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|||
"numeric-suffixes",
|
||||
"use numeric suffixes instead of alphabetic",
|
||||
);
|
||||
opts.optopt(
|
||||
"",
|
||||
"additional-suffix",
|
||||
"additional suffix to append to output file names",
|
||||
"SUFFIX",
|
||||
);
|
||||
opts.optopt("l", "lines", "put NUMBER lines per output file", "NUMBER");
|
||||
opts.optflag(
|
||||
"",
|
||||
|
@ -86,6 +92,7 @@ size is 1000, and default PREFIX is 'x'. With no INPUT, or when INPUT is
|
|||
prefix: "".to_owned(),
|
||||
numeric_suffix: false,
|
||||
suffix_length: 0,
|
||||
additional_suffix: "".to_owned(),
|
||||
input: "".to_owned(),
|
||||
strategy: "".to_owned(),
|
||||
strategy_param: "".to_owned(),
|
||||
|
@ -102,6 +109,12 @@ size is 1000, and default PREFIX is 'x'. With no INPUT, or when INPUT is
|
|||
None => 2,
|
||||
};
|
||||
|
||||
settings.additional_suffix = if matches.opt_present("additional-suffix") {
|
||||
matches.opt_str("additional-suffix").unwrap()
|
||||
} else {
|
||||
"".to_owned()
|
||||
};
|
||||
|
||||
settings.verbose = matches.opt_present("verbose");
|
||||
|
||||
settings.strategy = "l".to_owned();
|
||||
|
@ -134,6 +147,7 @@ struct Settings {
|
|||
prefix: String,
|
||||
numeric_suffix: bool,
|
||||
suffix_length: usize,
|
||||
additional_suffix: String,
|
||||
input: String,
|
||||
strategy: String,
|
||||
strategy_param: String,
|
||||
|
@ -316,11 +330,14 @@ fn split(settings: &Settings) -> i32 {
|
|||
let mut filename = settings.prefix.clone();
|
||||
filename.push_str(
|
||||
if settings.numeric_suffix {
|
||||
num_prefix(fileno, settings.suffix_length)
|
||||
num_prefix(fileno, settings.suffix_length)
|
||||
} else {
|
||||
str_prefix(fileno, settings.suffix_length)
|
||||
}
|
||||
.as_ref(),
|
||||
}.as_ref(),
|
||||
);
|
||||
filename.push_str(
|
||||
settings.additional_suffix
|
||||
.as_ref()
|
||||
);
|
||||
|
||||
if fileno != 0 {
|
||||
|
|
|
@ -145,3 +145,15 @@ fn test_split_str_prefixed_chunks_by_lines() {
|
|||
assert_eq!(glob.count(), 10);
|
||||
assert_eq!(glob.collate(), at.read(name).into_bytes());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_split_additional_suffix() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let name = "split_additional_suffix";
|
||||
let glob = Glob::new(&at, ".", r"x[[:alpha:]][[:alpha:]].txt$");
|
||||
RandomFile::new(&at, name).add_lines(2000);
|
||||
ucmd.args(&["--additional-suffix", ".txt", name]).succeeds();
|
||||
assert_eq!(glob.count(), 2);
|
||||
assert_eq!(glob.collate(), at.read(name).into_bytes());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue