feature/builder #8
|
|
@ -15,32 +15,66 @@ use clap::Args;
|
|||
use std::process::Stdio;
|
||||
|
||||
use crate::makepdf_structs::{
|
||||
BuildInfo, LineType, Status, VerboseLevel, COL_NORMAL, TXT_BOXX, TXT_CNTX, TXT_CRIT, TXT_ERRR,
|
||||
TXT_INFO, TXT_MISC, TXT_UKNW, TXT_WARN,
|
||||
BuildInfo, LineType, Status, VerboseLevel, COL_NORMAL, MAKE_VERBOSITY_LEVEL, TXT_BOXX,
|
||||
TXT_CNTX, TXT_CRIT, TXT_ERRR, TXT_INFO, TXT_MISC, TXT_UKNW, TXT_WARN,
|
||||
};
|
||||
use crate::Config;
|
||||
|
||||
#[derive(Args, Debug, Clone)]
|
||||
#[command(after_help = format!("{} {}","VERBOSITY:",MAKE_VERBOSITY_LEVEL.as_str()))]
|
||||
/// The configuration struct for the PdfMaker
|
||||
pub(crate) struct MakeConfig {
|
||||
/// The filename to compile
|
||||
pub(crate) filename: String,
|
||||
pub(crate) target: String,
|
||||
|
||||
/// The verbosity level
|
||||
#[arg(short, long, default_value = "warning")]
|
||||
pub(crate) verbosity: VerboseLevel,
|
||||
// /// The list of whitelisted verbosity levels
|
||||
// pub(crate) whitelist: Vec<VerboseLevel>,
|
||||
// /// The list of blacklisted verbosity levels
|
||||
// pub(crate) blacklist: Vec<VerboseLevel>,
|
||||
|
||||
/// switch to non interactive mode
|
||||
#[arg(short = 'N', long, default_value_t = false)]
|
||||
pub(crate) non_interactive: bool,
|
||||
|
||||
/// Select only these targets
|
||||
#[arg(short, long, value_name = "FILE", group = "select")]
|
||||
pub(crate) only: Vec<String>,
|
||||
|
||||
/// Deselect these targets
|
||||
#[arg(short, long, value_name = "FILE", group = "select")]
|
||||
pub(crate) no: Vec<String>,
|
||||
}
|
||||
|
||||
/// Make a pdf spawning a subprocess
|
||||
pub(crate) fn make_pdf(args: &MakeConfig, config: &Config) -> Result<()> {
|
||||
let _ = config;
|
||||
// Identify special targets: Clean, Glossaries, All, List etc.
|
||||
match args.target.as_str() {
|
||||
"all" => make_all(args),
|
||||
"clean" => make_clean(args),
|
||||
"list" => make_list(args),
|
||||
"glossaries" => make_glossaries(args),
|
||||
_ => (),
|
||||
}
|
||||
launch_subprocess(args).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn make_list(args: &MakeConfig) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn make_glossaries(args: &MakeConfig) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn make_all(args: &MakeConfig) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn make_clean(args: &MakeConfig) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
/// Pdfreading and curating
|
||||
async fn launch_subprocess(args: &MakeConfig) -> Result<Status> {
|
||||
|
|
@ -54,7 +88,10 @@ async fn launch_subprocess(args: &MakeConfig) -> Result<Status> {
|
|||
let mut built = 0;
|
||||
let to_build = last_run.lines_parsed;
|
||||
|
||||
cmd.arg(&args.filename);
|
||||
if args.non_interactive {
|
||||
cmd.arg("--interaction=nonstopmode");
|
||||
}
|
||||
cmd.arg(&args.target);
|
||||
cmd.env("max_print_line", "3000");
|
||||
// Specify that we want the command's standard output piped back to us.
|
||||
cmd.stdout(Stdio::piped());
|
||||
|
|
|
|||
|
|
@ -92,16 +92,21 @@ static STR_TO_TARGET: phf::Map<&'static str, VerboseLevel> = phf_map! {
|
|||
"critical" => VerboseLevel::Critical,
|
||||
};
|
||||
|
||||
/// List all targets
|
||||
pub(crate) static MAKE_VERBOSITY_LEVEL: LazyLock<String> = LazyLock::new(|| {
|
||||
let mut targets = STR_TO_TARGET.values().collect::<Vec<&VerboseLevel>>();
|
||||
targets.sort();
|
||||
format!("{:?}", targets)
|
||||
});
|
||||
|
||||
impl From<&str> for VerboseLevel {
|
||||
fn from(value: &str) -> Self {
|
||||
if let Some(target) = STR_TO_TARGET.get(&value.to_lowercase()).cloned() {
|
||||
target
|
||||
} else {
|
||||
let mut targets = STR_TO_TARGET.values().collect::<Vec<&VerboseLevel>>();
|
||||
targets.sort();
|
||||
panic!(
|
||||
"Invalid debug level {}. The debug level available are (from highest verbosity to lowest): {:?}",
|
||||
value, targets
|
||||
value, MAKE_VERBOSITY_LEVEL
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -128,7 +133,7 @@ impl BuildInfo {
|
|||
/// Create a new empty run
|
||||
pub fn new(args: &MakeConfig) -> Self {
|
||||
Self {
|
||||
filename: args.filename.clone(),
|
||||
filename: args.target.clone(),
|
||||
// options: args.update_from_arg_matches,
|
||||
options: Vec::new(),
|
||||
lines_parsed: 0,
|
||||
|
|
@ -215,7 +220,8 @@ pub(crate) enum LineType {
|
|||
MissingReference(String),
|
||||
|
||||
/// Generic Latex Warning
|
||||
#[regex(r"(LaTex |Warning:){2}[^\n]+", |lex| lex.slice()[14..].to_string())]
|
||||
// TODO: Just use a Prs like the others
|
||||
#[regex(r"(LaTex |Warning:)+[^\n]+", |lex| lex.slice()[14..].to_string())]
|
||||
Warning(String),
|
||||
|
||||
// /// Runaway argument
|
||||
|
|
@ -227,6 +233,7 @@ pub(crate) enum LineType {
|
|||
|
||||
/// Context, mosty for boxes
|
||||
// TODO: False positives / Reparsing Context("10") )) [107] (./Ecoles/Protecteur.tex
|
||||
// TODO: uncaught: [UKNW] [3] [4] (./Chapters/Intro.tex (/usr/share/texmf/tex/latex/lm/ot1lmr.fd) (/usr/share/texmf/tex/latex/lm/omllmm.fd) (/usr/share/texmf/tex/latex/lm/omslmsy.fd) (/usr/share/texmf/tex/latex/lm/omxlmex.fd) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/share/texlive/texmf-dist/tex/latex/microtype/mt-msa.cfg) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) (/usr/share/texlive/texmf-dist/tex/latex/microtype/mt-msb.cfg) (/usr/share/texmf/tex/latex/lm/ts1lmr.fd)) [5 <./Images//Ico/LogoNoush.jpg>] [6]
|
||||
#[regex(r"\[\d[^\]]+", |lex| lex.slice()[1..lex.slice().len()-1].to_string())]
|
||||
Context(String),
|
||||
|
||||
|
|
@ -383,8 +390,9 @@ pub(crate) struct Status {
|
|||
|
||||
impl Status {
|
||||
/// Add a recoverable error to the list of errors
|
||||
// TODO: Print this at the end of the parse
|
||||
pub(crate) fn add_error(&mut self, error_msg: String) {
|
||||
self.errors += 1;
|
||||
// self.errors += 1;
|
||||
self.v_errors.push(error_msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue