use clap::Parser;
use std::fs;
use std::io::{self, BufRead};
use std::path::Path;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
#[arg(short, long, allow_negative_numbers = true, default_value = "")]
pub rows: String,
#[arg(long, default_value = r"\n")]
pub row_delimiter: String,
#[arg(short, long, allow_negative_numbers = true, default_value = "")]
pub columns: String,
#[arg(long, default_value = r"\s")]
pub column_delimiter: String,
#[arg(value_delimiter = None, default_value = "", help = "Text to parse")]
pub input: String,
}
fn read_stdin() -> String {
io::stdin()
.lock()
.lines()
.fold("".to_string(), |acc, line| acc + &line.unwrap() + "\n")
.to_string()
}
pub fn parse_input(input_text: &str) -> String {
if input_text.is_empty() {
read_stdin()
} else if Path::new(input_text).exists() {
fs::read_to_string(input_text).expect("Input file could not be read.")
} else {
input_text.to_string()
}
}
#[cfg(test)]
#[path = "cli_tests.rs"]
mod cli_tests;