aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2021-05-21 21:28:18 +0200
committerTeddy Wing2021-05-21 21:29:04 +0200
commit85ae4e96ff10811148f6b99595b934bce18623d1 (patch)
treeaf83d47b4c079c3ab95feccb0f29db74df404559
parent580a7140ca263d4c8e4f53f52ab601ea51fb4af0 (diff)
downloadgoogle-calendar-rsvp-85ae4e96ff10811148f6b99595b934bce18623d1.tar.bz2
Add command line option parsing
-rw-r--r--Cargo.lock23
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs26
3 files changed, 49 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5ec144e..b5b2d69 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -88,6 +88,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
+name = "exitcode"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "de853764b47027c2e862a995c34978ffa63c1501f2e15f987ba11bd4f9bba193"
+
+[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -198,9 +204,20 @@ 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",
@@ -886,6 +903,12 @@ 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 7dc1f02..82c4168 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,6 +4,8 @@ version = "0.0.1"
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 55cc21b..ae42e82 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,17 +1,39 @@
+use getopts::Options;
use google_calendar3::api::{Event, EventAttendee};
-use google_calendar3::{CalendarHub, Result, Error};
+use google_calendar3::CalendarHub;
use home;
use hyper;
use hyper_rustls;
use tokio;
use yup_oauth2 as oauth2;
+use std::env;
use std::fs;
+use std::process;
#[tokio::main]
-async fn 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");
+
+ opts.optflag("", "email", "read an email from standard input");
+
+ let opt_matches = opts.parse(&args[1..])?;
+
+ if opt_matches.free.is_empty() {
+ eprintln!("error: missing event ID argument");
+
+ process::exit(exitcode::USAGE);
+ }
+
rsvp().await;
+
+ Ok(())
}
async fn rsvp() {