diff --git a/CHANGELOG.md b/CHANGELOG.md index 58d6041..5f09d4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Wiki entry for Gmail users [#58] +- Info logs for copy/move/delete cmd + silent mode [#74] ## [0.2.3] - 2021-04-08 @@ -132,4 +133,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#58]: https://github.com/soywod/himalaya/issues/58 [#61]: https://github.com/soywod/himalaya/issues/61 [#71]: https://github.com/soywod/himalaya/issues/71 +[#74]: https://github.com/soywod/himalaya/issues/74 [#75]: https://github.com/soywod/himalaya/issues/75 diff --git a/README.md b/README.md index 372025a..d864a82 100644 --- a/README.md +++ b/README.md @@ -82,15 +82,16 @@ for all the options.* ## Usage ``` -himalaya 0.2.0 +himalaya 0.2.3 soywod 📫 Minimalist CLI email client USAGE: - himalaya [OPTIONS] [SUBCOMMAND] + himalaya [FLAGS] [OPTIONS] [SUBCOMMAND] FLAGS: -h, --help Prints help information + -s, --silent Disables any output -V, --version Prints version information OPTIONS: diff --git a/src/main.rs b/src/main.rs index 48851d5..8785e99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,7 @@ use crate::{ imap::cli::{imap_matches, imap_subcmds}, mbox::cli::{mbox_matches, mbox_source_arg, mbox_subcmds}, msg::cli::{msg_matches, msg_subcmds}, - output::cli::output_arg, + output::cli::output_args, }; error_chain! { @@ -53,7 +53,7 @@ fn run() -> Result<()> { .version(env!("CARGO_PKG_VERSION")) .about(env!("CARGO_PKG_DESCRIPTION")) .author(env!("CARGO_PKG_AUTHORS")) - .arg(output_arg()) + .args(&output_args()) .arg(account_arg()) .arg(mbox_source_arg()) .subcommands(flag_subcmds()) diff --git a/src/mbox/cli.rs b/src/mbox/cli.rs index eff0067..2fea2b7 100644 --- a/src/mbox/cli.rs +++ b/src/mbox/cli.rs @@ -37,11 +37,12 @@ pub fn mbox_matches(matches: &ArgMatches) -> Result { let config = Config::new_from_file()?; let account = config.find_account_by_name(matches.value_of("account"))?; let output_fmt = matches.value_of("output").unwrap(); + let silent = matches.is_present("silent"); if let Some(_) = matches.subcommand_matches("mailboxes") { let mut imap_conn = ImapConnector::new(&account)?; let mboxes = imap_conn.list_mboxes()?; - print(&output_fmt, mboxes)?; + print(&output_fmt, &silent, mboxes)?; imap_conn.logout(); return Ok(true); } diff --git a/src/msg/cli.rs b/src/msg/cli.rs index 0ab0774..66c242a 100644 --- a/src/msg/cli.rs +++ b/src/msg/cli.rs @@ -163,6 +163,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> { let config = Config::new_from_file()?; let account = config.find_account_by_name(matches.value_of("account"))?; let output_fmt = matches.value_of("output").unwrap(); + let silent = matches.is_present("silent"); let mbox = matches.value_of("mailbox").unwrap(); if let Some(matches) = matches.subcommand_matches("list") { @@ -171,7 +172,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> { let page: usize = matches.value_of("page").unwrap().parse().unwrap(); let msgs = imap_conn.list_msgs(&mbox, &page_size, &page)?; let msgs = Msgs::from(&msgs); - print(&output_fmt, msgs)?; + print(&output_fmt, &silent, msgs)?; imap_conn.logout(); return Ok(()); } @@ -206,7 +207,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> { .join(" "); let msgs = imap_conn.search_msgs(&mbox, &query, &page_size, &page)?; let msgs = Msgs::from(&msgs); - print(&output_fmt, msgs)?; + print(&output_fmt, &silent, msgs)?; imap_conn.logout(); return Ok(()); } @@ -217,7 +218,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> { let mime = format!("text/{}", matches.value_of("mime-type").unwrap()); let msg = imap_conn.read_msg(&mbox, &uid)?; let msg = ReadableMsg::from_bytes(&mime, &msg)?; - print(&output_fmt, msg)?; + print(&output_fmt, &silent, msg)?; imap_conn.logout(); return Ok(()); } @@ -304,7 +305,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> { if let Some(matches) = matches.subcommand_matches("template") { if let Some(_) = matches.subcommand_matches("new") { let tpl = Msg::build_new_tpl(&config, &account)?; - print(&output_fmt, &tpl)?; + print(&output_fmt, &silent, &tpl)?; } if let Some(matches) = matches.subcommand_matches("reply") { @@ -316,7 +317,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> { } else { msg.build_reply_tpl(&config, &account)? }; - print(&output_fmt, &tpl)?; + print(&output_fmt, &silent, &tpl)?; imap_conn.logout(); } @@ -325,7 +326,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> { let uid = matches.value_of("uid").unwrap(); let msg = Msg::from(imap_conn.read_msg(&mbox, &uid)?); let tpl = msg.build_forward_tpl(&config, &account)?; - print(&output_fmt, &tpl)?; + print(&output_fmt, &silent, &tpl)?; imap_conn.logout(); } @@ -440,6 +441,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> { print( &output_fmt, + &silent, Info(format!( "Message {} successfully copied to folder `{}`", &uid, &target @@ -461,6 +463,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> { print( &output_fmt, + &silent, Info(format!( "Message {} successfully moved to folder `{}`", &uid, &target @@ -477,6 +480,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> { print( &output_fmt, + &silent, Info(format!("Message {} successfully deleted", &uid)), )?; return Ok(()); @@ -506,7 +510,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> { let mut imap_conn = ImapConnector::new(&account)?; let msgs = imap_conn.list_msgs(&mbox, &10, &0)?; let msgs = Msgs::from(&msgs); - print(&output_fmt, msgs)?; + print(&output_fmt, &silent, msgs)?; imap_conn.logout(); Ok(()) } diff --git a/src/output/cli.rs b/src/output/cli.rs index c5a8e9c..4cc6fdc 100644 --- a/src/output/cli.rs +++ b/src/output/cli.rs @@ -1,11 +1,17 @@ use clap::Arg; -pub fn output_arg<'a>() -> Arg<'a, 'a> { - Arg::with_name("output") - .long("output") - .short("o") - .help("Defines the output format") - .value_name("STRING") - .possible_values(&["plain", "json"]) - .default_value("plain") +pub fn output_args<'a>() -> Vec> { + vec![ + Arg::with_name("output") + .long("output") + .short("o") + .help("Defines the output format") + .value_name("STRING") + .possible_values(&["plain", "json"]) + .default_value("plain"), + Arg::with_name("silent") + .long("silent") + .short("s") + .help("Disables any output"), + ] } diff --git a/src/output/utils.rs b/src/output/utils.rs index 3ec4b5b..56a413e 100644 --- a/src/output/utils.rs +++ b/src/output/utils.rs @@ -41,13 +41,15 @@ pub fn run_cmd(cmd: &str) -> Result { Ok(String::from_utf8(output.stdout)?) } -pub fn print(output_type: &str, item: T) -> Result<()> { - match output_type { - "json" => print!( - "{}", - serde_json::to_string(&item).chain_err(|| "Could not decode JSON")? - ), - "text" | _ => println!("{}", item.to_string()), +pub fn print(output_type: &str, silent: &bool, item: T) -> Result<()> { + if silent == &false { + match output_type { + "json" => print!( + "{}", + serde_json::to_string(&item).chain_err(|| "Could not decode JSON")? + ), + "text" | _ => println!("{}", item.to_string()), + } } Ok(())