Files
himalaya/src/folder/command/add.rs
T
Perma Alesheikh 5a0ff83a5e replace anyhow and log with color_eyre and tracing
Since Himalaya is intended to be ran as a CLI in the terminal emulator
environment, their user experience could vastly improve with better and
more colorful error messages and logging.

This change will replace more minimal libraries for error-reporting/han-
dling with their more advanced counterparts.

Since these crates have tight integrations, this commit will change both
in one shot.

Also we have don't need env_logger any more. So I also have removed that
guy as well.

Signed-off-by: Perma Alesheikh <me@prma.dev>
2024-04-15 12:17:56 +02:00

56 lines
1.6 KiB
Rust

use clap::Parser;
use color_eyre::Result;
use email::{backend::feature::BackendFeatureSource, folder::add::AddFolder};
use tracing::info;
#[cfg(feature = "account-sync")]
use crate::cache::arg::disable::CacheDisableFlag;
use crate::{
account::arg::name::AccountNameFlag, backend::Backend, config::TomlConfig,
folder::arg::name::FolderNameArg, printer::Printer,
};
/// Create a new folder.
///
/// This command allows you to create a new folder using the given
/// name.
#[derive(Debug, Parser)]
pub struct AddFolderCommand {
#[command(flatten)]
pub folder: FolderNameArg,
#[cfg(feature = "account-sync")]
#[command(flatten)]
pub cache: CacheDisableFlag,
#[command(flatten)]
pub account: AccountNameFlag,
}
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_deref(),
#[cfg(feature = "account-sync")]
self.cache.disable,
)?;
let add_folder_kind = toml_account_config.add_folder_kind();
let backend = Backend::new(
toml_account_config.clone(),
account_config,
add_folder_kind,
|builder| builder.set_add_folder(BackendFeatureSource::Context),
)
.await?;
backend.add_folder(folder).await?;
printer.print(format!("Folder {folder} successfully created!"))
}
}