diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2019-02-16 20:40:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-16 20:40:19 +0000 |
commit | 9c4e46fa570e6e4498f3d9643cc4627705c53e5a (patch) | |
tree | cf4efcc073766edb3b1bb6529be4c3f0ae8ada83 /src/listing.rs | |
parent | Add rsync to alpine image to allow for syncing files into it (diff) | |
parent | Updated README (diff) | |
download | miniserve-9c4e46fa570e6e4498f3d9643cc4627705c53e5a.tar.gz miniserve-9c4e46fa570e6e4498f3d9643cc4627705c53e5a.zip |
Merge pull request #35 from boastful-squirrel/structopt
Switched to structopt
Diffstat (limited to 'src/listing.rs')
-rw-r--r-- | src/listing.rs | 42 |
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)?) |