2024-02-15 13:50:58 +01:00
|
|
|
|
// Copyright (C) 2024 Philipp Hofer
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
|
|
|
|
|
// the European Commission - subsequent versions of the EUPL (the "Licence").
|
|
|
|
|
// You may not use this work except in compliance with the Licence.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the European Union Public License along
|
|
|
|
|
// with this program. If not, you may obtain a copy of the Licence at:
|
|
|
|
|
// <https://joinup.ec.europa.eu/software/page/eupl>
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the Licence is distributed on an "AS IS" basis,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the Licence for the specific language governing permissions and
|
|
|
|
|
// limitations under the Licence.
|
|
|
|
|
|
2024-02-15 11:40:02 +01:00
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
2024-02-15 08:48:26 +01:00
|
|
|
|
use clap::{command, Parser};
|
2024-02-15 11:40:02 +01:00
|
|
|
|
use risp::{
|
|
|
|
|
config::Config,
|
|
|
|
|
law::{responsible::always_true, Classifier, Law},
|
|
|
|
|
misc::clear_cache,
|
|
|
|
|
};
|
2023-11-03 22:40:19 +01:00
|
|
|
|
|
2024-02-15 08:48:26 +01:00
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
|
#[command(version, about, long_about = None)]
|
|
|
|
|
struct Args {
|
|
|
|
|
/// Path to the config of a law text
|
|
|
|
|
#[arg(short, long)]
|
|
|
|
|
config: String,
|
2024-02-15 09:24:30 +01:00
|
|
|
|
|
2024-02-15 11:40:02 +01:00
|
|
|
|
/// 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)
|
|
|
|
|
#[arg(short, long)]
|
|
|
|
|
par_url: Option<String>,
|
|
|
|
|
|
2024-02-15 09:24:30 +01:00
|
|
|
|
/// Clears the cache (downloaded laws + paragraphs)
|
2024-02-15 11:40:02 +01:00
|
|
|
|
#[arg(long)]
|
2024-02-15 09:24:30 +01:00
|
|
|
|
clear_cache: bool,
|
2024-02-15 08:48:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-03 13:45:25 +01:00
|
|
|
|
fn main() {
|
2023-11-05 12:46:04 +01:00
|
|
|
|
env_logger::init();
|
|
|
|
|
|
2024-02-15 08:48:26 +01:00
|
|
|
|
let args = Args::parse();
|
2024-02-15 09:24:30 +01:00
|
|
|
|
|
|
|
|
|
if args.clear_cache {
|
|
|
|
|
if let Err(e) = clear_cache() {
|
|
|
|
|
println!("Failed to clear cache: {e:?}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-15 11:40:02 +01:00
|
|
|
|
if let Some(par_url) = &args.par_url {
|
|
|
|
|
let (_, mut builder, parser) = Config::load(&args.config).unwrap();
|
|
|
|
|
builder.add_classifier(Classifier::new("always-true", Arc::new(always_true)));
|
|
|
|
|
builder.new_header("initial");
|
2024-02-15 11:44:58 +01:00
|
|
|
|
parser.parse(par_url, &mut builder).unwrap();
|
2024-02-15 11:40:02 +01:00
|
|
|
|
let law: Law = builder.into();
|
|
|
|
|
law.to_md();
|
|
|
|
|
} else {
|
|
|
|
|
let law = Law::from_config(&args.config).unwrap();
|
2024-02-06 10:17:14 +01:00
|
|
|
|
|
2024-02-15 11:40:02 +01:00
|
|
|
|
law.to_md();
|
|
|
|
|
}
|
2023-11-03 13:45:25 +01:00
|
|
|
|
}
|