use crate::logging::*;
use crate::regexes::*;
use clap::Parser;
use log::Level::Error;
use std::fs;
#[allow(missing_docs)]
#[allow(clippy::missing_docs_in_private_items)]
#[derive(Debug, Parser)]
#[command(version, about)]
pub struct Cli {
#[arg(long, short, help = "Check formatting, do not modify files")]
pub check: bool,
#[arg(long, short, help = "Print to STDOUT, do not modify files")]
pub print: bool,
#[arg(long, short, help = "Keep lines, do not wrap")]
pub keep: bool,
#[arg(long, short, help = "Show info log messages")]
pub verbose: bool,
#[arg(long, short, help = "Hide warning messages")]
pub quiet: bool,
#[arg(long, short, help = "Show trace log messages")]
pub trace: bool,
#[arg(required = true)]
pub files: Vec<String>,
}
impl Cli {
pub fn resolve(&mut self) {
if self.trace {
self.verbose = true;
}
}
#[cfg(test)]
pub const fn new() -> Self {
Self {
check: false,
print: false,
keep: false,
verbose: false,
quiet: false,
trace: false,
files: Vec::<String>::new(),
}
}
}
pub fn read(file: &str, logs: &mut Vec<Log>) -> Option<(String, String)> {
let has_ext = EXTENSIONS.iter().any(|e| file.ends_with(e));
let mut new_file = file.to_owned();
if !has_ext {
new_file.push_str(".tex");
};
if let Ok(text) = fs::read_to_string(&new_file) {
return Some((new_file, text));
}
if has_ext {
record_file_log(logs, Error, file, "Could not open file.");
} else {
record_file_log(logs, Error, file, "File type invalid.");
}
None
}