From 06ce7b01758fcca5bcb789aaaadb6f945efc025d Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 29 May 2022 17:01:30 +0800 Subject: [PATCH] feat: replace --static option to --no-edit --- README.md | 4 +-- src/args.rs | 79 ++++++++++++++++++++++++----------------------------- src/main.rs | 7 +---- 3 files changed, 39 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index f3362ae..3452cd4 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,9 @@ duf duf folder_name ``` -Only serve static files, disable upload and delete operations +Only serve static files, disable editing operations such as update or delete ``` -duf --static +duf --no-edit ``` Finally, run this command to see a list of all available option diff --git a/src/args.rs b/src/args.rs index 183ff9d..12ba5ca 100644 --- a/src/args.rs +++ b/src/args.rs @@ -10,47 +10,43 @@ use crate::BoxResult; const ABOUT: &str = concat!("\n", crate_description!()); // Add extra newline. fn app() -> clap::Command<'static> { - let arg_port = Arg::new("port") - .short('p') - .long("port") - .default_value("5000") - .help("Specify port to listen on") - .value_name("port"); - - let arg_address = Arg::new("address") - .short('b') - .long("bind") - .default_value("127.0.0.1") - .help("Specify bind address") - .value_name("address"); - - let arg_path = Arg::new("path") - .default_value(".") - .allow_invalid_utf8(true) - .help("Path to a directory for serving files"); - - let arg_static = Arg::new("static") - .long("static") - .help("Only serve static files, disable upload and delete operations"); - - let arg_auth = Arg::new("auth") - .short('a') - .long("auth") - .help("Authenticate with user and pass") - .value_name("user:pass"); - - let arg_no_log = Arg::new("no-log") - .long("--no-log") - .help("Don't log any request/response information."); - clap::command!() .about(ABOUT) - .arg(arg_address) - .arg(arg_port) - .arg(arg_path) - .arg(arg_static) - .arg(arg_auth) - .arg(arg_no_log) + .arg( + Arg::new("address") + .short('b') + .long("bind") + .default_value("127.0.0.1") + .help("Specify bind address") + .value_name("address"), + ) + .arg( + Arg::new("port") + .short('p') + .long("port") + .default_value("5000") + .help("Specify port to listen on") + .value_name("port"), + ) + .arg( + Arg::new("path") + .default_value(".") + .allow_invalid_utf8(true) + .help("Path to a directory for serving files"), + ) + .arg( + Arg::new("no-edit") + .short('E') + .long("no-edit") + .help("Disable editing operations such as update or delete"), + ) + .arg( + Arg::new("auth") + .short('a') + .long("auth") + .help("Authenticate with user and pass") + .value_name("user:pass"), + ) } pub fn matches() -> ArgMatches { @@ -64,7 +60,6 @@ pub struct Args { pub path: PathBuf, pub readonly: bool, pub auth: Option, - pub log: bool, } impl Args { @@ -77,9 +72,8 @@ impl Args { let port = matches.value_of_t::("port")?; let path = matches.value_of_os("path").unwrap_or_default(); let path = Args::parse_path(path)?; - let readonly = matches.is_present("static"); + let readonly = matches.is_present("no-edit"); let auth = matches.value_of("auth").map(|v| v.to_owned()); - let log = !matches.is_present("no-log"); Ok(Args { address, @@ -87,7 +81,6 @@ impl Args { path, readonly, auth, - log, }) } diff --git a/src/main.rs b/src/main.rs index 7472ec6..6fbfb36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,13 +28,8 @@ async fn run() -> BoxResult<()> { if std::env::var("RUST_LOG").is_ok() { simple_logger::init()?; } else { - let level = if args.log { - LevelFilter::Info - } else { - LevelFilter::Error - }; simple_logger::SimpleLogger::default() - .with_level(level) + .with_level(LevelFilter::Info) .init()?; } serve(args).await