mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
csplit: run the file check before the arguments verifications
This commit is contained in:
parent
8551c55ab3
commit
b49fbd9a21
2 changed files with 12 additions and 3 deletions
|
@ -89,7 +89,7 @@ impl CsplitOptions {
|
||||||
/// more than once.
|
/// more than once.
|
||||||
pub fn csplit<T>(
|
pub fn csplit<T>(
|
||||||
options: &CsplitOptions,
|
options: &CsplitOptions,
|
||||||
patterns: Vec<patterns::Pattern>,
|
patterns: Vec<String>,
|
||||||
input: T,
|
input: T,
|
||||||
) -> Result<(), CsplitError>
|
) -> Result<(), CsplitError>
|
||||||
where
|
where
|
||||||
|
@ -97,6 +97,7 @@ where
|
||||||
{
|
{
|
||||||
let mut input_iter = InputSplitter::new(input.lines().enumerate());
|
let mut input_iter = InputSplitter::new(input.lines().enumerate());
|
||||||
let mut split_writer = SplitWriter::new(options);
|
let mut split_writer = SplitWriter::new(options);
|
||||||
|
let patterns: Vec<patterns::Pattern> = patterns::get_patterns(&patterns[..])?;
|
||||||
let ret = do_csplit(&mut split_writer, patterns, &mut input_iter);
|
let ret = do_csplit(&mut split_writer, patterns, &mut input_iter);
|
||||||
|
|
||||||
// consume the rest
|
// consume the rest
|
||||||
|
@ -563,7 +564,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
.collect();
|
.collect();
|
||||||
let patterns = patterns::get_patterns(&patterns[..])?;
|
|
||||||
let options = CsplitOptions::new(&matches);
|
let options = CsplitOptions::new(&matches);
|
||||||
if file_name == "-" {
|
if file_name == "-" {
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
|
|
|
@ -1362,8 +1362,17 @@ fn precision_format() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn zero_error() {
|
fn zero_error() {
|
||||||
let (_, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
at.touch("in");
|
||||||
ucmd.args(&["in", "0"])
|
ucmd.args(&["in", "0"])
|
||||||
.fails()
|
.fails()
|
||||||
.stderr_contains("0: line number must be greater");
|
.stderr_contains("0: line number must be greater");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_such_file() {
|
||||||
|
let (_, mut ucmd) = at_and_ucmd!();
|
||||||
|
ucmd.args(&["in", "0"])
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("cannot access 'in': No such file or directory");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue