mirror of
https://github.com/YGGverse/nexy.git
synced 2026-03-31 17:25:27 +00:00
implement list entries order option
This commit is contained in:
parent
3cc53b3dc7
commit
0a22d1388c
4 changed files with 26 additions and 2 deletions
|
|
@ -89,6 +89,9 @@ nexy -p /path/to/public_dir
|
|||
--list-dir-modified
|
||||
Show directory modified time
|
||||
|
||||
--list-dir-reverse
|
||||
Sort directories in list DESC (ASC by default)
|
||||
|
||||
--list-file-size
|
||||
Show file size in list (as the alternative text for navigation links)
|
||||
|
||||
|
|
@ -101,6 +104,9 @@ nexy -p /path/to/public_dir
|
|||
--list-file-modified
|
||||
Show file modified time
|
||||
|
||||
--list-file-reverse
|
||||
Sort files in list DESC (ASC by default)
|
||||
|
||||
--list-time-format <LIST_TIME_FORMAT>
|
||||
Time format for listing items
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,10 @@ pub struct Config {
|
|||
#[arg(long, default_value_t = false)]
|
||||
pub list_dir_modified: bool,
|
||||
|
||||
/// Sort directories in list DESC (ASC by default)
|
||||
#[arg(long, default_value_t = false)]
|
||||
pub list_dir_reverse: bool,
|
||||
|
||||
/// Show file size in list (as the alternative text for navigation links)
|
||||
#[arg(long, default_value_t = false)]
|
||||
pub list_file_size: bool,
|
||||
|
|
@ -100,6 +104,10 @@ pub struct Config {
|
|||
#[arg(long, default_value_t = false)]
|
||||
pub list_file_modified: bool,
|
||||
|
||||
/// Sort files in list DESC (ASC by default)
|
||||
#[arg(long, default_value_t = false)]
|
||||
pub list_file_reverse: bool,
|
||||
|
||||
/// Time format for listing items
|
||||
///
|
||||
/// * use escape notation for `%` e.g. `"%%Y-%%m-%%d %%H:%%M:%%S"`
|
||||
|
|
|
|||
|
|
@ -146,6 +146,9 @@ impl Storage {
|
|||
}
|
||||
// format dirs list
|
||||
dirs.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
if self.list_config.dir.is_reverse {
|
||||
dirs.reverse()
|
||||
}
|
||||
for dir in dirs {
|
||||
r.push({
|
||||
let dc = &self.list_config.dir; // just short alias
|
||||
|
|
@ -172,6 +175,9 @@ impl Storage {
|
|||
}
|
||||
// format files list
|
||||
files.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
if self.list_config.file.is_reverse {
|
||||
files.reverse()
|
||||
}
|
||||
for file in files {
|
||||
r.push({
|
||||
let fc = &self.list_config.file; // just short alias
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ pub struct Time {
|
|||
}
|
||||
|
||||
pub struct Dir {
|
||||
pub time: Time,
|
||||
pub is_count: bool,
|
||||
pub is_reverse: bool,
|
||||
pub time: Time,
|
||||
}
|
||||
pub struct File {
|
||||
pub time: Time,
|
||||
pub is_reverse: bool,
|
||||
pub is_size: bool,
|
||||
pub time: Time,
|
||||
}
|
||||
|
||||
pub struct ListConfig {
|
||||
|
|
@ -29,6 +31,7 @@ impl ListConfig {
|
|||
is_modified: config.list_dir_modified,
|
||||
},
|
||||
is_count: config.list_dir_count,
|
||||
is_reverse: config.list_dir_reverse,
|
||||
},
|
||||
file: File {
|
||||
time: Time {
|
||||
|
|
@ -37,6 +40,7 @@ impl ListConfig {
|
|||
is_modified: config.list_file_modified,
|
||||
},
|
||||
is_size: config.list_file_size,
|
||||
is_reverse: config.list_file_reverse,
|
||||
},
|
||||
time_format: config.list_time_format.clone(),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue