refactor: rename command to singular

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