mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-18 22:17:54 +08:00
add one cargo feature per backend feature
This commit is contained in:
@@ -6,13 +6,13 @@ use email::folder::add::imap::AddFolderImap;
|
||||
use email::folder::add::maildir::AddFolderMaildir;
|
||||
use log::info;
|
||||
|
||||
#[cfg(any(feature = "imap", feature = "maildir", feature = "sync"))]
|
||||
use crate::backend::BackendKind;
|
||||
#[cfg(feature = "sync")]
|
||||
use crate::cache::arg::disable::CacheDisableFlag;
|
||||
use crate::{
|
||||
account::arg::name::AccountNameFlag,
|
||||
backend::{Backend, BackendKind},
|
||||
cache::arg::disable::CacheDisableFlag,
|
||||
config::TomlConfig,
|
||||
folder::arg::name::FolderNameArg,
|
||||
printer::Printer,
|
||||
account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig,
|
||||
folder::arg::name::FolderNameArg, printer::Printer,
|
||||
};
|
||||
|
||||
/// Create a new folder.
|
||||
@@ -20,10 +20,11 @@ use crate::{
|
||||
/// This command allows you to create a new folder using the given
|
||||
/// name.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct FolderCreateCommand {
|
||||
pub struct AddFolderCommand {
|
||||
#[command(flatten)]
|
||||
pub folder: FolderNameArg,
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
#[command(flatten)]
|
||||
pub cache: CacheDisableFlag,
|
||||
|
||||
@@ -31,13 +32,14 @@ pub struct FolderCreateCommand {
|
||||
pub account: AccountNameFlag,
|
||||
}
|
||||
|
||||
impl FolderCreateCommand {
|
||||
impl AddFolderCommand {
|
||||
pub async fn execute(self, printer: &mut impl Printer, config: &TomlConfig) -> Result<()> {
|
||||
info!("executing create folder command");
|
||||
|
||||
let folder = &self.folder.name;
|
||||
let (toml_account_config, account_config) = config.clone().into_account_configs(
|
||||
self.account.name.as_ref().map(String::as_str),
|
||||
#[cfg(feature = "sync")]
|
||||
self.cache.disable,
|
||||
)?;
|
||||
|
||||
@@ -48,10 +50,16 @@ impl FolderCreateCommand {
|
||||
&account_config,
|
||||
add_folder_kind,
|
||||
|builder| match add_folder_kind {
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder.set_add_folder(|ctx| ctx.imap.as_ref().and_then(AddFolderImap::new));
|
||||
}
|
||||
#[cfg(feature = "maildir")]
|
||||
Some(BackendKind::Maildir) => {
|
||||
builder
|
||||
.set_add_folder(|ctx| ctx.maildir.as_ref().and_then(AddFolderMaildir::new));
|
||||
}
|
||||
#[cfg(feature = "sync")]
|
||||
Some(BackendKind::MaildirForSync) => {
|
||||
builder.set_add_folder(|ctx| {
|
||||
ctx.maildir_for_sync
|
||||
@@ -59,10 +67,6 @@ impl FolderCreateCommand {
|
||||
.and_then(AddFolderMaildir::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder.set_add_folder(|ctx| ctx.imap.as_ref().and_then(AddFolderImap::new));
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -8,13 +8,13 @@ use email::folder::delete::maildir::DeleteFolderMaildir;
|
||||
use log::info;
|
||||
use std::process;
|
||||
|
||||
#[cfg(any(feature = "imap", feature = "maildir", feature = "sync"))]
|
||||
use crate::backend::BackendKind;
|
||||
#[cfg(feature = "sync")]
|
||||
use crate::cache::arg::disable::CacheDisableFlag;
|
||||
use crate::{
|
||||
account::arg::name::AccountNameFlag,
|
||||
backend::{Backend, BackendKind},
|
||||
cache::arg::disable::CacheDisableFlag,
|
||||
config::TomlConfig,
|
||||
folder::arg::name::FolderNameArg,
|
||||
printer::Printer,
|
||||
account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig,
|
||||
folder::arg::name::FolderNameArg, printer::Printer,
|
||||
};
|
||||
|
||||
/// Delete a folder.
|
||||
@@ -26,6 +26,7 @@ pub struct FolderDeleteCommand {
|
||||
#[command(flatten)]
|
||||
pub folder: FolderNameArg,
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
#[command(flatten)]
|
||||
pub cache: CacheDisableFlag,
|
||||
|
||||
@@ -51,6 +52,7 @@ impl FolderDeleteCommand {
|
||||
|
||||
let (toml_account_config, account_config) = config.clone().into_account_configs(
|
||||
self.account.name.as_ref().map(String::as_str),
|
||||
#[cfg(feature = "sync")]
|
||||
self.cache.disable,
|
||||
)?;
|
||||
|
||||
@@ -61,11 +63,18 @@ impl FolderDeleteCommand {
|
||||
&account_config,
|
||||
delete_folder_kind,
|
||||
|builder| match delete_folder_kind {
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder
|
||||
.set_delete_folder(|ctx| ctx.imap.as_ref().and_then(DeleteFolderImap::new));
|
||||
}
|
||||
#[cfg(feature = "maildir")]
|
||||
Some(BackendKind::Maildir) => {
|
||||
builder.set_delete_folder(|ctx| {
|
||||
ctx.maildir.as_ref().and_then(DeleteFolderMaildir::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "sync")]
|
||||
Some(BackendKind::MaildirForSync) => {
|
||||
builder.set_delete_folder(|ctx| {
|
||||
ctx.maildir_for_sync
|
||||
@@ -73,11 +82,6 @@ impl FolderDeleteCommand {
|
||||
.and_then(DeleteFolderMaildir::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder
|
||||
.set_delete_folder(|ctx| ctx.imap.as_ref().and_then(DeleteFolderImap::new));
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -6,13 +6,13 @@ use email::folder::expunge::imap::ExpungeFolderImap;
|
||||
use email::folder::expunge::maildir::ExpungeFolderMaildir;
|
||||
use log::info;
|
||||
|
||||
#[cfg(any(feature = "imap", feature = "maildir", feature = "sync"))]
|
||||
use crate::backend::BackendKind;
|
||||
#[cfg(feature = "sync")]
|
||||
use crate::cache::arg::disable::CacheDisableFlag;
|
||||
use crate::{
|
||||
account::arg::name::AccountNameFlag,
|
||||
backend::{Backend, BackendKind},
|
||||
cache::arg::disable::CacheDisableFlag,
|
||||
config::TomlConfig,
|
||||
folder::arg::name::FolderNameArg,
|
||||
printer::Printer,
|
||||
account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig,
|
||||
folder::arg::name::FolderNameArg, printer::Printer,
|
||||
};
|
||||
|
||||
/// Expunge a folder.
|
||||
@@ -25,6 +25,7 @@ pub struct FolderExpungeCommand {
|
||||
#[command(flatten)]
|
||||
pub folder: FolderNameArg,
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
#[command(flatten)]
|
||||
pub cache: CacheDisableFlag,
|
||||
|
||||
@@ -39,6 +40,7 @@ impl FolderExpungeCommand {
|
||||
let folder = &self.folder.name;
|
||||
let (toml_account_config, account_config) = config.clone().into_account_configs(
|
||||
self.account.name.as_ref().map(String::as_str),
|
||||
#[cfg(feature = "sync")]
|
||||
self.cache.disable,
|
||||
)?;
|
||||
|
||||
@@ -49,11 +51,19 @@ impl FolderExpungeCommand {
|
||||
&account_config,
|
||||
expunge_folder_kind,
|
||||
|builder| match expunge_folder_kind {
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder.set_expunge_folder(|ctx| {
|
||||
ctx.imap.as_ref().and_then(ExpungeFolderImap::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "maildir")]
|
||||
Some(BackendKind::Maildir) => {
|
||||
builder.set_expunge_folder(|ctx| {
|
||||
ctx.maildir.as_ref().and_then(ExpungeFolderMaildir::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "sync")]
|
||||
Some(BackendKind::MaildirForSync) => {
|
||||
builder.set_expunge_folder(|ctx| {
|
||||
ctx.maildir_for_sync
|
||||
@@ -61,12 +71,6 @@ impl FolderExpungeCommand {
|
||||
.and_then(ExpungeFolderMaildir::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder.set_expunge_folder(|ctx| {
|
||||
ctx.imap.as_ref().and_then(ExpungeFolderImap::new)
|
||||
});
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -6,10 +6,13 @@ use email::folder::list::imap::ListFoldersImap;
|
||||
use email::folder::list::maildir::ListFoldersMaildir;
|
||||
use log::info;
|
||||
|
||||
#[cfg(any(feature = "imap", feature = "maildir", feature = "sync"))]
|
||||
use crate::backend::BackendKind;
|
||||
#[cfg(feature = "sync")]
|
||||
use crate::cache::arg::disable::CacheDisableFlag;
|
||||
use crate::{
|
||||
account::arg::name::AccountNameFlag,
|
||||
backend::{Backend, BackendKind},
|
||||
cache::arg::disable::CacheDisableFlag,
|
||||
backend::Backend,
|
||||
config::TomlConfig,
|
||||
folder::Folders,
|
||||
printer::{PrintTableOpts, Printer},
|
||||
@@ -24,6 +27,7 @@ pub struct FolderListCommand {
|
||||
#[command(flatten)]
|
||||
pub table: TableMaxWidthFlag,
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
#[command(flatten)]
|
||||
pub cache: CacheDisableFlag,
|
||||
|
||||
@@ -37,6 +41,7 @@ impl FolderListCommand {
|
||||
|
||||
let (toml_account_config, account_config) = config.clone().into_account_configs(
|
||||
self.account.name.as_ref().map(String::as_str),
|
||||
#[cfg(feature = "sync")]
|
||||
self.cache.disable,
|
||||
)?;
|
||||
|
||||
@@ -47,11 +52,18 @@ impl FolderListCommand {
|
||||
&account_config,
|
||||
list_folders_kind,
|
||||
|builder| match list_folders_kind {
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder
|
||||
.set_list_folders(|ctx| ctx.imap.as_ref().and_then(ListFoldersImap::new));
|
||||
}
|
||||
#[cfg(feature = "maildir")]
|
||||
Some(BackendKind::Maildir) => {
|
||||
builder.set_list_folders(|ctx| {
|
||||
ctx.maildir.as_ref().and_then(ListFoldersMaildir::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "sync")]
|
||||
Some(BackendKind::MaildirForSync) => {
|
||||
builder.set_list_folders(|ctx| {
|
||||
ctx.maildir_for_sync
|
||||
@@ -59,11 +71,6 @@ impl FolderListCommand {
|
||||
.and_then(ListFoldersMaildir::new)
|
||||
});
|
||||
}
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder
|
||||
.set_list_folders(|ctx| ctx.imap.as_ref().and_then(ListFoldersImap::new));
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
#[cfg(feature = "folder-add")]
|
||||
mod create;
|
||||
#[cfg(feature = "folder-delete")]
|
||||
mod delete;
|
||||
#[cfg(feature = "folder-expunge")]
|
||||
mod expunge;
|
||||
#[cfg(feature = "folder-list")]
|
||||
mod list;
|
||||
#[cfg(feature = "folder-purge")]
|
||||
mod purge;
|
||||
|
||||
use anyhow::Result;
|
||||
@@ -9,10 +14,16 @@ use clap::Subcommand;
|
||||
|
||||
use crate::{config::TomlConfig, printer::Printer};
|
||||
|
||||
use self::{
|
||||
create::FolderCreateCommand, delete::FolderDeleteCommand, expunge::FolderExpungeCommand,
|
||||
list::FolderListCommand, purge::FolderPurgeCommand,
|
||||
};
|
||||
#[cfg(feature = "folder-add")]
|
||||
use self::create::AddFolderCommand;
|
||||
#[cfg(feature = "folder-delete")]
|
||||
use self::delete::FolderDeleteCommand;
|
||||
#[cfg(feature = "folder-expunge")]
|
||||
use self::expunge::FolderExpungeCommand;
|
||||
#[cfg(feature = "folder-list")]
|
||||
use self::list::FolderListCommand;
|
||||
#[cfg(feature = "folder-purge")]
|
||||
use self::purge::FolderPurgeCommand;
|
||||
|
||||
/// Manage folders.
|
||||
///
|
||||
@@ -20,29 +31,40 @@ use self::{
|
||||
/// emails. This subcommand allows you to manage them.
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum FolderSubcommand {
|
||||
#[command(alias = "add", alias = "new")]
|
||||
Create(FolderCreateCommand),
|
||||
#[cfg(feature = "folder-add")]
|
||||
#[command(visible_alias = "create", alias = "new")]
|
||||
Add(AddFolderCommand),
|
||||
|
||||
#[cfg(feature = "folder-list")]
|
||||
#[command(alias = "lst")]
|
||||
List(FolderListCommand),
|
||||
|
||||
#[cfg(feature = "folder-expunge")]
|
||||
#[command()]
|
||||
Expunge(FolderExpungeCommand),
|
||||
|
||||
#[cfg(feature = "folder-purge")]
|
||||
#[command()]
|
||||
Purge(FolderPurgeCommand),
|
||||
|
||||
#[cfg(feature = "folder-delete")]
|
||||
#[command(alias = "remove", alias = "rm")]
|
||||
Delete(FolderDeleteCommand),
|
||||
}
|
||||
|
||||
impl FolderSubcommand {
|
||||
#[allow(unused)]
|
||||
pub async fn execute(self, printer: &mut impl Printer, config: &TomlConfig) -> Result<()> {
|
||||
match self {
|
||||
Self::Create(cmd) => cmd.execute(printer, config).await,
|
||||
#[cfg(feature = "folder-add")]
|
||||
Self::Add(cmd) => cmd.execute(printer, config).await,
|
||||
#[cfg(feature = "folder-list")]
|
||||
Self::List(cmd) => cmd.execute(printer, config).await,
|
||||
#[cfg(feature = "folder-expunge")]
|
||||
Self::Expunge(cmd) => cmd.execute(printer, config).await,
|
||||
#[cfg(feature = "folder-purge")]
|
||||
Self::Purge(cmd) => cmd.execute(printer, config).await,
|
||||
#[cfg(feature = "folder-delete")]
|
||||
Self::Delete(cmd) => cmd.execute(printer, config).await,
|
||||
}
|
||||
}
|
||||
|
||||
+15
-11
@@ -6,13 +6,13 @@ use email::folder::purge::imap::PurgeFolderImap;
|
||||
use log::info;
|
||||
use std::process;
|
||||
|
||||
#[cfg(any(feature = "imap", feature = "maildir", feature = "sync"))]
|
||||
use crate::backend::BackendKind;
|
||||
#[cfg(feature = "sync")]
|
||||
use crate::cache::arg::disable::CacheDisableFlag;
|
||||
use crate::{
|
||||
account::arg::name::AccountNameFlag,
|
||||
backend::{Backend, BackendKind},
|
||||
cache::arg::disable::CacheDisableFlag,
|
||||
config::TomlConfig,
|
||||
folder::arg::name::FolderNameArg,
|
||||
printer::Printer,
|
||||
account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig,
|
||||
folder::arg::name::FolderNameArg, printer::Printer,
|
||||
};
|
||||
|
||||
/// Purge a folder.
|
||||
@@ -24,6 +24,7 @@ pub struct FolderPurgeCommand {
|
||||
#[command(flatten)]
|
||||
pub folder: FolderNameArg,
|
||||
|
||||
#[cfg(feature = "sync")]
|
||||
#[command(flatten)]
|
||||
pub cache: CacheDisableFlag,
|
||||
|
||||
@@ -49,6 +50,7 @@ impl FolderPurgeCommand {
|
||||
|
||||
let (toml_account_config, account_config) = config.clone().into_account_configs(
|
||||
self.account.name.as_ref().map(String::as_str),
|
||||
#[cfg(feature = "sync")]
|
||||
self.cache.disable,
|
||||
)?;
|
||||
|
||||
@@ -59,12 +61,19 @@ impl FolderPurgeCommand {
|
||||
&account_config,
|
||||
purge_folder_kind,
|
||||
|builder| match purge_folder_kind {
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder
|
||||
.set_purge_folder(|ctx| ctx.imap.as_ref().and_then(PurgeFolderImap::new));
|
||||
}
|
||||
// TODO
|
||||
// #[cfg(feature = "maildir")]
|
||||
// Some(BackendKind::Maildir) => {
|
||||
// builder.set_purge_folder(|ctx| {
|
||||
// ctx.maildir.as_ref().and_then(PurgeFolderMaildir::new)
|
||||
// });
|
||||
// }
|
||||
// #[cfg(feature = "sync")]
|
||||
// Some(BackendKind::MaildirForSync) => {
|
||||
// builder.set_purge_folder(|ctx| {
|
||||
// ctx.maildir_for_sync
|
||||
@@ -72,11 +81,6 @@ impl FolderPurgeCommand {
|
||||
// .and_then(PurgeFolderMaildir::new)
|
||||
// });
|
||||
// }
|
||||
#[cfg(feature = "imap")]
|
||||
Some(BackendKind::Imap) => {
|
||||
builder
|
||||
.set_purge_folder(|ctx| ctx.imap.as_ref().and_then(PurgeFolderImap::new));
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user