mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 21:37:55 +08:00
move watch command from folder to envelope
This commit is contained in:
@@ -3,7 +3,6 @@ mod delete;
|
||||
mod expunge;
|
||||
mod list;
|
||||
mod purge;
|
||||
mod watch;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Subcommand;
|
||||
@@ -12,7 +11,7 @@ use crate::{config::TomlConfig, printer::Printer};
|
||||
|
||||
use self::{
|
||||
create::FolderCreateCommand, delete::FolderDeleteCommand, expunge::FolderExpungeCommand,
|
||||
list::FolderListCommand, purge::FolderPurgeCommand, watch::FolderWatchCommand,
|
||||
list::FolderListCommand, purge::FolderPurgeCommand,
|
||||
};
|
||||
|
||||
/// Manage folders.
|
||||
@@ -27,9 +26,6 @@ pub enum FolderSubcommand {
|
||||
#[command(alias = "lst")]
|
||||
List(FolderListCommand),
|
||||
|
||||
#[command()]
|
||||
Watch(FolderWatchCommand),
|
||||
|
||||
#[command()]
|
||||
Expunge(FolderExpungeCommand),
|
||||
|
||||
@@ -45,7 +41,6 @@ impl FolderSubcommand {
|
||||
match self {
|
||||
Self::Create(cmd) => cmd.execute(printer, config).await,
|
||||
Self::List(cmd) => cmd.execute(printer, config).await,
|
||||
Self::Watch(cmd) => cmd.execute(printer, config).await,
|
||||
Self::Expunge(cmd) => cmd.execute(printer, config).await,
|
||||
Self::Purge(cmd) => cmd.execute(printer, config).await,
|
||||
Self::Delete(cmd) => cmd.execute(printer, config).await,
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use log::info;
|
||||
|
||||
use crate::{
|
||||
account::arg::name::AccountNameFlag, backend::Backend, cache::arg::disable::CacheDisableFlag,
|
||||
config::TomlConfig, folder::arg::name::FolderNameArg, printer::Printer,
|
||||
};
|
||||
|
||||
/// Watch a folder for changes.
|
||||
///
|
||||
/// This command allows you to watch a new folder using the given
|
||||
/// name.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct FolderWatchCommand {
|
||||
#[command(flatten)]
|
||||
pub folder: FolderNameArg,
|
||||
|
||||
#[command(flatten)]
|
||||
pub cache: CacheDisableFlag,
|
||||
|
||||
#[command(flatten)]
|
||||
pub account: AccountNameFlag,
|
||||
}
|
||||
|
||||
impl FolderWatchCommand {
|
||||
pub async fn execute(self, printer: &mut impl Printer, config: &TomlConfig) -> Result<()> {
|
||||
info!("executing folder watch command");
|
||||
|
||||
let folder = &self.folder.name;
|
||||
|
||||
let some_account_name = self.account.name.as_ref().map(String::as_str);
|
||||
let (toml_account_config, account_config) = config
|
||||
.clone()
|
||||
.into_account_configs(some_account_name, self.cache.disable)?;
|
||||
let backend = Backend::new(toml_account_config, account_config.clone(), false).await?;
|
||||
|
||||
printer.print_log(format!("Start watching folder {folder} for changes…"))?;
|
||||
|
||||
backend.watch_emails(&folder).await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user