diff options
author | elandsborough <elliott.landsborough@gmail.com> | 2024-01-10 19:53:36 +0000 |
---|---|---|
committer | ElliottLandsborough <elliott.landsborough@gmail.com> | 2024-01-13 03:28:24 +0000 |
commit | e5e3ad2fed80bea3f2c9c90f87a405bca077691e (patch) | |
tree | 80c37e10ad52880d35efb55fbead0f17afa83323 /src/config.rs | |
parent | Skip newline test case on Windows (diff) | |
download | miniserve-e5e3ad2fed80bea3f2c9c90f87a405bca077691e.tar.gz miniserve-e5e3ad2fed80bea3f2c9c90f87a405bca077691e.zip |
Set default sorting order and method with arguments
Diffstat (limited to '')
-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, |