mirror of
https://github.com/YGGverse/nexy.git
synced 2026-03-31 17:25:27 +00:00
implement argument option to append trailing slash to files match pattern(s), update crate version
This commit is contained in:
parent
ff323e58c7
commit
dc44d38761
5 changed files with 106 additions and 80 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "nexy"
|
||||
version = "0.4.1"
|
||||
version = "0.5.0"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
|
|
@ -13,4 +13,5 @@ repository = "https://github.com/YGGverse/nexy"
|
|||
anyhow = "1.0"
|
||||
chrono = "^0.4.20"
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
regex = "1.11"
|
||||
urlencoding = "2.1"
|
||||
|
|
@ -140,12 +140,15 @@ nexy -p /path/to/public_dir
|
|||
--list-file-reverse
|
||||
Sort files in list DESC (ASC by default)
|
||||
|
||||
--list-file-slash <LIST_FILE_SLASH>
|
||||
Append trailing slash to files match regex pattern(s)
|
||||
|
||||
--list-time-format <LIST_TIME_FORMAT>
|
||||
Time format for listing items
|
||||
|
||||
* use escape notation for `%` e.g. `"%%Y-%%m-%%d %%H:%%M:%%S"`
|
||||
|
||||
[default: "%Y/%m/%d"]
|
||||
[default: %Y/%m/%d]
|
||||
|
||||
-r, --read-chunk <READ_CHUNK>
|
||||
Optimize memory usage on reading large files or stream
|
||||
|
|
|
|||
|
|
@ -147,6 +147,10 @@ pub struct Config {
|
|||
#[arg(long, default_value_t = false)]
|
||||
pub list_file_reverse: bool,
|
||||
|
||||
/// Append trailing slash to files match regex pattern(s)
|
||||
#[arg(long)]
|
||||
pub list_file_slash: Vec<String>,
|
||||
|
||||
/// Time format for listing items
|
||||
///
|
||||
/// * use escape notation for `%` e.g. `"%%Y-%%m-%%d %%H:%%M:%%S"`
|
||||
|
|
|
|||
|
|
@ -240,9 +240,17 @@ impl Public {
|
|||
if fc.alt.is_size {
|
||||
a.push(b(file.meta.size()))
|
||||
}
|
||||
if !l.ends_with('/') {
|
||||
for p in &fc.append_slash {
|
||||
if p.is_match(&l) {
|
||||
l.push('/');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if !a.is_empty() {
|
||||
l.push(' ');
|
||||
l.push_str(&a.join(", "));
|
||||
l.push_str(&a.join(", "))
|
||||
}
|
||||
l
|
||||
})
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
//! valid listing configuration from the plain `clap` arguments list.
|
||||
//! This feature is evolving, and it may require refactoring in the future.
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
pub struct Time {
|
||||
pub is_accessed: bool,
|
||||
pub is_created: bool,
|
||||
|
|
@ -35,6 +37,7 @@ pub struct Dir {
|
|||
}
|
||||
pub struct File {
|
||||
pub alt: FileAlt,
|
||||
pub append_slash: Vec<Regex>,
|
||||
pub is_reverse: bool,
|
||||
pub sort: FileSort,
|
||||
}
|
||||
|
|
@ -103,6 +106,13 @@ impl ListConfig {
|
|||
is_size: config.list_file_show_size,
|
||||
},
|
||||
is_reverse: config.list_file_reverse,
|
||||
append_slash: {
|
||||
let mut p = Vec::with_capacity(config.list_file_slash.len());
|
||||
for pattern in &config.list_file_slash {
|
||||
p.push(Regex::new(pattern)?)
|
||||
}
|
||||
p
|
||||
},
|
||||
sort: FileSort {
|
||||
time: Time {
|
||||
is_accessed: config.list_file_sort_by_accessed,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue