mirror of
https://github.com/YGGverse/nexy.git
synced 2026-03-31 17:25:27 +00:00
validate unique arguments count
This commit is contained in:
parent
917b1007ad
commit
9b8485c494
2 changed files with 30 additions and 4 deletions
|
|
@ -31,7 +31,7 @@ impl Storage {
|
||||||
bail!("Symlinks yet not supported!");
|
bail!("Symlinks yet not supported!");
|
||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
list_config: ListConfig::init(config),
|
list_config: ListConfig::init(config)?,
|
||||||
public_dir,
|
public_dir,
|
||||||
read_chunk: config.read_chunk,
|
read_chunk: config.read_chunk,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,34 @@ pub struct ListConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ListConfig {
|
impl ListConfig {
|
||||||
pub fn init(config: &crate::config::Config) -> Self {
|
pub fn init(config: &crate::config::Config) -> anyhow::Result<Self> {
|
||||||
Self {
|
use anyhow::bail;
|
||||||
|
fn is_unique(args: &[bool]) -> bool {
|
||||||
|
let mut c = 0;
|
||||||
|
for a in args {
|
||||||
|
if *a {
|
||||||
|
c += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c <= 1
|
||||||
|
}
|
||||||
|
if !is_unique(&[
|
||||||
|
config.list_dir_sort_accessed,
|
||||||
|
config.list_dir_sort_created,
|
||||||
|
config.list_dir_sort_modified,
|
||||||
|
config.list_dir_sort_count,
|
||||||
|
]) {
|
||||||
|
bail!("Dir sort option should be unique!")
|
||||||
|
}
|
||||||
|
if !is_unique(&[
|
||||||
|
config.list_file_sort_accessed,
|
||||||
|
config.list_file_sort_created,
|
||||||
|
config.list_file_sort_modified,
|
||||||
|
config.list_file_sort_size,
|
||||||
|
]) {
|
||||||
|
bail!("File sort option should be unique!")
|
||||||
|
}
|
||||||
|
Ok(Self {
|
||||||
dir: Dir {
|
dir: Dir {
|
||||||
time: Time {
|
time: Time {
|
||||||
is_accessed: config.list_dir_accessed,
|
is_accessed: config.list_dir_accessed,
|
||||||
|
|
@ -71,6 +97,6 @@ impl ListConfig {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
time_format: config.list_time_format.clone(),
|
time_format: config.list_time_format.clone(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue