CalCalist/src/cli.rs

86 lines
2.3 KiB
Rust
Raw Normal View History

//! Command line surface.
use std::path::PathBuf;
use clap::{Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(
name = "calcalist",
version,
about = "Aggregate and sync events between CalDAV, Google Calendar and iCal feeds"
)]
pub struct Cli {
/// Configuration file (default: $XDG_CONFIG_HOME/calcalist/calcalist.toml)
#[arg(long, short, global = true, value_name = "FILE")]
pub config: Option<PathBuf>,
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
/// Run one synchronisation cycle
Sync {
/// Report what would change without writing anything
#[arg(long)]
dry_run: bool,
/// Proceed even when the mass-deletion guard trips
#[arg(long)]
force: bool,
},
/// Show endpoints, aggregates and the last sync result
Status,
/// Serve the configuration web interface on localhost
Serve {
#[arg(long, default_value_t = 8723)]
port: u16,
},
/// Google account operations
Google {
#[command(subcommand)]
command: GoogleCommand,
},
/// Aggregate maintenance
Aggregate {
#[command(subcommand)]
command: AggregateCommand,
},
Close the remaining M1 gaps Eight items were still open at the end of M1: two integration tests that had only been run by hand, and six known gaps. Recurrence overrides now reach Google. Google addresses an exception through the series rather than as an event of its own, so the master is sent first and each override is then matched to its instance by original start time and patched. Matching needs the two sides' spellings reduced to one key: iCalendar writes a zoned local time, Google an absolute offset. An override matching no occurrence is counted rather than forced — that means a stale RECURRENCE-ID left behind by an edited RRULE, and inventing an event for it would put something in the calendar the series does not contain. Reading one component apart from another needed a view `properties` cannot give: it flattens every VEVENT together, which is right for the UID a series shares and wrong for an override, whose SUMMARY and the master's are then indistinguishable. `Calendar::events` splits them. A TZID now travels with the VTIMEZONE that defines it, derived from the zone's own transition table as the yearly rule it implies. This changes the content hash of every zoned recurring event, so the first cycle after this re-pushes them. A Google authorisation is filed under the account it was granted for rather than the endpoint that asked for it, so two endpoints on one account no longer need a login each. The account is read from the primary calendar's id, which needs no scope beyond the calendar one already granted. Authorisations written by the previous scheme are still honoured, and move across at the next login. An unreachable Google endpoint no longer ends the cycle — one lapsed token used to stop the CalDAV side too. It is named, only the aggregates depending on it stand down, and the run exits non-zero so a partial cycle cannot pass for success. The CalDAV leg cannot be narrowed the same way: pimsync is one process covering every pair, so a failure does not say which pair it belongs to. `--dry-run` now pulls for real, into a throwaway copy of the local mirrors and through a pimsync configuration that only ever reads from a server. What it reports is measured against the calendars as they are now rather than against whatever the last real cycle left behind. `calcalist prune` reports local mirrors of endpoints the configuration no longer names, and removes them under --force. The integration tests run against a real Radicale server and a real iCal feed: convergence and idempotence, the dry run, prune, and the scheduling rule asserted on the bytes that actually reached the server. The plan asked for an SMTP sink for that last one; Radicale implements no RFC 6638 scheduling, so a quiet SMTP port would have proved nothing about the transform. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 13:49:38 +03:00
/// Remove local mirrors of endpoints the configuration no longer names
Prune {
/// Delete them; without this the command only reports what it found
#[arg(long)]
force: bool,
},
/// Check that the environment and configuration are usable
Doctor,
}
#[derive(Debug, Subcommand)]
pub enum GoogleCommand {
/// Authorise calcalist against a Google account
Login {
/// Endpoint id to authorise
endpoint: String,
},
}
#[derive(Debug, Subcommand)]
pub enum AggregateCommand {
/// Move an aggregate to a different target endpoint
Retarget {
/// Aggregate id
id: String,
/// Endpoint id to publish the aggregate to from now on
#[arg(long = "to", value_name = "ENDPOINT")]
to: String,
/// Leave mirrored events on the previous target (default)
#[arg(long, conflicts_with = "purge_old")]
keep_old: bool,
/// Delete calcalist's mirrored events from the previous target
#[arg(long)]
purge_old: bool,
},
}