cleaner config (no error if cache is cleaned
Some checks are pending
CI/CD Pipeline / test (push) Waiting to run

This commit is contained in:
philipp 2024-06-27 09:49:08 +02:00
parent e26e7df913
commit 4fb3733311
3 changed files with 16 additions and 13 deletions

View File

@ -27,10 +27,11 @@ use tracing_subscriber::fmt;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command(version, about, long_about = None)] #[command(version, about, long_about = None)]
#[group(required = true, args(&["config", "clear_cache"]))]
struct Args { struct Args {
/// Path to the config of a law text /// Path to the config of a law text
#[arg(short, long)] #[arg(short, long)]
config: String, config: Option<String>,
/// Parses a single paragraph (for debugging, e.g. https://www.ris.bka.gv.at/Dokumente/Bundesnormen/NOR40217849/NOR40217849.xml) /// Parses a single paragraph (for debugging, e.g. https://www.ris.bka.gv.at/Dokumente/Bundesnormen/NOR40217849/NOR40217849.xml)
/// Conflicts with `config` (either parse full law XOR single paragraph) /// Conflicts with `config` (either parse full law XOR single paragraph)
@ -41,6 +42,7 @@ struct Args {
#[arg(long)] #[arg(long)]
clear_cache: bool, clear_cache: bool,
} }
use tracing_subscriber::prelude::*; use tracing_subscriber::prelude::*;
fn main() { fn main() {
tracing_subscriber::registry() tracing_subscriber::registry()
@ -53,17 +55,18 @@ fn main() {
if let Err(e) = clear_cache() { if let Err(e) = clear_cache() {
println!("Failed to clear cache: {e:?}"); println!("Failed to clear cache: {e:?}");
} }
} } else {
let config = &args.config.unwrap(); // ok, checked with clap
if let Some(par_url) = &args.par_url { if let Some(par_url) = &args.par_url {
let (_, mut builder, parser) = Config::load(&args.config).unwrap(); let (_, mut builder, parser) = Config::load(config).unwrap();
builder.add_classifier(Classifier::new("always-true", Arc::new(always_true))); builder.add_classifier(Classifier::new("always-true", Arc::new(always_true)));
// builder.new_header("initial"); // builder.new_header("initial");
parser.parse(par_url, &mut builder).unwrap(); parser.parse(par_url, &mut builder).unwrap();
let law: Law = builder.into(); let law: Law = builder.into();
println!("{law:?}"); println!("{law:?}");
} else { } else {
let law = Law::from_config(&args.config).unwrap(); let law = Law::from_config(config).unwrap();
law.to_md(); law.to_md();
} }
}
} }

View File

@ -212,7 +212,7 @@ fn fetch(url: &str) -> Result<String, Error> {
mod tests { mod tests {
use std::fs; use std::fs;
use crate::config::Config; use crate::{config::Config, overview};
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
#[test] #[test]

0
update_laws.sh Normal file → Executable file
View File