From 3a1a981b8cc81ca849abaa5234399e565b7f7380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Mon, 1 Jun 2026 14:12:34 +0200 Subject: [PATCH] refactor: rename command to singular --- config.sample.toml | 23 ++++++++++------------- default.nix | 2 +- src/cli.rs | 40 ++++++++++++++++++++-------------------- src/main.rs | 8 ++++---- 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/config.sample.toml b/config.sample.toml index 989a7ee7..bc814053 100644 --- a/config.sample.toml +++ b/config.sample.toml @@ -115,11 +115,10 @@ # shared commands fall back to this id when `-m/--mailbox` is not passed. # # Account-level entries override same-named global entries. -#[mailbox.alias] -#inbox = "INBOX" -#sent = "[Gmail]/Sent Mail" -#drafts = "[Gmail]/Drafts" -#trash = "[Gmail]/Trash" +#mailbox.alias.inbox = "INBOX" +#mailbox.alias.sent = "[Gmail]/Sent Mail" +#mailbox.alias.drafts = "[Gmail]/Drafts" +#mailbox.alias.trash = "[Gmail]/Trash" # -------------------------------------------------------------------------------- # User-defined composers and readers @@ -136,18 +135,16 @@ # `default = true` when no name is passed. # # Example using https://github.com/pimalaya/mml: -#[message.composer.mml] -#compose = "mml compose" -#reply = "mml reply" -#forward = "mml forward" -#default = true +#message.composer.mml.compose = ["mml", "compose"] +#message.composer.mml.reply = ["mml", "reply"] +#message.composer.mml.forward = ["mml", "forward"] +#message.composer.mml.default = true # Readers consume a MIME message on stdin and emit human-readable bytes on # stdout. They are invoked by `messages read-with`. # -#[message.reader.mml] -#command = "mml read" -#default = true +#message.reader.mml.command = ["mml", "read"] +#message.reader.mml.default = true # -------------------------------------------------------------------------------- # Account config diff --git a/default.nix b/default.nix index 19a6f730..4cd41f96 100644 --- a/default.nix +++ b/default.nix @@ -39,7 +39,7 @@ pimalaya.mkDefault ( + '' mkdir -p $out/share/{applications,completions,man} cp assets/himalaya.desktop "$out"/share/applications/ - ${emulator} "$out"/bin/himalaya${exe} man "$out"/share/man + ${emulator} "$out"/bin/himalaya${exe} manual "$out"/share/man ${emulator} "$out"/bin/himalaya${exe} completion bash > "$out"/share/completions/himalaya.bash ${emulator} "$out"/bin/himalaya${exe} completion elvish > "$out"/share/completions/himalaya.elvish ${emulator} "$out"/bin/himalaya${exe} completion fish > "$out"/share/completions/himalaya.fish diff --git a/src/cli.rs b/src/cli.rs index b3eab3c4..265d391b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -56,9 +56,9 @@ use crate::{ #[command(author, version, about)] #[command(long_version = long_version!())] #[command(propagate_version = true, infer_subcommands = true)] -pub struct HimalayaCli { +pub struct Cli { #[command(subcommand)] - pub command: HimalayaCommand, + pub cmd: Command, /// Override the default configuration file path. /// @@ -96,19 +96,19 @@ pub struct HimalayaCli { } #[derive(Debug, Subcommand)] -pub enum HimalayaCommand { +pub enum Command { // --- Shared API // - #[command(subcommand, visible_alias = "mbox", alias = "mboxes")] - Mailboxes(MailboxCommand), + #[command(subcommand, visible_alias = "mbox")] + Mailbox(MailboxCommand), #[command(subcommand)] - Envelopes(EnvelopeCommand), + Envelope(EnvelopeCommand), #[command(subcommand)] - Flags(FlagCommand), - #[command(subcommand, visible_alias = "msg", alias = "msgs")] - Messages(MessageCommand), + Flag(FlagCommand), + #[command(subcommand, visible_alias = "msg")] + Message(MessageCommand), #[command(subcommand)] - Attachments(AttachmentCommand), + Attachment(AttachmentCommand), // --- Protocol-specific APIs // @@ -132,8 +132,8 @@ pub enum HimalayaCommand { // #[command(subcommand)] Account(AccountCommand), - Completions(CompletionCommand), - Manuals(ManualCommand), + Completion(CompletionCommand), + Manual(ManualCommand), } /// Loads `Config` from the merged `config_paths` or, when no file @@ -147,7 +147,7 @@ pub fn load_or_wizard(config_paths: &[PathBuf]) -> Result { } } -impl HimalayaCommand { +impl Command { pub fn execute( self, printer: &mut impl Printer, @@ -168,27 +168,27 @@ impl HimalayaCommand { match self { // --- Shared API // - Self::Mailboxes(cmd) => { + Self::Mailbox(cmd) => { let (config, account_config) = configs()?; let client = EmailClient::new(config, account_config, backend)?; cmd.execute(printer, client) } - Self::Envelopes(cmd) => { + Self::Envelope(cmd) => { let (config, account_config) = configs()?; let client = EmailClient::new(config, account_config, backend)?; cmd.execute(printer, client) } - Self::Flags(cmd) => { + Self::Flag(cmd) => { let (config, account_config) = configs()?; let client = EmailClient::new(config, account_config, backend)?; cmd.execute(printer, client) } - Self::Messages(cmd) => { + Self::Message(cmd) => { let (config, account_config) = configs()?; let client = EmailClient::new(config, account_config, backend)?; cmd.execute(printer, client) } - Self::Attachments(cmd) => { + Self::Attachment(cmd) => { let (config, account_config) = configs()?; let client = EmailClient::new(config, account_config, backend)?; cmd.execute(printer, client) @@ -225,8 +225,8 @@ impl HimalayaCommand { // --- Meta // Self::Account(cmd) => cmd.execute(printer, config_paths, account_name, backend), - Self::Completions(cmd) => cmd.execute(printer, HimalayaCli::command()), - Self::Manuals(cmd) => cmd.execute(printer, HimalayaCli::command()), + Self::Completion(cmd) => cmd.execute(printer, Cli::command()), + Self::Manual(cmd) => cmd.execute(printer, Cli::command()), } } } diff --git a/src/main.rs b/src/main.rs index 986ada60..ce6b2eb9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,19 +36,19 @@ use anyhow::Result; use clap::Parser; use pimalaya_cli::{error::ErrorReport, log::Logger, printer::StdoutPrinter}; -use crate::cli::HimalayaCli; +use crate::cli::Cli; fn main() { - let cli = HimalayaCli::parse(); + let cli = Cli::parse(); let mut printer = StdoutPrinter::new(&cli.json); let result = execute(cli, &mut printer); ErrorReport::eval(&mut printer, result); } -fn execute(cli: HimalayaCli, printer: &mut StdoutPrinter) -> Result<()> { +fn execute(cli: Cli, printer: &mut StdoutPrinter) -> Result<()> { Logger::try_init(&cli.log)?; let config = cli.config_paths.as_ref(); let account = cli.account.name.as_deref(); let backend = cli.backend; - cli.command.execute(printer, config, account, backend) + cli.cmd.execute(printer, config, account, backend) }