mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-20 15:11:11 +00:00
add silent flag (#74)
This commit is contained in:
parent
8e6740db65
commit
ebf1b854be
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Wiki entry for Gmail users [#58]
|
- Wiki entry for Gmail users [#58]
|
||||||
|
- Info logs for copy/move/delete cmd + silent mode [#74]
|
||||||
|
|
||||||
## [0.2.3] - 2021-04-08
|
## [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
|
[#58]: https://github.com/soywod/himalaya/issues/58
|
||||||
[#61]: https://github.com/soywod/himalaya/issues/61
|
[#61]: https://github.com/soywod/himalaya/issues/61
|
||||||
[#71]: https://github.com/soywod/himalaya/issues/71
|
[#71]: https://github.com/soywod/himalaya/issues/71
|
||||||
|
[#74]: https://github.com/soywod/himalaya/issues/74
|
||||||
[#75]: https://github.com/soywod/himalaya/issues/75
|
[#75]: https://github.com/soywod/himalaya/issues/75
|
||||||
|
|
|
@ -82,15 +82,16 @@ for all the options.*
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
himalaya 0.2.0
|
himalaya 0.2.3
|
||||||
soywod <clement.douin@posteo.net>
|
soywod <clement.douin@posteo.net>
|
||||||
📫 Minimalist CLI email client
|
📫 Minimalist CLI email client
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
himalaya [OPTIONS] [SUBCOMMAND]
|
himalaya [FLAGS] [OPTIONS] [SUBCOMMAND]
|
||||||
|
|
||||||
FLAGS:
|
FLAGS:
|
||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
|
-s, --silent Disables any output
|
||||||
-V, --version Prints version information
|
-V, --version Prints version information
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
|
|
|
@ -36,7 +36,7 @@ use crate::{
|
||||||
imap::cli::{imap_matches, imap_subcmds},
|
imap::cli::{imap_matches, imap_subcmds},
|
||||||
mbox::cli::{mbox_matches, mbox_source_arg, mbox_subcmds},
|
mbox::cli::{mbox_matches, mbox_source_arg, mbox_subcmds},
|
||||||
msg::cli::{msg_matches, msg_subcmds},
|
msg::cli::{msg_matches, msg_subcmds},
|
||||||
output::cli::output_arg,
|
output::cli::output_args,
|
||||||
};
|
};
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
|
@ -53,7 +53,7 @@ fn run() -> Result<()> {
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
.about(env!("CARGO_PKG_DESCRIPTION"))
|
.about(env!("CARGO_PKG_DESCRIPTION"))
|
||||||
.author(env!("CARGO_PKG_AUTHORS"))
|
.author(env!("CARGO_PKG_AUTHORS"))
|
||||||
.arg(output_arg())
|
.args(&output_args())
|
||||||
.arg(account_arg())
|
.arg(account_arg())
|
||||||
.arg(mbox_source_arg())
|
.arg(mbox_source_arg())
|
||||||
.subcommands(flag_subcmds())
|
.subcommands(flag_subcmds())
|
||||||
|
|
|
@ -37,11 +37,12 @@ pub fn mbox_matches(matches: &ArgMatches) -> Result<bool> {
|
||||||
let config = Config::new_from_file()?;
|
let config = Config::new_from_file()?;
|
||||||
let account = config.find_account_by_name(matches.value_of("account"))?;
|
let account = config.find_account_by_name(matches.value_of("account"))?;
|
||||||
let output_fmt = matches.value_of("output").unwrap();
|
let output_fmt = matches.value_of("output").unwrap();
|
||||||
|
let silent = matches.is_present("silent");
|
||||||
|
|
||||||
if let Some(_) = matches.subcommand_matches("mailboxes") {
|
if let Some(_) = matches.subcommand_matches("mailboxes") {
|
||||||
let mut imap_conn = ImapConnector::new(&account)?;
|
let mut imap_conn = ImapConnector::new(&account)?;
|
||||||
let mboxes = imap_conn.list_mboxes()?;
|
let mboxes = imap_conn.list_mboxes()?;
|
||||||
print(&output_fmt, mboxes)?;
|
print(&output_fmt, &silent, mboxes)?;
|
||||||
imap_conn.logout();
|
imap_conn.logout();
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,6 +163,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
let config = Config::new_from_file()?;
|
let config = Config::new_from_file()?;
|
||||||
let account = config.find_account_by_name(matches.value_of("account"))?;
|
let account = config.find_account_by_name(matches.value_of("account"))?;
|
||||||
let output_fmt = matches.value_of("output").unwrap();
|
let output_fmt = matches.value_of("output").unwrap();
|
||||||
|
let silent = matches.is_present("silent");
|
||||||
let mbox = matches.value_of("mailbox").unwrap();
|
let mbox = matches.value_of("mailbox").unwrap();
|
||||||
|
|
||||||
if let Some(matches) = matches.subcommand_matches("list") {
|
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 page: usize = matches.value_of("page").unwrap().parse().unwrap();
|
||||||
let msgs = imap_conn.list_msgs(&mbox, &page_size, &page)?;
|
let msgs = imap_conn.list_msgs(&mbox, &page_size, &page)?;
|
||||||
let msgs = Msgs::from(&msgs);
|
let msgs = Msgs::from(&msgs);
|
||||||
print(&output_fmt, msgs)?;
|
print(&output_fmt, &silent, msgs)?;
|
||||||
imap_conn.logout();
|
imap_conn.logout();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -206,7 +207,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
.join(" ");
|
.join(" ");
|
||||||
let msgs = imap_conn.search_msgs(&mbox, &query, &page_size, &page)?;
|
let msgs = imap_conn.search_msgs(&mbox, &query, &page_size, &page)?;
|
||||||
let msgs = Msgs::from(&msgs);
|
let msgs = Msgs::from(&msgs);
|
||||||
print(&output_fmt, msgs)?;
|
print(&output_fmt, &silent, msgs)?;
|
||||||
imap_conn.logout();
|
imap_conn.logout();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -217,7 +218,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
let mime = format!("text/{}", matches.value_of("mime-type").unwrap());
|
let mime = format!("text/{}", matches.value_of("mime-type").unwrap());
|
||||||
let msg = imap_conn.read_msg(&mbox, &uid)?;
|
let msg = imap_conn.read_msg(&mbox, &uid)?;
|
||||||
let msg = ReadableMsg::from_bytes(&mime, &msg)?;
|
let msg = ReadableMsg::from_bytes(&mime, &msg)?;
|
||||||
print(&output_fmt, msg)?;
|
print(&output_fmt, &silent, msg)?;
|
||||||
imap_conn.logout();
|
imap_conn.logout();
|
||||||
return Ok(());
|
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) = matches.subcommand_matches("template") {
|
||||||
if let Some(_) = matches.subcommand_matches("new") {
|
if let Some(_) = matches.subcommand_matches("new") {
|
||||||
let tpl = Msg::build_new_tpl(&config, &account)?;
|
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") {
|
if let Some(matches) = matches.subcommand_matches("reply") {
|
||||||
|
@ -316,7 +317,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
} else {
|
} else {
|
||||||
msg.build_reply_tpl(&config, &account)?
|
msg.build_reply_tpl(&config, &account)?
|
||||||
};
|
};
|
||||||
print(&output_fmt, &tpl)?;
|
print(&output_fmt, &silent, &tpl)?;
|
||||||
imap_conn.logout();
|
imap_conn.logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +326,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
let uid = matches.value_of("uid").unwrap();
|
let uid = matches.value_of("uid").unwrap();
|
||||||
let msg = Msg::from(imap_conn.read_msg(&mbox, &uid)?);
|
let msg = Msg::from(imap_conn.read_msg(&mbox, &uid)?);
|
||||||
let tpl = msg.build_forward_tpl(&config, &account)?;
|
let tpl = msg.build_forward_tpl(&config, &account)?;
|
||||||
print(&output_fmt, &tpl)?;
|
print(&output_fmt, &silent, &tpl)?;
|
||||||
imap_conn.logout();
|
imap_conn.logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,6 +441,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
|
|
||||||
print(
|
print(
|
||||||
&output_fmt,
|
&output_fmt,
|
||||||
|
&silent,
|
||||||
Info(format!(
|
Info(format!(
|
||||||
"Message {} successfully copied to folder `{}`",
|
"Message {} successfully copied to folder `{}`",
|
||||||
&uid, &target
|
&uid, &target
|
||||||
|
@ -461,6 +463,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
|
|
||||||
print(
|
print(
|
||||||
&output_fmt,
|
&output_fmt,
|
||||||
|
&silent,
|
||||||
Info(format!(
|
Info(format!(
|
||||||
"Message {} successfully moved to folder `{}`",
|
"Message {} successfully moved to folder `{}`",
|
||||||
&uid, &target
|
&uid, &target
|
||||||
|
@ -477,6 +480,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
|
|
||||||
print(
|
print(
|
||||||
&output_fmt,
|
&output_fmt,
|
||||||
|
&silent,
|
||||||
Info(format!("Message {} successfully deleted", &uid)),
|
Info(format!("Message {} successfully deleted", &uid)),
|
||||||
)?;
|
)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -506,7 +510,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
let mut imap_conn = ImapConnector::new(&account)?;
|
let mut imap_conn = ImapConnector::new(&account)?;
|
||||||
let msgs = imap_conn.list_msgs(&mbox, &10, &0)?;
|
let msgs = imap_conn.list_msgs(&mbox, &10, &0)?;
|
||||||
let msgs = Msgs::from(&msgs);
|
let msgs = Msgs::from(&msgs);
|
||||||
print(&output_fmt, msgs)?;
|
print(&output_fmt, &silent, msgs)?;
|
||||||
imap_conn.logout();
|
imap_conn.logout();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
use clap::Arg;
|
use clap::Arg;
|
||||||
|
|
||||||
pub fn output_arg<'a>() -> Arg<'a, 'a> {
|
pub fn output_args<'a>() -> Vec<Arg<'a, 'a>> {
|
||||||
Arg::with_name("output")
|
vec![
|
||||||
.long("output")
|
Arg::with_name("output")
|
||||||
.short("o")
|
.long("output")
|
||||||
.help("Defines the output format")
|
.short("o")
|
||||||
.value_name("STRING")
|
.help("Defines the output format")
|
||||||
.possible_values(&["plain", "json"])
|
.value_name("STRING")
|
||||||
.default_value("plain")
|
.possible_values(&["plain", "json"])
|
||||||
|
.default_value("plain"),
|
||||||
|
Arg::with_name("silent")
|
||||||
|
.long("silent")
|
||||||
|
.short("s")
|
||||||
|
.help("Disables any output"),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,13 +41,15 @@ pub fn run_cmd(cmd: &str) -> Result<String> {
|
||||||
Ok(String::from_utf8(output.stdout)?)
|
Ok(String::from_utf8(output.stdout)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print<T: fmt::Display + Serialize>(output_type: &str, item: T) -> Result<()> {
|
pub fn print<T: fmt::Display + Serialize>(output_type: &str, silent: &bool, item: T) -> Result<()> {
|
||||||
match output_type {
|
if silent == &false {
|
||||||
"json" => print!(
|
match output_type {
|
||||||
"{}",
|
"json" => print!(
|
||||||
serde_json::to_string(&item).chain_err(|| "Could not decode JSON")?
|
"{}",
|
||||||
),
|
serde_json::to_string(&item).chain_err(|| "Could not decode JSON")?
|
||||||
"text" | _ => println!("{}", item.to_string()),
|
),
|
||||||
|
"text" | _ => println!("{}", item.to_string()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue