aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2021-05-21 23:18:17 +0200
committerTeddy Wing2021-05-21 23:23:50 +0200
commitd446feb636e40d6c9ee335051c936afede10cfc8 (patch)
tree7e97e20c895b887a438f5f34b9350368e94b408e /src
parent0cec2db1fc61488bb5658f68ba5459861419d9fe (diff)
downloadgoogle-calendar-rsvp-d446feb636e40d6c9ee335051c936afede10cfc8.tar.bz2
Parse command line options manually
Decided to parse command line options manually so that if multiple event response status flags are passed, only the last one will be used.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs32
1 files changed, 23 insertions, 9 deletions
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;
}