diff options
Diffstat (limited to '')
-rw-r--r-- | src/args.rs | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/src/args.rs b/src/args.rs index c14f954..36e2cf2 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,15 +1,15 @@ use std::net::IpAddr; use std::path::PathBuf; -use clap::{Parser, ValueHint}; +use clap::{Parser, ValueEnum, ValueHint}; use clap_complete::Shell; use http::header::{HeaderMap, HeaderName, HeaderValue}; use crate::auth; use crate::errors::ContextualError; -use crate::renderer; +use crate::renderer::ThemeSlug; -#[derive(clap::ArgEnum, Clone)] +#[derive(ValueEnum, Clone)] pub enum MediaType { Image, Audio, @@ -24,14 +24,14 @@ pub struct CliArgs { pub verbose: bool, /// Which path to serve - #[clap(name = "PATH", parse(from_os_str), value_hint = ValueHint::AnyPath)] + #[clap(name = "PATH", value_hint = ValueHint::AnyPath)] pub path: Option<PathBuf>, /// The name of a directory index file to serve, like "index.html" /// /// Normally, when miniserve serves a directory, it creates a listing for that directory. /// However, if a directory contains this file, miniserve will serve that file instead. - #[clap(long, parse(from_os_str), name = "index_file", value_hint = ValueHint::FilePath)] + #[clap(long, name = "index_file", value_hint = ValueHint::FilePath)] pub index: Option<PathBuf>, /// Activate SPA (Single Page Application) mode @@ -50,9 +50,8 @@ pub struct CliArgs { #[clap( short = 'i', long = "interfaces", - parse(try_from_str = parse_interface), - multiple_occurrences(true), - number_of_values = 1, + value_parser(parse_interface), + num_args(1..), )] pub interfaces: Vec<IpAddr>, @@ -62,9 +61,8 @@ pub struct CliArgs { #[clap( short = 'a', long = "auth", - parse(try_from_str = parse_auth), - multiple_occurrences(true), - number_of_values = 1, + value_parser(parse_auth), + num_args(1..) )] pub auth: Vec<auth::RequiredAuth>, @@ -73,7 +71,7 @@ pub struct CliArgs { pub route_prefix: Option<String>, /// Generate a random 6-hexdigit route - #[clap(long = "random-route", conflicts_with("route-prefix"))] + #[clap(long = "random-route", conflicts_with("route_prefix"))] pub random_route: bool, /// Hide symlinks in listing and prevent them from being followed @@ -89,48 +87,41 @@ pub struct CliArgs { short = 'c', long = "color-scheme", default_value = "squirrel", - possible_values = &*renderer::THEME_SLUGS, - ignore_case = true, + ignore_case = true )] - pub color_scheme: String, + pub color_scheme: ThemeSlug, /// Default color scheme #[clap( short = 'd', long = "color-scheme-dark", default_value = "archlinux", - possible_values = &*renderer::THEME_SLUGS, - ignore_case = true, + ignore_case = true )] - pub color_scheme_dark: String, + pub color_scheme_dark: ThemeSlug, /// Enable QR code display #[clap(short = 'q', long = "qrcode")] pub qrcode: bool, /// Enable file uploading (and optionally specify for which directory) - #[clap(short = 'u', long = "upload-files", value_hint = ValueHint::FilePath, min_values = 0)] + #[clap(short = 'u', long = "upload-files", value_hint = ValueHint::FilePath, num_args(0..=1), value_delimiter(','))] pub allowed_upload_dir: Option<Vec<PathBuf>>, /// Enable creating directories - #[clap(short = 'U', long = "mkdir", requires = "allowed-upload-dir")] + #[clap(short = 'U', long = "mkdir", requires = "allowed_upload_dir")] pub mkdir_enabled: bool, /// Specify uploadable media types - #[clap( - arg_enum, - short = 'm', - long = "media-type", - requires = "allowed-upload-dir" - )] + #[clap(short = 'm', long = "media-type", requires = "allowed_upload_dir")] pub media_type: Option<Vec<MediaType>>, /// Directly specify the uploadable media type expression #[clap( short = 'M', long = "raw-media-type", - requires = "allowed-upload-dir", - conflicts_with = "media-type" + requires = "allowed_upload_dir", + conflicts_with = "media_type" )] pub media_type_raw: Option<String>, @@ -164,8 +155,8 @@ pub struct CliArgs { /// Set custom header for responses #[clap( long = "header", - parse(try_from_str = parse_header), - multiple_occurrences(true), + value_parser(parse_header), + num_args(1..), number_of_values = 1 )] pub header: Vec<HeaderMap>, @@ -187,7 +178,7 @@ pub struct CliArgs { pub show_wget_footer: bool, /// Generate completion file for a shell - #[clap(long = "print-completions", value_name = "shell", arg_enum)] + #[clap(long = "print-completions", value_name = "shell")] pub print_completions: Option<Shell>, /// Generate man page @@ -196,12 +187,12 @@ pub struct CliArgs { /// TLS certificate to use #[cfg(feature = "tls")] - #[clap(long = "tls-cert", requires = "tls-key", value_hint = ValueHint::FilePath)] + #[clap(long = "tls-cert", requires = "tls_key", value_hint = ValueHint::FilePath)] pub tls_cert: Option<PathBuf>, /// TLS private key to use #[cfg(feature = "tls")] - #[clap(long = "tls-key", requires = "tls-cert", value_hint = ValueHint::FilePath)] + #[clap(long = "tls-key", requires = "tls_cert", value_hint = ValueHint::FilePath)] pub tls_key: Option<PathBuf>, /// Enable README.md rendering in directories |