refactored to make it more input-agnostic
This commit is contained in:
parent
dfbf23ed6a
commit
92c30167df
2 changed files with 40 additions and 24 deletions
47
src/main.rs
47
src/main.rs
|
@ -74,7 +74,7 @@ struct CliAuto {
|
|||
}
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
struct CliIcsDebug {
|
||||
struct CliDebugOutput {
|
||||
#[arg(long)]
|
||||
config: Utf8PathBuf,
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ struct CliIcsDebug {
|
|||
#[derive(clap::Subcommand)]
|
||||
enum Commands {
|
||||
Auto(CliAuto),
|
||||
IcsDebug(CliIcsDebug),
|
||||
DebugOutput(CliDebugOutput),
|
||||
}
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
|
@ -154,17 +154,26 @@ struct EventInstance {
|
|||
calendar_ui: CalendarUi,
|
||||
dtstart: DatePerhapsTime,
|
||||
location: Option<String>,
|
||||
recurrence_id: Option<icalendar::DatePerhapsTime>,
|
||||
recurrence_id: Option<DatePerhapsTime>,
|
||||
summary: Option<String>,
|
||||
uid: Option<String>,
|
||||
url: Option<String>,
|
||||
}
|
||||
|
||||
/// Used to link recurrence exceptions to the original events they replace
|
||||
#[derive(Eq, Ord, PartialOrd, PartialEq)]
|
||||
struct RecurrenceKey<'a> {
|
||||
recurrence_id: DatePerhapsTime,
|
||||
uid: &'a str,
|
||||
impl EventInstance {
|
||||
fn filter(&self, config_output: &ConfigOutput) -> bool {
|
||||
if let Some(uid) = &self.uid
|
||||
&& config_output.hide_uids.contains(uid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if let Some(summary) = &self.summary
|
||||
&& config_output.hide_summaries.contains(summary)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -191,17 +200,11 @@ fn process_data<'a>(
|
|||
|
||||
let mut instances = vec![];
|
||||
for ical in &data.icals {
|
||||
for ei in ical.event_instances(¶ms)? {
|
||||
if let Some(uid) = &ei.uid
|
||||
&& config_output.hide_uids.contains(uid)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if let Some(summary) = &ei.summary
|
||||
&& config_output.hide_summaries.contains(summary)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for ei in ical
|
||||
.event_instances(¶ms)?
|
||||
.into_iter()
|
||||
.filter(|x| x.filter(config_output))
|
||||
{
|
||||
instances.push(ei);
|
||||
}
|
||||
}
|
||||
|
@ -412,7 +415,7 @@ async fn do_everything(cli: &CliAuto) -> Result<()> {
|
|||
}
|
||||
let bytes = resp.bytes().await?;
|
||||
|
||||
let temp_path = dl.file_path.with_extension(".ics.temp");
|
||||
let temp_path = dl.file_path.with_extension(".wac_temp");
|
||||
std::fs::write(&temp_path, &bytes)?;
|
||||
std::fs::rename(&temp_path, &dl.file_path)?;
|
||||
}
|
||||
|
@ -443,7 +446,7 @@ fn main_auto(cli: CliAuto) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
fn main_ics_debug(cli: CliIcsDebug) -> Result<()> {
|
||||
fn main_debug_output(cli: CliDebugOutput) -> Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
tracing::info!("Started tracing");
|
||||
let config = std::fs::read_to_string(&cli.config)?;
|
||||
|
@ -464,6 +467,6 @@ fn main() -> Result<()> {
|
|||
|
||||
match cli.command {
|
||||
Commands::Auto(x) => main_auto(x),
|
||||
Commands::IcsDebug(x) => main_ics_debug(x),
|
||||
Commands::DebugOutput(x) => main_debug_output(x),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue