mirror of
https://github.com/icewind1991/zox
synced 2026-06-03 18:34:07 +02:00
fix arg parsing
This commit is contained in:
parent
80307c9b16
commit
267303e09a
1 changed files with 19 additions and 13 deletions
32
src/main.rs
32
src/main.rs
|
|
@ -1,7 +1,6 @@
|
||||||
use main_error::MainError;
|
use main_error::MainError;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::convert::Infallible;
|
|
||||||
use std::io::{stdout, Write};
|
use std::io::{stdout, Write};
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
|
@ -43,10 +42,11 @@ impl Args {
|
||||||
},
|
},
|
||||||
list: args.contains("-l"),
|
list: args.contains("-l"),
|
||||||
filter: args
|
filter: args
|
||||||
.free_from_fn::<_, Infallible>(|free| {
|
.finish()
|
||||||
Ok(free.split(' ').map(str::to_ascii_lowercase).collect())
|
.into_iter()
|
||||||
})
|
.filter_map(|s| s.into_string().ok())
|
||||||
.unwrap_or_default(),
|
.map(|s| s.to_ascii_lowercase())
|
||||||
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -216,17 +216,23 @@ fn main() -> Result<(), MainError> {
|
||||||
let matches = history.filter(|item| item.matches(&args.filter));
|
let matches = history.filter(|item| item.matches(&args.filter));
|
||||||
|
|
||||||
let mut matches: Vec<History> = matches.collect();
|
let mut matches: Vec<History> = matches.collect();
|
||||||
matches.sort_by(
|
matches.sort_by(|a, b| {
|
||||||
|a, b| match a.get_sort(args.sort, now) - b.get_sort(args.sort, now) {
|
b.get_sort(args.sort, now)
|
||||||
diff if diff < 0.0 => Ordering::Greater,
|
.partial_cmp(&a.get_sort(args.sort, now))
|
||||||
diff if diff > 0.0 => Ordering::Less,
|
.unwrap_or(Ordering::Equal)
|
||||||
_ => Ordering::Equal,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if args.list {
|
if args.list {
|
||||||
|
let out = stdout();
|
||||||
|
let mut out = out.lock();
|
||||||
for item in matches {
|
for item in matches {
|
||||||
println!("{:<11}{}", item.get_sort(args.sort, now), item.path);
|
writeln!(
|
||||||
|
&mut out,
|
||||||
|
"{:<11}{}",
|
||||||
|
item.get_sort(args.sort, now),
|
||||||
|
item.path
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let Some(first) = matches.first() {
|
if let Some(first) = matches.first() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue