use super::Configurable;
use crate::app::Cli;
use crate::config_file::Config;
#[derive(Clone, Debug, Copy, PartialEq, Eq, Default)]
pub struct TotalSize(pub bool);
impl Configurable<Self> for TotalSize {
fn from_cli(cli: &Cli) -> Option<Self> {
if cli.total_size {
Some(Self(true))
} else {
None
}
}
fn from_config(config: &Config) -> Option<Self> {
config.total_size.map(Self)
}
}
#[cfg(test)]
mod test {
use clap::Parser;
use super::TotalSize;
use crate::app::Cli;
use crate::config_file::Config;
use crate::flags::Configurable;
#[test]
fn test_from_cli_none() {
let argv = ["lsd"];
let cli = Cli::try_parse_from(argv).unwrap();
assert_eq!(None, TotalSize::from_cli(&cli));
}
#[test]
fn test_from_cli_true() {
let argv = ["lsd", "--total-size"];
let cli = Cli::try_parse_from(argv).unwrap();
assert_eq!(Some(TotalSize(true)), TotalSize::from_cli(&cli));
}
#[test]
fn test_from_config_none() {
assert_eq!(None, TotalSize::from_config(&Config::with_none()));
}
#[test]
fn test_from_config_true() {
let mut c = Config::with_none();
c.total_size = Some(true);
assert_eq!(Some(TotalSize(true)), TotalSize::from_config(&c));
}
#[test]
fn test_from_config_false() {
let mut c = Config::with_none();
c.total_size = Some(false);
assert_eq!(Some(TotalSize(false)), TotalSize::from_config(&c));
}
}