mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-05 17:15:12 +00:00
fix folder source not taken into consideration
This commit is contained in:
parent
abb9f4172b
commit
dda90809cb
|
@ -1,13 +1,20 @@
|
|||
//! This module provides arguments related to the user config.
|
||||
|
||||
use clap::Arg;
|
||||
use clap::{Arg, ArgMatches};
|
||||
|
||||
/// Represents the config path argument.
|
||||
/// This argument allows the user to customize the config file path.
|
||||
pub fn path_arg<'a>() -> Arg<'a, 'a> {
|
||||
Arg::with_name("config")
|
||||
const ARG_CONFIG: &str = "config";
|
||||
|
||||
/// Represents the config file path argument. This argument allows the
|
||||
/// user to customize the config file path.
|
||||
pub fn arg<'a>() -> Arg<'a, 'a> {
|
||||
Arg::with_name(ARG_CONFIG)
|
||||
.long("config")
|
||||
.short("c")
|
||||
.help("Forces a specific config path")
|
||||
.help("Forces a specific config file path")
|
||||
.value_name("PATH")
|
||||
}
|
||||
|
||||
/// Represents the config file path argument parser.
|
||||
pub fn parse_arg<'a>(matches: &'a ArgMatches<'a>) -> Option<&'a str> {
|
||||
matches.value_of(ARG_CONFIG)
|
||||
}
|
||||
|
|
|
@ -2,55 +2,52 @@
|
|||
|
||||
use anyhow::Result;
|
||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use log::{debug, info};
|
||||
use log::info;
|
||||
|
||||
use crate::ui::table;
|
||||
|
||||
type MaxTableWidth = Option<usize>;
|
||||
const ARG_ACCOUNT: &str = "account";
|
||||
const CMD_ACCOUNTS: &str = "accounts";
|
||||
|
||||
/// Represents the account commands.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum Cmd {
|
||||
/// Represents the list accounts command.
|
||||
List(MaxTableWidth),
|
||||
List(table::args::MaxTableWidth),
|
||||
}
|
||||
|
||||
/// Represents the account command matcher.
|
||||
pub fn matches(m: &ArgMatches) -> Result<Option<Cmd>> {
|
||||
info!(">> account command matcher");
|
||||
|
||||
let cmd = if let Some(m) = m.subcommand_matches("accounts") {
|
||||
let cmd = if let Some(m) = m.subcommand_matches(CMD_ACCOUNTS) {
|
||||
info!("accounts command matched");
|
||||
|
||||
let max_table_width = m
|
||||
.value_of("max-table-width")
|
||||
.and_then(|width| width.parse::<usize>().ok());
|
||||
debug!("max table width: {:?}", max_table_width);
|
||||
|
||||
let max_table_width = table::args::parse_max_width(m);
|
||||
Some(Cmd::List(max_table_width))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
info!("<< account command matcher");
|
||||
Ok(cmd)
|
||||
}
|
||||
|
||||
/// Represents the account subcommands.
|
||||
pub fn subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||
vec![SubCommand::with_name("accounts")
|
||||
vec![SubCommand::with_name(CMD_ACCOUNTS)
|
||||
.aliases(&["account", "acc", "a"])
|
||||
.about("Lists accounts")
|
||||
.arg(table::args::max_width())]
|
||||
}
|
||||
|
||||
/// Represents the user account name argument.
|
||||
/// This argument allows the user to select a different account than
|
||||
/// the default one.
|
||||
pub fn name_arg<'a>() -> Arg<'a, 'a> {
|
||||
Arg::with_name("account")
|
||||
/// Represents the user account name argument. This argument allows
|
||||
/// the user to select a different account than the default one.
|
||||
pub fn arg<'a>() -> Arg<'a, 'a> {
|
||||
Arg::with_name(ARG_ACCOUNT)
|
||||
.long("account")
|
||||
.short("a")
|
||||
.help("Selects a specific account")
|
||||
.value_name("NAME")
|
||||
.value_name("STRING")
|
||||
}
|
||||
|
||||
/// Represents the user account name argument parser.
|
||||
pub fn parse_arg<'a>(matches: &'a ArgMatches<'a>) -> Option<&'a str> {
|
||||
matches.value_of(ARG_ACCOUNT)
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ pub fn source_arg<'a>() -> Arg<'a, 'a> {
|
|||
.long("folder")
|
||||
.help("Specifies the source folder")
|
||||
.value_name("SOURCE")
|
||||
.default_value("inbox")
|
||||
}
|
||||
|
||||
/// Represents the source folder argument parser.
|
||||
|
|
51
src/main.rs
51
src/main.rs
|
@ -21,8 +21,8 @@ fn create_app<'a>() -> clap::App<'a, 'a> {
|
|||
.about(env!("CARGO_PKG_DESCRIPTION"))
|
||||
.author(env!("CARGO_PKG_AUTHORS"))
|
||||
.global_setting(clap::AppSettings::GlobalVersion)
|
||||
.arg(&config::args::path_arg())
|
||||
.arg(&account::args::name_arg())
|
||||
.arg(&config::args::arg())
|
||||
.arg(&account::args::arg())
|
||||
.args(&output::args::args())
|
||||
.arg(folder::args::source_arg())
|
||||
.subcommands(compl::args::subcmds())
|
||||
|
@ -73,10 +73,9 @@ fn main() -> Result<()> {
|
|||
}
|
||||
|
||||
// Init entities and services.
|
||||
let config = DeserializedConfig::from_opt_path(m.value_of("config"))?;
|
||||
let (account_config, backend_config) = config.to_configs(m.value_of("account"))?;
|
||||
let default_folder = account_config.folder_alias("inbox")?;
|
||||
let folder = m.value_of("folder-source").unwrap_or(&default_folder);
|
||||
let config = DeserializedConfig::from_opt_path(config::args::parse_arg(&m))?;
|
||||
let (account_config, backend_config) = config.to_configs(account::args::parse_arg(&m))?;
|
||||
let folder = account_config.folder_alias(folder::args::parse_source_arg(&m))?;
|
||||
|
||||
// Check IMAP commands.
|
||||
#[cfg(feature = "imap-backend")]
|
||||
|
@ -85,10 +84,10 @@ fn main() -> Result<()> {
|
|||
let mut imap = ImapBackend::new(&account_config, imap_config);
|
||||
match imap::args::matches(&m)? {
|
||||
Some(imap::args::Command::Notify(keepalive)) => {
|
||||
return imap::handlers::notify(keepalive, folder, &mut imap);
|
||||
return imap::handlers::notify(keepalive, &folder, &mut imap);
|
||||
}
|
||||
Some(imap::args::Command::Watch(keepalive)) => {
|
||||
return imap::handlers::watch(keepalive, folder, &mut imap);
|
||||
return imap::handlers::watch(keepalive, &folder, &mut imap);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
@ -124,24 +123,24 @@ fn main() -> Result<()> {
|
|||
Some(email::args::Cmd::Attachments(seq)) => {
|
||||
return email::handlers::attachments(
|
||||
seq,
|
||||
folder,
|
||||
&folder,
|
||||
&account_config,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
);
|
||||
}
|
||||
Some(email::args::Cmd::Copy(seq, mbox_dst)) => {
|
||||
return email::handlers::copy(seq, folder, mbox_dst, &mut printer, backend.as_mut());
|
||||
return email::handlers::copy(seq, &folder, mbox_dst, &mut printer, backend.as_mut());
|
||||
}
|
||||
Some(email::args::Cmd::Delete(seq)) => {
|
||||
return email::handlers::delete(seq, folder, &mut printer, backend.as_mut());
|
||||
return email::handlers::delete(seq, &folder, &mut printer, backend.as_mut());
|
||||
}
|
||||
Some(email::args::Cmd::Forward(seq, attachment_paths, encrypt)) => {
|
||||
return email::handlers::forward(
|
||||
seq,
|
||||
attachment_paths,
|
||||
encrypt,
|
||||
folder,
|
||||
&folder,
|
||||
&account_config,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
|
@ -153,14 +152,14 @@ fn main() -> Result<()> {
|
|||
max_width,
|
||||
page_size,
|
||||
page,
|
||||
folder,
|
||||
&folder,
|
||||
&account_config,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
);
|
||||
}
|
||||
Some(email::args::Cmd::Move(seq, mbox_dst)) => {
|
||||
return email::handlers::move_(seq, folder, mbox_dst, &mut printer, backend.as_mut());
|
||||
return email::handlers::move_(seq, &folder, mbox_dst, &mut printer, backend.as_mut());
|
||||
}
|
||||
Some(email::args::Cmd::Read(seq, text_mime, raw, headers)) => {
|
||||
return email::handlers::read(
|
||||
|
@ -168,7 +167,7 @@ fn main() -> Result<()> {
|
|||
text_mime,
|
||||
raw,
|
||||
headers,
|
||||
folder,
|
||||
&folder,
|
||||
&account_config,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
|
@ -180,7 +179,7 @@ fn main() -> Result<()> {
|
|||
all,
|
||||
attachment_paths,
|
||||
encrypt,
|
||||
folder,
|
||||
&folder,
|
||||
&account_config,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
|
@ -188,7 +187,7 @@ fn main() -> Result<()> {
|
|||
);
|
||||
}
|
||||
Some(email::args::Cmd::Save(raw_msg)) => {
|
||||
return email::handlers::save(folder, raw_msg, &mut printer, backend.as_mut());
|
||||
return email::handlers::save(&folder, raw_msg, &mut printer, backend.as_mut());
|
||||
}
|
||||
Some(email::args::Cmd::Search(query, max_width, page_size, page)) => {
|
||||
return email::handlers::search(
|
||||
|
@ -196,7 +195,7 @@ fn main() -> Result<()> {
|
|||
max_width,
|
||||
page_size,
|
||||
page,
|
||||
folder,
|
||||
&folder,
|
||||
&account_config,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
|
@ -209,7 +208,7 @@ fn main() -> Result<()> {
|
|||
max_width,
|
||||
page_size,
|
||||
page,
|
||||
folder,
|
||||
&folder,
|
||||
&account_config,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
|
@ -240,7 +239,7 @@ fn main() -> Result<()> {
|
|||
return flag::handlers::set(
|
||||
seq_range,
|
||||
flags,
|
||||
folder,
|
||||
&folder,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
);
|
||||
|
@ -249,7 +248,7 @@ fn main() -> Result<()> {
|
|||
return flag::handlers::add(
|
||||
seq_range,
|
||||
flags,
|
||||
folder,
|
||||
&folder,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
);
|
||||
|
@ -258,7 +257,7 @@ fn main() -> Result<()> {
|
|||
return flag::handlers::remove(
|
||||
seq_range,
|
||||
flags,
|
||||
folder,
|
||||
&folder,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
);
|
||||
|
@ -274,7 +273,7 @@ fn main() -> Result<()> {
|
|||
seq,
|
||||
all,
|
||||
tpl,
|
||||
folder,
|
||||
&folder,
|
||||
&account_config,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
|
@ -284,7 +283,7 @@ fn main() -> Result<()> {
|
|||
return tpl::handlers::forward(
|
||||
seq,
|
||||
tpl,
|
||||
folder,
|
||||
&folder,
|
||||
&account_config,
|
||||
&mut printer,
|
||||
backend.as_mut(),
|
||||
|
@ -292,7 +291,7 @@ fn main() -> Result<()> {
|
|||
}
|
||||
Some(tpl::args::Cmd::Save(atts, tpl)) => {
|
||||
return tpl::handlers::save(
|
||||
folder,
|
||||
&folder,
|
||||
&account_config,
|
||||
atts,
|
||||
tpl,
|
||||
|
@ -302,7 +301,7 @@ fn main() -> Result<()> {
|
|||
}
|
||||
Some(tpl::args::Cmd::Send(atts, tpl)) => {
|
||||
return tpl::handlers::send(
|
||||
folder,
|
||||
&folder,
|
||||
&account_config,
|
||||
atts,
|
||||
tpl,
|
||||
|
|
Loading…
Reference in a new issue