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",
|
"numeric-suffixes",
|
||||||
"use numeric suffixes instead of alphabetic",
|
"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.optopt("l", "lines", "put NUMBER lines per output file", "NUMBER");
|
||||||
opts.optflag(
|
opts.optflag(
|
||||||
"",
|
"",
|
||||||
|
@ -86,6 +92,7 @@ size is 1000, and default PREFIX is 'x'. With no INPUT, or when INPUT is
|
||||||
prefix: "".to_owned(),
|
prefix: "".to_owned(),
|
||||||
numeric_suffix: false,
|
numeric_suffix: false,
|
||||||
suffix_length: 0,
|
suffix_length: 0,
|
||||||
|
additional_suffix: "".to_owned(),
|
||||||
input: "".to_owned(),
|
input: "".to_owned(),
|
||||||
strategy: "".to_owned(),
|
strategy: "".to_owned(),
|
||||||
strategy_param: "".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,
|
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.verbose = matches.opt_present("verbose");
|
||||||
|
|
||||||
settings.strategy = "l".to_owned();
|
settings.strategy = "l".to_owned();
|
||||||
|
@ -134,6 +147,7 @@ struct Settings {
|
||||||
prefix: String,
|
prefix: String,
|
||||||
numeric_suffix: bool,
|
numeric_suffix: bool,
|
||||||
suffix_length: usize,
|
suffix_length: usize,
|
||||||
|
additional_suffix: String,
|
||||||
input: String,
|
input: String,
|
||||||
strategy: String,
|
strategy: String,
|
||||||
strategy_param: String,
|
strategy_param: String,
|
||||||
|
@ -316,11 +330,14 @@ fn split(settings: &Settings) -> i32 {
|
||||||
let mut filename = settings.prefix.clone();
|
let mut filename = settings.prefix.clone();
|
||||||
filename.push_str(
|
filename.push_str(
|
||||||
if settings.numeric_suffix {
|
if settings.numeric_suffix {
|
||||||
num_prefix(fileno, settings.suffix_length)
|
num_prefix(fileno, settings.suffix_length)
|
||||||
} else {
|
} else {
|
||||||
str_prefix(fileno, settings.suffix_length)
|
str_prefix(fileno, settings.suffix_length)
|
||||||
}
|
}.as_ref(),
|
||||||
.as_ref(),
|
);
|
||||||
|
filename.push_str(
|
||||||
|
settings.additional_suffix
|
||||||
|
.as_ref()
|
||||||
);
|
);
|
||||||
|
|
||||||
if fileno != 0 {
|
if fileno != 0 {
|
||||||
|
|
|
@ -145,3 +145,15 @@ fn test_split_str_prefixed_chunks_by_lines() {
|
||||||
assert_eq!(glob.count(), 10);
|
assert_eq!(glob.count(), 10);
|
||||||
assert_eq!(glob.collate(), at.read(name).into_bytes());
|
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