aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..a60226b
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,61 @@
+mod cli;
+mod client;
+mod commands;
+mod config;
+mod mailurl;
+mod message;
+mod output;
+
+use anyhow::Result;
+use clap::Parser;
+
+use cli::{Cli, Cmd};
+
+fn main() -> Result<()> {
+ let cli = Cli::parse();
+
+ // `accounts` inspects the config file itself; everything else needs one
+ // resolved account.
+ if let Cmd::Accounts = cli.cmd {
+ return commands::accounts(&cli.config, cli.format);
+ }
+ let acc = config::load(&cli.config, &cli.account)?;
+
+ match cli.cmd {
+ Cmd::Accounts => unreachable!("handled above"),
+ Cmd::Folders => commands::folders(&acc, cli.format),
+ Cmd::Status { folder } => commands::status(&acc, &folder, cli.format),
+ Cmd::List {
+ folder,
+ unread,
+ query,
+ max,
+ } => commands::list(&acc, &folder, unread, query, max, cli.format),
+ Cmd::Get {
+ uid,
+ folder,
+ raw,
+ html,
+ mark_read,
+ } => commands::get(&acc, uid, &folder, raw, html, mark_read, cli.format),
+ Cmd::Send {
+ to,
+ cc,
+ subject,
+ body,
+ body_file,
+ no_record,
+ } => commands::send(&acc, &to, &cc, &subject, body, body_file, no_record),
+ Cmd::Mark {
+ state,
+ uids,
+ folder,
+ } => commands::mark(&acc, state, &uids, &folder),
+ Cmd::Move { uids, to, folder } => commands::move_cmd(&acc, &uids, &to, &folder),
+ Cmd::Delete { uids, folder } => {
+ let trash = acc.trash_folder.clone();
+ commands::move_cmd(&acc, &uids, &trash, &folder)
+ }
+ Cmd::Search { query, folder } => commands::search(&acc, &query, &folder, cli.format),
+ }
+}