aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rwxr-xr-x[-rw-r--r--]src/main.rs51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..f6e4a37 100644..100755
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,52 @@
+mod client;
+mod config;
+mod message;
+
+use clap::{crate_version, Parser};
+use std::path::PathBuf;
+use std::process::exit;
+
+#[derive(Parser, Debug)]
+#[clap(author, version, about, long_about = None)]
+#[clap(version = crate_version!())]
+struct Args {
+ #[clap(short, long, value_parser)]
+ config: PathBuf,
+
+ #[clap(subcommand)]
+ subcmd: message::MessageKind,
+}
+
+const TWILIO_BASE_URL: &str = "https://api.twilio.com";
+
fn main() {
- println!("Hello, world!");
+ let args = Args::parse();
+
+ let config: config::Config = match config::Config::load_from_file(&args.config) {
+ Ok(config) => config,
+ Err(e) => {
+ eprintln!("unable to load data from {}: {}", args.config.display(), e);
+ exit(1);
+ }
+ };
+
+ let msg = message::Message::builder()
+ .from(config.from.to_owned())
+ .to(config.to.to_owned())
+ .with_action(args.subcmd, &config)
+ .build();
+
+ let client = client::TwilioClient::new(
+ &config.account_sid,
+ &config.auth_token,
+ reqwest::Url::parse(TWILIO_BASE_URL).unwrap(),
+ );
+
+ match client.send(msg) {
+ Ok(m) => println!("message sent successfully: status is {:?}", m.status),
+ Err(error) => {
+ eprintln!("failed to send the message: {}", error);
+ exit(1);
+ }
+ }
}