diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2024-01-13 04:36:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-13 04:36:58 +0000 |
commit | c78db05996af04e52d6b16f961a8b247a60c3e88 (patch) | |
tree | 53149c8ee8aa68fa680d23e5011a4c3adfd5b5de /src/config.rs | |
parent | Use tokio::fs instead of std::fs to enable async file operations (fixes #445) (diff) | |
parent | Set default sorting order and method with arguments (diff) | |
download | miniserve-c78db05996af04e52d6b16f961a8b247a60c3e88.tar.gz miniserve-c78db05996af04e52d6b16f961a8b247a60c3e88.zip |
Merge pull request #1308 from ElliottLandsborough/set_sorting_order_with_arguments
Set default sorting order and method with arguments
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs index 1ef9eca..491ac40 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,6 +15,7 @@ use crate::{ args::{parse_auth, CliArgs, MediaType}, auth::RequiredAuth, file_utils::sanitize_path, + listing::{SortingMethod, SortingOrder}, renderer::ThemeSlug, }; @@ -50,6 +51,12 @@ pub struct MiniserveConfig { /// Show hidden files pub show_hidden: bool, + /// Default sorting method + pub default_sorting_method: Option<SortingMethod>, + + /// Default sorting order + pub default_sorting_order: Option<SortingOrder>, + /// Route prefix; Either empty or prefixed with slash pub route_prefix: String, @@ -265,6 +272,24 @@ impl MiniserveConfig { .transpose()? .unwrap_or_default(); + let default_sorting_method: Option<SortingMethod> = match args + .default_sorting_method + .to_owned() + .parse::<SortingMethod>() + { + Ok(value) => Some(value), + Err(_) => None, + }; + + let default_sorting_order: Option<SortingOrder> = match args + .default_sorting_order + .to_owned() + .parse::<SortingOrder>() + { + Ok(value) => Some(value), + Err(_) => None, + }; + Ok(MiniserveConfig { verbose: args.verbose, path: args.path.unwrap_or_else(|| PathBuf::from(".")), @@ -274,6 +299,8 @@ impl MiniserveConfig { path_explicitly_chosen, no_symlinks: args.no_symlinks, show_hidden: args.hidden, + default_sorting_method, + default_sorting_order, route_prefix, favicon_route, css_route, |