aboutsummaryrefslogtreecommitdiffstats
path: root/src/listing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/listing.rs')
-rw-r--r--src/listing.rs42
1 files changed, 16 insertions, 26 deletions
diff --git a/src/listing.rs b/src/listing.rs
index f0662ef..056c847 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -1,31 +1,34 @@
use actix_web::{fs, HttpRequest, HttpResponse, Result};
use bytesize::ByteSize;
+use clap::{_clap_count_exprs, arg_enum};
use htmlescape::encode_minimal as escape_html_entity;
use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
use std::cmp::Ordering;
use std::fmt::Write as FmtWrite;
use std::io;
use std::path::Path;
-use std::str::FromStr;
-#[derive(Clone, Copy, Debug)]
-/// Available sorting methods
-pub enum SortingMethods {
- /// Natural sorting method
+arg_enum! {
+ #[derive(Clone, Copy, Debug)]
+ /// Available sorting methods
+ ///
+ /// Natural: natural sorting method
/// 1 -> 2 -> 3 -> 11
- Natural,
-
- /// Pure alphabetical sorting method
+ ///
+ /// Alpha: pure alphabetical sorting method
/// 1 -> 11 -> 2 -> 3
- Alpha,
-
- /// Directories are listed first, alphabetical sorting is also applied
+ ///
+ /// DirsFirst: directories are listed first, alphabetical sorting is also applied
/// 1/ -> 2/ -> 3/ -> 11 -> 12
- DirsFirst,
+ pub enum SortingMethods {
+ Natural,
+ Alpha,
+ DirsFirst,
+ }
}
#[derive(PartialEq)]
-/// Possible entry types
+/// Possible entry types
enum EntryType {
/// Entry is a directory
Directory,
@@ -75,19 +78,6 @@ impl Entry {
}
}
-impl FromStr for SortingMethods {
- type Err = ();
-
- fn from_str(s: &str) -> Result<SortingMethods, ()> {
- match s {
- "natural" => Ok(SortingMethods::Natural),
- "alpha" => Ok(SortingMethods::Alpha),
- "dirsfirst" => Ok(SortingMethods::DirsFirst),
- _ => Err(()),
- }
- }
-}
-
pub fn file_handler(req: &HttpRequest<crate::MiniserveConfig>) -> Result<fs::NamedFile> {
let path = &req.state().path;
Ok(fs::NamedFile::open(path)?)