mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
improve logging, replace log-level by RUST_LOG
This commit is contained in:
+19
-20
@@ -1,44 +1,43 @@
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use clap;
|
||||
use error_chain::error_chain;
|
||||
use log::debug;
|
||||
|
||||
use crate::{config::model::Account, imap::model::ImapConnector, msg::cli::uid_arg};
|
||||
use crate::{app::App, imap::model::ImapConnector, msg::cli::uid_arg};
|
||||
|
||||
error_chain! {
|
||||
links {
|
||||
Config(crate::config::model::Error, crate::config::model::ErrorKind);
|
||||
Imap(crate::imap::model::Error, crate::imap::model::ErrorKind);
|
||||
}
|
||||
}
|
||||
|
||||
fn flags_arg<'a>() -> Arg<'a, 'a> {
|
||||
Arg::with_name("flags")
|
||||
fn flags_arg<'a>() -> clap::Arg<'a, 'a> {
|
||||
clap::Arg::with_name("flags")
|
||||
.help("IMAP flags (see https://tools.ietf.org/html/rfc3501#page-11)")
|
||||
.value_name("FLAGS…")
|
||||
.multiple(true)
|
||||
.required(true)
|
||||
}
|
||||
|
||||
pub fn flag_subcmds<'s>() -> Vec<App<'s, 's>> {
|
||||
vec![SubCommand::with_name("flags")
|
||||
pub fn flag_subcmds<'a>() -> Vec<clap::App<'a, 'a>> {
|
||||
vec![clap::SubCommand::with_name("flags")
|
||||
.aliases(&["flag"])
|
||||
.about("Handles flags")
|
||||
.subcommand(
|
||||
SubCommand::with_name("set")
|
||||
clap::SubCommand::with_name("set")
|
||||
.aliases(&["s"])
|
||||
.about("Replaces all message flags")
|
||||
.arg(uid_arg())
|
||||
.arg(flags_arg()),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("add")
|
||||
clap::SubCommand::with_name("add")
|
||||
.aliases(&["a"])
|
||||
.about("Appends flags to a message")
|
||||
.arg(uid_arg())
|
||||
.arg(flags_arg()),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("remove")
|
||||
clap::SubCommand::with_name("remove")
|
||||
.aliases(&["rm", "r"])
|
||||
.about("Removes flags from a message")
|
||||
.arg(uid_arg())
|
||||
@@ -46,8 +45,8 @@ pub fn flag_subcmds<'s>() -> Vec<App<'s, 's>> {
|
||||
)]
|
||||
}
|
||||
|
||||
pub fn flag_matches(account: &Account, mbox: &str, matches: &ArgMatches) -> Result<bool> {
|
||||
if let Some(matches) = matches.subcommand_matches("set") {
|
||||
pub fn flag_matches(app: &App) -> Result<bool> {
|
||||
if let Some(matches) = app.arg_matches.subcommand_matches("set") {
|
||||
debug!("set command matched");
|
||||
|
||||
let uid = matches.value_of("uid").unwrap();
|
||||
@@ -56,14 +55,14 @@ pub fn flag_matches(account: &Account, mbox: &str, matches: &ArgMatches) -> Resu
|
||||
let flags = matches.value_of("flags").unwrap();
|
||||
debug!("flags: {}", flags);
|
||||
|
||||
let mut imap_conn = ImapConnector::new(&account)?;
|
||||
imap_conn.set_flags(mbox, uid, flags)?;
|
||||
let mut imap_conn = ImapConnector::new(&app.account)?;
|
||||
imap_conn.set_flags(app.mbox, uid, flags)?;
|
||||
|
||||
imap_conn.logout();
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("add") {
|
||||
if let Some(matches) = app.arg_matches.subcommand_matches("add") {
|
||||
debug!("add command matched");
|
||||
|
||||
let uid = matches.value_of("uid").unwrap();
|
||||
@@ -72,14 +71,14 @@ pub fn flag_matches(account: &Account, mbox: &str, matches: &ArgMatches) -> Resu
|
||||
let flags = matches.value_of("flags").unwrap();
|
||||
debug!("flags: {}", flags);
|
||||
|
||||
let mut imap_conn = ImapConnector::new(&account)?;
|
||||
imap_conn.add_flags(mbox, uid, flags)?;
|
||||
let mut imap_conn = ImapConnector::new(&app.account)?;
|
||||
imap_conn.add_flags(app.mbox, uid, flags)?;
|
||||
|
||||
imap_conn.logout();
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("remove") {
|
||||
if let Some(matches) = app.arg_matches.subcommand_matches("remove") {
|
||||
debug!("remove command matched");
|
||||
|
||||
let uid = matches.value_of("uid").unwrap();
|
||||
@@ -88,8 +87,8 @@ pub fn flag_matches(account: &Account, mbox: &str, matches: &ArgMatches) -> Resu
|
||||
let flags = matches.value_of("flags").unwrap();
|
||||
debug!("flags: {}", flags);
|
||||
|
||||
let mut imap_conn = ImapConnector::new(&account)?;
|
||||
imap_conn.remove_flags(mbox, uid, flags)?;
|
||||
let mut imap_conn = ImapConnector::new(&app.account)?;
|
||||
imap_conn.remove_flags(app.mbox, uid, flags)?;
|
||||
|
||||
imap_conn.logout();
|
||||
return Ok(true);
|
||||
|
||||
Reference in New Issue
Block a user