refactor backend system, remove accouts flattening

This commit is contained in:
Clément DOUIN
2024-02-21 11:38:50 +01:00
parent 76ab833a62
commit 3e0cf0cfda
59 changed files with 377 additions and 1591 deletions
+8 -33
View File
@@ -2,25 +2,18 @@ use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[cfg(feature = "account-subcmd")]
use crate::account::command::AccountSubcommand;
#[cfg(feature = "envelope-subcmd")]
use crate::envelope::command::EnvelopeSubcommand;
#[cfg(feature = "flag-subcmd")]
use crate::flag::command::FlagSubcommand;
#[cfg(feature = "folder-subcmd")]
use crate::folder::command::FolderSubcommand;
#[cfg(feature = "attachment-subcmd")]
use crate::message::attachment::command::AttachmentSubcommand;
#[cfg(feature = "message-subcmd")]
use crate::message::command::MessageSubcommand;
#[cfg(feature = "template-subcmd")]
use crate::message::template::command::TemplateSubcommand;
#[allow(unused)]
use crate::{
account::command::AccountSubcommand,
completion::command::CompletionGenerateCommand,
config::{self, TomlConfig},
envelope::command::EnvelopeSubcommand,
flag::command::FlagSubcommand,
folder::command::FolderSubcommand,
manual::command::ManualGenerateCommand,
message::{
attachment::command::AttachmentSubcommand, command::MessageSubcommand,
template::command::TemplateSubcommand,
},
output::{ColorFmt, OutputFmt},
printer::Printer,
};
@@ -29,12 +22,8 @@ use crate::{
#[command(name = "himalaya", author, version, about)]
#[command(propagate_version = true, infer_subcommands = true)]
pub struct Cli {
#[cfg(feature = "envelope-list")]
#[command(subcommand)]
pub command: Option<HimalayaCommand>,
#[cfg(not(feature = "envelope-list"))]
#[command(subcommand)]
pub command: HimalayaCommand,
/// Override the default configuration file path
///
@@ -88,38 +77,31 @@ pub struct Cli {
#[derive(Subcommand, Debug)]
pub enum HimalayaCommand {
#[cfg(feature = "account-subcmd")]
#[command(subcommand)]
#[command(alias = "accounts")]
Account(AccountSubcommand),
#[cfg(feature = "folder-subcmd")]
#[command(subcommand)]
#[command(visible_alias = "mailbox", aliases = ["mailboxes", "mboxes", "mbox"])]
#[command(alias = "folders")]
Folder(FolderSubcommand),
#[cfg(feature = "envelope-subcmd")]
#[command(subcommand)]
#[command(alias = "envelopes")]
Envelope(EnvelopeSubcommand),
#[cfg(feature = "flag-subcmd")]
#[command(subcommand)]
#[command(alias = "flags")]
Flag(FlagSubcommand),
#[cfg(feature = "message-subcmd")]
#[command(subcommand)]
#[command(alias = "messages", alias = "msgs", alias = "msg")]
Message(MessageSubcommand),
#[cfg(feature = "attachment-subcmd")]
#[command(subcommand)]
#[command(alias = "attachments")]
Attachment(AttachmentSubcommand),
#[cfg(feature = "template-subcmd")]
#[command(subcommand)]
#[command(alias = "templates", alias = "tpls", alias = "tpl")]
Template(TemplateSubcommand),
@@ -141,37 +123,30 @@ impl HimalayaCommand {
config_path: Option<&PathBuf>,
) -> Result<()> {
match self {
#[cfg(feature = "account-subcmd")]
Self::Account(cmd) => {
let config = TomlConfig::from_some_path_or_default(config_path).await?;
cmd.execute(printer, &config).await
}
#[cfg(feature = "folder-subcmd")]
Self::Folder(cmd) => {
let config = TomlConfig::from_some_path_or_default(config_path).await?;
cmd.execute(printer, &config).await
}
#[cfg(feature = "envelope-subcmd")]
Self::Envelope(cmd) => {
let config = TomlConfig::from_some_path_or_default(config_path).await?;
cmd.execute(printer, &config).await
}
#[cfg(feature = "flag-subcmd")]
Self::Flag(cmd) => {
let config = TomlConfig::from_some_path_or_default(config_path).await?;
cmd.execute(printer, &config).await
}
#[cfg(feature = "message-subcmd")]
Self::Message(cmd) => {
let config = TomlConfig::from_some_path_or_default(config_path).await?;
cmd.execute(printer, &config).await
}
#[cfg(feature = "attachment-subcmd")]
Self::Attachment(cmd) => {
let config = TomlConfig::from_some_path_or_default(config_path).await?;
cmd.execute(printer, &config).await
}
#[cfg(feature = "template-subcmd")]
Self::Template(cmd) => {
let config = TomlConfig::from_some_path_or_default(config_path).await?;
cmd.execute(printer, &config).await