aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2021-05-21 23:18:17 +0200
committerTeddy Wing2021-05-21 23:23:50 +0200
commitd446feb636e40d6c9ee335051c936afede10cfc8 (patch)
tree7e97e20c895b887a438f5f34b9350368e94b408e
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.
-rw-r--r--Cargo.lock16
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs32
3 files changed, 23 insertions, 26 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b5b2d69..0bc6063 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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"
diff --git a/Cargo.toml b/Cargo.toml
index 82c4168..c4a54ac 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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;
}