feat: replace --static option to --no-edit
This commit is contained in:
parent
4841ebb76d
commit
06ce7b0175
3 changed files with 39 additions and 51 deletions
|
@ -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
|
||||
|
|
79
src/args.rs
79
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<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,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue