diff options
| -rw-r--r-- | Cargo.lock | 16 | ||||
| -rw-r--r-- | Cargo.toml | 1 | ||||
| -rw-r--r-- | src/main.rs | 32 | 
3 files changed, 23 insertions, 26 deletions
| @@ -204,20 +204,10 @@ dependencies = [  ]  [[package]] -name = "getopts" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" -dependencies = [ - "unicode-width", -] - -[[package]]  name = "google-calendar-rsvp"  version = "0.0.1"  dependencies = [   "exitcode", - "getopts",   "google-calendar3",   "home",   "hyper", @@ -903,12 +893,6 @@ dependencies = [  ]  [[package]] -name = "unicode-width" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" - -[[package]]  name = "unicode-xid"  version = "0.2.2"  source = "registry+https://github.com/rust-lang/crates.io-index" @@ -5,7 +5,6 @@ edition = "2018"  [dependencies]  exitcode = "1.1.2" -getopts = "0.2.21"  google-calendar3 = "2.0.4+20210327"  home = "0.5.3"  hyper = "0.14.7" diff --git a/src/main.rs b/src/main.rs index f6ed64b..84157fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -use getopts::Options;  use google_calendar3::api::{Event, EventAttendee};  use google_calendar3::CalendarHub;  use home; @@ -12,26 +11,41 @@ use std::fs;  use std::process; +#[derive(Debug)] +enum EventResponseStatus { +    Accepted, +    Declined, +    Tentative, +} + +  #[tokio::main]  async fn main() -> Result<(), Box<dyn std::error::Error>> {      let args: Vec<String> = env::args().collect(); -    let mut opts = Options::new(); -    opts.optflag("y", "yes", "accept invitation"); -    opts.optflag("n", "no", "decline invitation"); -    opts.optflag("m", "maybe", "tentatively accept invitation"); +    let mut action: Option<EventResponseStatus> = None; +    let mut email = false; +    let mut event_ids = Vec::new(); -    opts.optflag("", "email", "read an email from standard input"); +    for arg in &args[1..] { +        match arg.as_ref() { +            "-y" | "--yes" => action = Some(EventResponseStatus::Accepted), +            "-n" | "--no" => action = Some(EventResponseStatus::Declined), +            "-m" | "--maybe" => action = Some(EventResponseStatus::Tentative), -    let opt_matches = opts.parse(&args[1..])?; +            "--email" => email = true, + +            id => event_ids.push(id), +        } +    } -    if opt_matches.free.is_empty() { +    if event_ids.is_empty() {          eprintln!("error: missing event ID argument");          process::exit(exitcode::USAGE);      } -    for event_id in &opt_matches.free { +    for event_id in &event_ids {          rsvp(event_id).await;      } | 
