Skip to content

Commit 9f40ddb

Browse files
committed
Update
1 parent 0762662 commit 9f40ddb

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ cargo install --git https://github.com/GMELab/col-combiner
2121
## Usage
2222

2323
```bash
24-
col-combiner --file <file> --dir <dir> # if dir is not specified, the current directory is used
24+
col-combiner <file> [--dir <dir>] # if dir is not specified, the current directory is used
2525
# For example
26-
col-combiner --file example.txt --dir example_dir
26+
col-combiner example.txt --dir example_dir
2727
# now we get a file called in example_dir called combined_example.txt
2828
```

src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use clap::Parser;
66
#[command(version, about, long_about = None)]
77
pub struct Args {
88
/// Name of the file to combine in child directories
9-
#[arg(short, long)]
109
pub file: String,
1110
/// Directory to search for subdirectories in.
1211
#[arg(short, long)]
@@ -55,9 +54,19 @@ fn main() {
5554

5655
println!("Processing file: {}", file_path.display());
5756

58-
let content = std::fs::read_to_string(&file_path)
57+
let mut content = std::fs::read_to_string(&file_path)
5958
.unwrap_or_else(|_| panic!("Failed to read file '{}'", file_path.display()));
6059

60+
let lines_count = content.lines().count();
61+
if lines_count == 1 {
62+
println!(
63+
"Warning: File '{}' has only one line, converting to single-column format",
64+
file_path.display()
65+
);
66+
// If the file has only one line, we treat it as a single-column file
67+
content = content.trim().split('\t').collect::<Vec<_>>().join("\n");
68+
}
69+
6170
for (j, line) in content.lines().enumerate() {
6271
let trimmed = line.trim();
6372
// split the line by tab character

0 commit comments

Comments
 (0)