add default page size config (#96)

This commit is contained in:
Clément DOUIN
2021-04-17 22:37:59 +02:00
parent 2f4caaca07
commit 3e0d1f704d
10 changed files with 248 additions and 168 deletions
+14
View File
@@ -8,6 +8,8 @@ use crate::output::utils::run_cmd;
error_chain! {}
const DEFAULT_PAGE_SIZE: usize = 10;
// Account
#[derive(Debug, Deserialize)]
@@ -17,6 +19,7 @@ pub struct Account {
pub name: Option<String>,
pub downloads_dir: Option<PathBuf>,
pub signature: Option<String>,
pub default_page_size: Option<usize>,
// Specific
pub default: Option<bool>,
@@ -94,6 +97,7 @@ pub struct Config {
pub downloads_dir: Option<PathBuf>,
pub notify_cmd: Option<String>,
pub signature: Option<String>,
pub default_page_size: Option<usize>,
#[serde(flatten)]
pub accounts: HashMap<String, Account>,
@@ -193,4 +197,14 @@ impl Config {
.or_else(|| self.signature.as_ref())
.map(|sig| sig.to_owned())
}
pub fn default_page_size(&self, account: &Account) -> usize {
account
.default_page_size
.as_ref()
.or_else(|| self.default_page_size.as_ref())
.or(Some(&DEFAULT_PAGE_SIZE))
.unwrap()
.to_owned()
}
}