use std::io::Read;
use std::path::PathBuf;
use anyhow::{Context, Result};
pub(super) fn read_input(path: Option<&PathBuf>) -> Result<String> {
let use_stdin = path.is_none() || path.is_some_and(|value| value.as_os_str() == "-");
if use_stdin {
let mut buffer = String::new();
std::io::stdin()
.read_to_string(&mut buffer)
.context("read from stdin")?;
return Ok(buffer);
}
let path = path.expect("checked path above");
std::fs::read_to_string(path).with_context(|| format!("read import file {}", path.display()))
}