]> OzVa Git service - ozva-cloud/commitdiff
feat: replace --static option to --no-edit
authorsigoden <sigoden@gmail.com>
Sun, 29 May 2022 09:01:30 +0000 (17:01 +0800)
committersigoden <sigoden@gmail.com>
Sun, 29 May 2022 09:01:30 +0000 (17:01 +0800)
README.md
src/args.rs
src/main.rs

index f3362ae4a6d0a78736da7ffb11d884c0baa03805..3452cd40f81a7320ce2089e0543d7b8de1c2d18f 100644 (file)
--- 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
index 183ff9db7d5bd80607e46fee93a95f49b575c236..12ba5ca3f701314229676eab954af4089facf0c8 100644 (file)
@@ -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<String>,
-    pub log: bool,
 }
 
 impl Args {
@@ -77,9 +72,8 @@ impl Args {
         let port = matches.value_of_t::<u16>("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,
         })
     }
 
index 7472ec649492a2c3c700aa84ba584557713c36c6..6fbfb36194a1cd91df5c5b6e05ae59271229fa59 100644 (file)
@@ -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