update limit argument data type

This commit is contained in:
yggverse 2025-02-12 20:12:27 +02:00
parent a22fa6449a
commit f3045ad5a4
2 changed files with 4 additions and 4 deletions

View file

@ -8,8 +8,8 @@ pub struct Argument {
pub index: Option<String>,
/// Limit channel items (unlimited by default)
#[arg(short, long, default_value_t = 0)]
pub limit: usize,
#[arg(short, long)]
pub limit: Option<usize>,
/// Show output (`dw` by default)
#[arg(short, long, default_value_t = String::from("dw"))]

View file

@ -43,7 +43,7 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box<dyn Error>> {
.items()
.iter()
{
if argument.limit > 0 && total >= argument.limit {
if argument.limit.is_some_and(|limit| total >= limit) {
break;
}
@ -108,7 +108,7 @@ fn crawl(argument: &Argument, output: &Output) -> Result<(), Box<dyn Error>> {
let mut files: Vec<_> = read_dir(&path)?.filter_map(Result::ok).collect();
files.sort_by_key(|f| f.file_name());
let mut data = Vec::with_capacity(argument.limit);
let mut data = Vec::with_capacity(argument.limit.unwrap_or_default());
let mut index = File::create(&index_filename)?;
let mut total = 0;