]> OzVa Git service - ozva-cloud/commitdiff
chore: update cli help message and reamde
authorsigoden <sigoden@gmail.com>
Mon, 20 Jun 2022 11:40:09 +0000 (19:40 +0800)
committersigoden <sigoden@gmail.com>
Mon, 20 Jun 2022 11:40:09 +0000 (19:40 +0800)
Cargo.lock
Cargo.toml
README.md
src/args.rs
src/auth.rs

index 694f5a70996b7855eee564f72a20ccf9df8ab67a..f60d61940d789d2c5502c35b3f9515628ac650fe 100644 (file)
@@ -423,6 +423,7 @@ dependencies = [
  "bitflags",
  "clap_lex",
  "indexmap",
+ "terminal_size",
  "textwrap",
 ]
 
@@ -2146,6 +2147,16 @@ dependencies = [
  "utf-8",
 ]
 
+[[package]]
+name = "terminal_size"
+version = "0.1.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
+dependencies = [
+ "libc",
+ "winapi 0.3.9",
+]
+
 [[package]]
 name = "termtree"
 version = "0.2.4"
@@ -2157,6 +2168,9 @@ name = "textwrap"
 version = "0.15.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
+dependencies = [
+ "terminal_size",
+]
 
 [[package]]
 name = "thiserror"
index 8de3755212ef77c996efa2d46c504a67dfcf544e..149fc84440632042a8452cde8cbd414e26ab7b96 100644 (file)
@@ -3,7 +3,7 @@ name = "dufs"
 version = "0.19.0"
 edition = "2021"
 authors = ["sigoden <sigoden@gmail.com>"]
-description = "Dufs is a simple file server."
+description = "Dufs is a distinctive utility file server"
 license = "MIT OR Apache-2.0"
 homepage = "https://github.com/sigoden/dufs"
 repository = "https://github.com/sigoden/dufs"
@@ -11,7 +11,7 @@ categories = ["command-line-utilities", "web-programming::http-server"]
 keywords = ["static", "file", "server", "webdav", "cli"]
 
 [dependencies]
-clap = { version = "3", default-features = false, features = ["std"] }
+clap = { version = "3", default-features = false, features = ["std", "wrap_help"] }
 chrono = "0.4"
 tokio = { version = "1", features = ["rt-multi-thread", "macros", "fs", "io-util", "signal"]}
 tokio-rustls = "0.23"
