log_genius/input.rs
1use crate::error::{AppError, Result};
2use std::{fs, io};
3use std::io::Read;
4use std::path::PathBuf;
5
6pub fn read_input(file_path: Option<PathBuf>) -> Result<String> {
7 let mut buffer = String::new();
8
9 match file_path {
10 Some(path) => {
11 buffer = fs::read_to_string(path)?;
12 }
13 None => {
14 io::stdin().read_to_string(&mut buffer)?;
15 }
16 }
17
18 if buffer.trim().is_empty() {
19 eprintln!("Warning: Input is empty.");
20 }
21
22 Ok(buffer)
23}