Adds targets, fix help message
This commit is contained in:
parent
bccae62b3a
commit
e6fd22db8d
|
|
@ -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);
|
||||
cmd.arg(&args.target);
|
||||
if args.non_interactive {
|
||||
cmd.arg("--interaction=batchmode");
|
||||
}
|
||||
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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue