fix default command

This commit is contained in:
Clément DOUIN 2024-01-03 22:49:39 +01:00
parent 0352e91e36
commit 70fad9b1fd
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
6 changed files with 35 additions and 7 deletions

View file

@ -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

View file

@ -23,7 +23,7 @@ use crate::{
#[command(propagate_version = true, infer_subcommands = true)]
pub struct Cli {
#[command(subcommand)]
pub command: HimalayaCommand,
pub command: Option<HimalayaCommand>,
/// Override the default configuration file path
///

View file

@ -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");

View file

@ -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 {

View file

@ -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
}
}
}

View file

@ -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.
///