Skip to content

Commit dec7be1

Browse files
committed
csplit: PathBuf
1 parent a94e001 commit dec7be1

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

text/src/csplit.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use plib::PROJECT_NAME;
1919
use regex::Regex;
2020
use std::fs::{self, File, OpenOptions};
2121
use std::io::{self, BufRead, Error, ErrorKind, Read, Write};
22+
use std::path::PathBuf;
2223

2324
/// csplit - split files based on context
2425
#[derive(Parser, Debug)]
@@ -41,7 +42,7 @@ struct Args {
4142
suppress: bool,
4243

4344
/// File to read as input.
44-
filename: String,
45+
filename: PathBuf,
4546

4647
/// Operands defining context on which to split.
4748
operands: Vec<String>,
@@ -189,7 +190,7 @@ fn csplit_file(args: &Args, ctx: SplitOps, new_files: &mut Vec<String>) -> io::R
189190
let mut split_options = ctx.ops;
190191
// open file, or stdin
191192
let file: Box<dyn Read> = {
192-
if args.filename == "-" {
193+
if args.filename == PathBuf::from("-") {
193194
Box::new(io::stdin().lock())
194195
} else {
195196
Box::new(fs::File::open(&args.filename)?)
@@ -605,7 +606,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
605606
let mut new_files = vec![];
606607
if let Err(err) = csplit_file(&args, ctx, &mut new_files) {
607608
exit_code = 1;
608-
eprintln!("{}: {}", args.filename, err);
609+
eprintln!("{}: {}", args.filename.display(), err);
609610
if !args.keep {
610611
for file_name in new_files.iter() {
611612
fs::remove_file(file_name).unwrap();
@@ -803,7 +804,7 @@ mod tests {
803804
keep: false,
804805
num: 2,
805806
suppress: false,
806-
filename: String::from("test.txt"),
807+
filename: PathBuf::from("test.txt"),
807808
operands: vec![
808809
String::from("/pattern/+1"),
809810
String::from("%skip%10"),
@@ -850,7 +851,7 @@ mod tests {
850851
keep: false,
851852
num: 2,
852853
suppress: false,
853-
filename: String::from("tests/assets/test_file.txt"),
854+
filename: PathBuf::from("tests/assets/test_file.txt"),
854855
operands: vec![String::from("5"), String::from("{3}")],
855856
};
856857

@@ -900,7 +901,7 @@ mod tests {
900901
keep: false,
901902
num: 2,
902903
suppress: false,
903-
filename: String::from("tests/assets/test_file_c"),
904+
filename: PathBuf::from("tests/assets/test_file_c"),
904905
operands: vec![
905906
String::from(r"%main\(%"),
906907
String::from("/^}/+1"),
@@ -957,7 +958,7 @@ mod tests {
957958
keep: false,
958959
num: 2,
959960
suppress: false,
960-
filename: String::from("tests/assets/test_file_c"),
961+
filename: PathBuf::from("tests/assets/test_file_c"),
961962
operands: vec![
962963
String::from(r"%main\(%+1"),
963964
String::from("/^}/+1"),
@@ -1013,7 +1014,7 @@ mod tests {
10131014
keep: false,
10141015
num: 2,
10151016
suppress: false,
1016-
filename: String::from("tests/assets/test_file_c"),
1017+
filename: PathBuf::from("tests/assets/test_file_c"),
10171018
operands: vec![
10181019
String::from(r"%main\(%-1"),
10191020
String::from("/^}/+1"),
@@ -1070,7 +1071,7 @@ mod tests {
10701071
keep: false,
10711072
num: 2,
10721073
suppress: false,
1073-
filename: String::from("tests/assets/test_file_c"),
1074+
filename: PathBuf::from("tests/assets/test_file_c"),
10741075
operands: vec![
10751076
String::from(r"%main\(%"),
10761077
String::from("/^}/"),
@@ -1127,7 +1128,7 @@ mod tests {
11271128
keep: false,
11281129
num: 2,
11291130
suppress: false,
1130-
filename: String::from("tests/assets/test_file_c"),
1131+
filename: PathBuf::from("tests/assets/test_file_c"),
11311132
operands: vec![
11321133
String::from(r"%main\(%"),
11331134
String::from("/^}/-1"),

0 commit comments

Comments
 (0)