mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-15 11:27:53 +08:00
refactor: rename command to singular
This commit is contained in:
+10
-13
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+20
-20
@@ -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<Config> {
|
||||
}
|
||||
}
|
||||
|
||||
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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user