index fd39687c2494c49e11909b1cb40c9b25ca25974e..9d34b586ce398d37832a0fb06622675d6a5daf17 100644 (file)
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@
 [![CI](https://github.com/sigoden/dufs/actions/workflows/ci.yaml/badge.svg)](https://github.com/sigoden/dufs/actions/workflows/ci.yaml)
 [![Crates](https://img.shields.io/crates/v/dufs.svg)](https://crates.io/crates/dufs)
 
-Dufs is a simple file server. Support static serve, search, upload, webdav...
+Dufs is a distinctive utility file server that supports static serving, uploading, searching, accessing control, webdav...
 
 ![demo](https://user-images.githubusercontent.com/4012553/174486522-7af350e6-0195-4f4a-8480-d9464fc6452f.png)
 
@@ -40,29 +40,28 @@ Download from [Github Releases](https://github.com/sigoden/dufs/releases), unzip
 ## CLI
 
 ```
-Dufs is a simple file server. - https://github.com/sigoden/dufs
+Dufs is a distinctive utility file server - https://github.com/sigoden/dufs
 
 USAGE:
     dufs [OPTIONS] [--] [path]
 
 ARGS:
-    <path>    Path to a root directory for serving files [default: .]
+    <path>    Specific path to serve [default: .]
 
 OPTIONS:
     -b, --bind <addr>...         Specify bind address
     -p, --port <port>            Specify port to listen on [default: 5000]
-        --path-prefix <path>     Specify an url path prefix
+        --path-prefix <path>     Specify an path prefix
     -a, --auth <rule>...         Add auth for path
-        --auth-method <value>    Select auth method [default: digest] [possible values: basic,
-                                 digest]
+        --auth-method <value>    Select auth method [default: digest] [possible values: basic, digest]
     -A, --allow-all              Allow all operations
         --allow-upload           Allow upload files/folders
         --allow-delete           Allow delete files/folders
         --allow-symlink          Allow symlink to files/folders outside root directory
         --enable-cors            Enable CORS, sets `Access-Control-Allow-Origin: *`
-        --render-index           Render index.html when requesting a directory
-        --render-try-index       Render index.html if it exists when requesting a directory
-        --render-spa             Render for single-page application
+        --render-index           Serve index.html when requesting a directory, returns 404 if not found index.html
+        --render-try-index       Serve index.html when requesting a directory, returns file listing if not found index.html
+        --render-spa             Serve SPA(Single Page Application)
         --tls-cert <path>        Path to an SSL/TLS certificate to serve with HTTPS
         --tls-key <path>         Path to the SSL/TLS certificate's private key
     -h, --help                   Print help information
@@ -71,30 +70,60 @@ OPTIONS:
 
 ## Examples
 
-Serve current working directory, no upload/delete
+Serve current working directory
 
 ```
 dufs
 ```
 
-Allow upload/delete
+Explicitly allow all operations including upload/delete 
 
 ```
 dufs -A
 ```
 
-Listen on a specific port
+Only allow upload operation
 
 ```
-dufs -p 80
+dufs --allow-upload
+```
+
+Serve a directory
+
+```
+dufs Downloads
+```
+
+Serve a single file
+
+```
+dufs linux-distro.iso
 ```
 
-For a single page application (SPA)
+Serve index.html when requesting a directory
+
+```
+dufs --render-index
+```
+
+Serve SPA(Single Page Application)
 
 ```
 dufs --render-spa
 ```
 
+Require username/password
+
+```
+dufs -a /@admin:123
+```
+
+Listen on a specific port
+
+```
+dufs -p 80
+```
+
 Use https
 
 ```
@@ -126,36 +155,9 @@ Delete a file/folder
 curl -X DELETE http://127.0.0.1:5000/path-to-file
 ```
 
-## Details
-
-<details>
-<summary>
-
-#### 1. Control render logic
-
-</summary>
-
-
-The default render logic is:
-
--  If request for a folder, rendering the directory listing. 
--  If request for a file, rendering the file.
--  If request target does not exist, returns 404.
+## Access Control
 
-The `--render-*` options change the render logic:
-
-- `--render-index`: If request for a folder, rendering index.html in the folder. If the index.html file does not exist, return 404.
-- `--render-try-index`: Like `--render-index`, rendering the directory listing if the index.html file does not exist, other than return 404.
-- `--render-spa`: If request target does not exist, rendering `/index.html`
-
-</details>
-
-<details>
-<summary>
-
-#### 2. Path level access control
-
-</summary>
+Dufs implements path level access control through http authentication.
 
 ```
 dufs -a <path>@<readwrite>[@<readonly>]
@@ -176,14 +178,6 @@ dufs -a /@admin:pass@* -a /ui@designer:pass1 -A
 - Account `admin:pass` can upload/delete/download any files/folders.
 - Account `designer:pass1` can upload/delete/download any files/folders in the `ui` folder.
 
-Curl with digest auth:
-
-```
-curl --digest -u designer:pass1 http://127.0.0.1:5000/ui/path-to-file
-```
-
-</details>
-
 ## License
 
 Copyright (c) 2022 dufs-developers.
index 662d440313a971443ce3c5033ab0b903665c0f26..e43d349801fc5b983c6f968255bcae5d3401177b 100644 (file)
@@ -40,13 +40,13 @@ fn app() -> Command<'static> {
             Arg::new("path")
                 .default_value(".")
                 .allow_invalid_utf8(true)
-                .help("Path to a root directory for serving files"),
+                .help("Specific path to serve"),
         )
         .arg(
             Arg::new("path-prefix")
                 .long("path-prefix")
                 .value_name("path")
-                .help("Specify an url path prefix"),
+                .help("Specify an path prefix"),
         )
         .arg(
             Arg::new("auth")
@@ -94,17 +94,17 @@ fn app() -> Command<'static> {
         .arg(
             Arg::new("render-index")
                 .long("render-index")
-                .help("Render index.html when requesting a directory"),
+                .help("Serve index.html when requesting a directory, returns 404 if not found index.html"),
         )
         .arg(
             Arg::new("render-try-index")
                 .long("render-try-index")
-                .help("Render index.html if it exists when requesting a directory"),
+                .help("Serve index.html when requesting a directory, returns file listing if not found index.html"),
         )
         .arg(
             Arg::new("render-spa")
                 .long("render-spa")
-                .help("Render for single-page application"),
+                .help("Serve SPA(Single Page Application)"),
         )
         .arg(
             Arg::new("tls-cert")
@@ -124,7 +124,7 @@ pub fn matches() -> ArgMatches {
     app().get_matches()
 }
 
-#[derive(Debug, Clone)]
+#[derive(Debug)]
 pub struct Args {
     pub addrs: Vec<IpAddr>,
     pub port: u16,
index c3e695866f3b08776df445eb9863dc03e0a38947..424d48e8d26d2c0646db07f676efecd6d7a1c4b5 100644 (file)
@@ -22,12 +22,12 @@ lazy_static! {
     };
 }
 
-#[derive(Debug, Clone)]
+#[derive(Debug)]
 pub struct AccessControl {
     rules: HashMap<String, PathControl>,
 }
 
-#[derive(Debug, Clone)]
+#[derive(Debug)]
 pub struct PathControl {
     readwrite: Account,
     readonly: Option<Account>,