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
|
--list-dir-modified
|
||||||
Show directory modified time
|
Show directory modified time
|
||||||
|
|
||||||
|
--list-dir-reverse
|
||||||
|
Sort directories in list DESC (ASC by default)
|
||||||
|
|
||||||
--list-file-size
|
--list-file-size
|
||||||
Show file size in list (as the alternative text for navigation links)
|
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
|
--list-file-modified
|
||||||
Show file modified time
|
Show file modified time
|
||||||
|
|
||||||
|
--list-file-reverse
|
||||||
|
Sort files in list DESC (ASC by default)
|
||||||
|
|
||||||
--list-time-format <LIST_TIME_FORMAT>
|
--list-time-format <LIST_TIME_FORMAT>
|
||||||
Time format for listing items
|
Time format for listing items
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,10 @@ pub struct Config {
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
pub list_dir_modified: bool,
|
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)
|
/// Show file size in list (as the alternative text for navigation links)
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
pub list_file_size: bool,
|
pub list_file_size: bool,
|
||||||
|
|
@ -100,6 +104,10 @@ pub struct Config {
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
pub list_file_modified: bool,
|
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
|
/// Time format for listing items
|
||||||
///
|
///
|
||||||
/// * use escape notation for `%` e.g. `"%%Y-%%m-%%d %%H:%%M:%%S"`
|
/// * use escape notation for `%` e.g. `"%%Y-%%m-%%d %%H:%%M:%%S"`
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,9 @@ impl Storage {
|
||||||
}
|
}
|
||||||
// format dirs list
|
// format dirs list
|
||||||
dirs.sort_by(|a, b| a.name.cmp(&b.name));
|
dirs.sort_by(|a, b| a.name.cmp(&b.name));
|
||||||
|
if self.list_config.dir.is_reverse {
|
||||||
|
dirs.reverse()
|
||||||
|
}
|
||||||
for dir in dirs {
|
for dir in dirs {
|
||||||
r.push({
|
r.push({
|
||||||
let dc = &self.list_config.dir; // just short alias
|
let dc = &self.list_config.dir; // just short alias
|
||||||
|
|
@ -172,6 +175,9 @@ impl Storage {
|
||||||
}
|
}
|
||||||
// format files list
|
// format files list
|
||||||
files.sort_by(|a, b| a.name.cmp(&b.name));
|
files.sort_by(|a, b| a.name.cmp(&b.name));
|
||||||
|
if self.list_config.file.is_reverse {
|
||||||
|
files.reverse()
|
||||||
|
}
|
||||||
for file in files {
|
for file in files {
|
||||||
r.push({
|
r.push({
|
||||||
let fc = &self.list_config.file; // just short alias
|
let fc = &self.list_config.file; // just short alias
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,14 @@ pub struct Time {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Dir {
|
pub struct Dir {
|
||||||
pub time: Time,
|
|
||||||
pub is_count: bool,
|
pub is_count: bool,
|
||||||
|
pub is_reverse: bool,
|
||||||
|
pub time: Time,
|
||||||
}
|
}
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub time: Time,
|
pub is_reverse: bool,
|
||||||
pub is_size: bool,
|
pub is_size: bool,
|
||||||
|
pub time: Time,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ListConfig {
|
pub struct ListConfig {
|
||||||
|
|
@ -29,6 +31,7 @@ impl ListConfig {
|
||||||
is_modified: config.list_dir_modified,
|
is_modified: config.list_dir_modified,
|
||||||
},
|
},
|
||||||
is_count: config.list_dir_count,
|
is_count: config.list_dir_count,
|
||||||
|
is_reverse: config.list_dir_reverse,
|
||||||
},
|
},
|
||||||
file: File {
|
file: File {
|
||||||
time: Time {
|
time: Time {
|
||||||
|
|
@ -37,6 +40,7 @@ impl ListConfig {
|
||||||
is_modified: config.list_file_modified,
|
is_modified: config.list_file_modified,
|
||||||
},
|
},
|
||||||
is_size: config.list_file_size,
|
is_size: config.list_file_size,
|
||||||
|
is_reverse: config.list_file_reverse,
|
||||||
},
|
},
|
||||||
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