rename imap folder into mailbox

This commit is contained in:
Clément DOUIN
2026-03-02 11:45:27 +01:00
parent 9811619629
commit 0ec0159a28
16 changed files with 36 additions and 208 deletions
+5 -110
View File
@@ -1,50 +1,22 @@
use std::path::PathBuf;
use anyhow::Result;
use clap::{Args, CommandFactory, Parser, Subcommand};
use clap::{Parser, Subcommand};
use pimalaya_toolbox::{
config::TomlConfig,
long_version,
terminal::{
clap::{
args::{AccountArg, JsonFlag, LogFlags},
commands::{CompletionCommand, ManualCommand},
parsers::path_parser,
},
printer::Printer,
},
};
use crate::{
// account::command::AccountSubcommand,
account::Account,
config::Config,
folder::command::MailboxCommand, // message::{
// attachment::command::AttachmentSubcommand, command::MessageSubcommand,
// template::command::TemplateSubcommand,
// },
};
/// IMAP CLI (requires `imap` cargo feature).
///
/// This command gives you access to the IMAP CLI API, and allows
/// you to manage IMAP mailboxes: list mailboxes, read messages,
/// add flags etc.
#[derive(Debug, Subcommand)]
#[command(rename_all = "lowercase")]
pub enum ImapCommand {
#[command(subcommand)]
#[command(aliases = ["mboxes", "mbox"])]
Mailboxes(MailboxCommand),
}
impl ImapCommand {
pub fn execute(self, printer: &mut impl Printer, account: Account) -> Result<()> {
match self {
Self::Mailboxes(cmd) => cmd.execute(printer, account),
}
}
}
use crate::config::Config;
#[cfg(feature = "imap")]
use crate::imap::command::ImapCommand;
#[derive(Parser, Debug)]
#[command(name = env!("CARGO_PKG_NAME"))]
@@ -78,6 +50,7 @@ pub struct HimalayaCli {
#[derive(Debug, Subcommand)]
pub enum BackendCommand {
#[cfg(feature = "imap")]
#[command(subcommand)]
Imap(ImapCommand),
}
@@ -98,81 +71,3 @@ impl BackendCommand {
}
}
}
#[derive(Subcommand, Debug)]
pub enum HimalayaCommand {
// #[command(subcommand)]
// #[command(alias = "accounts")]
// Account(AccountSubcommand),
#[command(subcommand)]
#[command(visible_alias = "mailbox", aliases = ["mailboxes", "mboxes", "mbox"])]
#[command(alias = "folders")]
Folder(MailboxCommand),
// #[command(subcommand)]
// #[command(alias = "envelopes")]
// Envelope(EnvelopeSubcommand),
// #[command(subcommand)]
// #[command(alias = "flags")]
// Flag(FlagSubcommand),
// #[command(subcommand)]
// #[command(alias = "messages", alias = "msgs", alias = "msg")]
// Message(MessageSubcommand),
// #[command(subcommand)]
// #[command(alias = "attachments")]
// Attachment(AttachmentSubcommand),
// #[command(subcommand)]
// #[command(alias = "templates", alias = "tpls", alias = "tpl")]
// Template(TemplateSubcommand),
#[command(arg_required_else_help = true, alias = "mans")]
Manuals(ManualCommand),
#[command(arg_required_else_help = true)]
Completions(CompletionCommand),
}
impl HimalayaCommand {
pub fn execute(
self,
printer: &mut impl Printer,
config_paths: &[PathBuf],
account_name: Option<&str>,
) -> Result<()> {
match self {
// Self::Account(cmd) => {
// let config = TomlConfig::from_paths_or_default(config_paths).await?;
// cmd.execute(printer, config, config_paths.first()).await
// }
Self::Folder(cmd) => {
let config = Config::from_paths_or_default(config_paths)?;
let (_, account) = config.get_account(account_name)?;
cmd.execute(printer, account)
}
// Self::Envelope(cmd) => {
// let config = TomlConfig::from_paths_or_default(config_paths).await?;
// cmd.execute(printer, &config).await
// }
// Self::Flag(cmd) => {
// let config = TomlConfig::from_paths_or_default(config_paths).await?;
// cmd.execute(printer, &config).await
// }
// Self::Message(cmd) => {
// let config = TomlConfig::from_paths_or_default(config_paths).await?;
// cmd.execute(printer, &config).await
// }
// Self::Attachment(cmd) => {
// let config = TomlConfig::from_paths_or_default(config_paths).await?;
// cmd.execute(printer, &config).await
// }
// Self::Template(cmd) => {
// let config = TomlConfig::from_paths_or_default(config_paths).await?;
// cmd.execute(printer, &config).await
// }
Self::Manuals(cmd) => cmd.execute(printer, HimalayaCli::command()),
Self::Completions(cmd) => cmd.execute(printer, HimalayaCli::command()),
}
}
}
-32
View File
@@ -1,32 +0,0 @@
use std::io;
use clap::{value_parser, CommandFactory, Parser};
use clap_complete::Shell;
use color_eyre::Result;
use tracing::info;
use crate::cli::Cli;
/// Print completion script for the given shell to stdout.
///
/// This command allows you to generate completion script for a given
/// shell. The script is printed to the standard output. If you want
/// to write it to a file, just use unix redirection.
#[derive(Debug, Parser)]
pub struct CompletionGenerateCommand {
/// Shell for which completion script should be generated for.
#[arg(value_parser = value_parser!(Shell))]
pub shell: Shell,
}
impl CompletionGenerateCommand {
pub async fn execute(self) -> Result<()> {
info!("executing generate completion command");
let mut cmd = Cli::command();
let name = cmd.get_name().to_string();
clap_complete::generate(self.shell, &mut cmd, name, &mut io::stdout());
Ok(())
}
}
-1
View File
@@ -1 +0,0 @@
pub mod command;
+26
View File
@@ -0,0 +1,26 @@
use anyhow::Result;
use clap::Subcommand;
use pimalaya_toolbox::terminal::printer::Printer;
use crate::{account::Account, imap::mailbox::command::MailboxCommand};
/// IMAP CLI (requires `imap` cargo feature).
///
/// This command gives you access to the IMAP CLI API, and allows
/// you to manage IMAP mailboxes: list mailboxes, read messages,
/// add flags etc.
#[derive(Debug, Subcommand)]
#[command(rename_all = "lowercase")]
pub enum ImapCommand {
#[command(subcommand)]
#[command(aliases = ["mboxes", "mbox"])]
Mailboxes(MailboxCommand),
}
impl ImapCommand {
pub fn execute(self, printer: &mut impl Printer, account: Account) -> Result<()> {
match self {
Self::Mailboxes(cmd) => cmd.execute(printer, account),
}
}
}
@@ -1,14 +1,14 @@
// mod add;
// mod delete;
// mod expunge;
mod list;
pub mod list;
// mod purge;
use anyhow::Result;
use clap::Subcommand;
use pimalaya_toolbox::terminal::printer::Printer;
use crate::{account::Account, folder::command::list::ListMailboxesCommand};
use crate::{account::Account, imap::mailbox::command::list::ListMailboxesCommand};
/// Create, list and purge mailboxes.
///
+1
View File
@@ -1 +1,2 @@
pub mod command;
pub mod mailbox;
+2 -1
View File
@@ -1,7 +1,8 @@
pub mod account;
pub mod cli;
pub mod config;
pub mod folder;
#[cfg(feature = "imap")]
pub mod imap;
pub mod sasl;
pub mod stream;
pub mod tls;
-62
View File
@@ -1,62 +0,0 @@
use std::{fs, path::PathBuf};
use clap::{CommandFactory, Parser};
use clap_mangen::Man;
use color_eyre::Result;
use pimalaya_tui::terminal::cli::printer::Printer;
use tracing::info;
use crate::{cli::Cli, dir_parser};
/// Generate manual pages to the given directory.
///
/// This command allows you to generate manual pages (following the
/// man page format) to the given directory. If the directory does not
/// exist, it will be created. Any existing man pages will be
/// overriden.
#[derive(Debug, Parser)]
pub struct ManualGenerateCommand {
/// Directory where man files should be generated in.
#[arg(value_parser = dir_parser)]
pub dir: PathBuf,
}
impl ManualGenerateCommand {
pub async fn execute(self, printer: &mut impl Printer) -> Result<()> {
info!("executing generate manuals command");
let cmd = Cli::command();
let cmd_name = cmd.get_name().to_string();
let subcmds = cmd.get_subcommands().cloned().collect::<Vec<_>>();
let subcmds_len = subcmds.len() + 1;
let mut buffer = Vec::new();
Man::new(cmd).render(&mut buffer)?;
fs::create_dir_all(&self.dir)?;
printer.log(format!("Generating man page for command {cmd_name}\n"))?;
fs::write(self.dir.join(format!("{}.1", cmd_name)), buffer)?;
for subcmd in subcmds {
let subcmd_name = subcmd.get_name().to_string();
let mut buffer = Vec::new();
Man::new(subcmd).render(&mut buffer)?;
printer.log(format!(
"Generating man page for subcommand {subcmd_name}\n"
))?;
fs::write(
self.dir.join(format!("{}-{}.1", cmd_name, subcmd_name)),
buffer,
)?;
}
printer.log(format!(
"{subcmds_len} man page(s) successfully generated in {}!\n",
self.dir.display()
))?;
Ok(())
}
}