diff --git a/CHANGELOG.md b/CHANGELOG.md index bc27b11..fd86cff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed default command: running `himalaya` without argument will list envelopes, as it used to be in previous versions. - Fixed bug when listing envelopes with `backend = "imap"`, `sync.enable = true` and `envelope.watch.backend = "imap"` led to unwanted IMAP connection creation (which slowed down the listing). ## [1.0.0-beta] - 2024-01-01 diff --git a/src/cli.rs b/src/cli.rs index 0cf2858..407243e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -23,7 +23,7 @@ use crate::{ #[command(propagate_version = true, infer_subcommands = true)] pub struct Cli { #[command(subcommand)] - pub command: HimalayaCommand, + pub command: Option, /// Override the default configuration file path /// diff --git a/src/email/envelope/command/list.rs b/src/email/envelope/command/list.rs index 68d19da..4f2823b 100644 --- a/src/email/envelope/command/list.rs +++ b/src/email/envelope/command/list.rs @@ -50,6 +50,19 @@ pub struct ListEnvelopesCommand { pub account: AccountNameFlag, } +impl Default for ListEnvelopesCommand { + fn default() -> Self { + Self { + folder: Default::default(), + page: 1, + page_size: Default::default(), + table: Default::default(), + cache: Default::default(), + account: Default::default(), + } + } +} + impl ListEnvelopesCommand { pub async fn execute(self, printer: &mut impl Printer, config: &TomlConfig) -> Result<()> { info!("executing list envelopes command"); diff --git a/src/folder/arg/name.rs b/src/folder/arg/name.rs index c978f57..1e2257e 100644 --- a/src/folder/arg/name.rs +++ b/src/folder/arg/name.rs @@ -18,6 +18,14 @@ pub struct FolderNameOptionalArg { pub name: String, } +impl Default for FolderNameOptionalArg { + fn default() -> Self { + Self { + name: INBOX.to_owned(), + } + } +} + /// The required folder name argument parser. #[derive(Debug, Parser)] pub struct FolderNameArg { diff --git a/src/main.rs b/src/main.rs index bd8172c..328c144 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,8 @@ use anyhow::Result; use clap::Parser; use env_logger::{Builder as LoggerBuilder, Env, DEFAULT_FILTER_ENV}; use himalaya::{ - cli::Cli, config::TomlConfig, message::command::mailto::MessageMailtoCommand, - printer::StdoutPrinter, + cli::Cli, config::TomlConfig, envelope::command::list::ListEnvelopesCommand, + message::command::mailto::MessageMailtoCommand, printer::StdoutPrinter, }; use log::{debug, warn}; use std::env; @@ -35,7 +35,13 @@ async fn main() -> Result<()> { let cli = Cli::parse(); let mut printer = StdoutPrinter::new(cli.output, cli.color); - cli.command - .execute(&mut printer, cli.config_path.as_ref()) - .await + match cli.command { + Some(cmd) => cmd.execute(&mut printer, cli.config_path.as_ref()).await, + None => { + let config = TomlConfig::from_some_path_or_default(cli.config_path.as_ref()).await?; + ListEnvelopesCommand::default() + .execute(&mut printer, &config) + .await + } + } } diff --git a/src/ui/table/arg/max_width.rs b/src/ui/table/arg/max_width.rs index db394ff..214a7c2 100644 --- a/src/ui/table/arg/max_width.rs +++ b/src/ui/table/arg/max_width.rs @@ -1,7 +1,7 @@ use clap::Parser; /// The table max width argument parser. -#[derive(Debug, Parser)] +#[derive(Debug, Default, Parser)] pub struct TableMaxWidthFlag { /// The maximum width the table should not exceed. ///