use std::path::PathBuf; use clap::Parser; #[derive(Parser, Debug)] #[command( name = "filebrowser-ng", about = "A simple, noob-friendly web file browser", version )] pub struct Cli { /// Root folder the server has access to (required). /// All user folders and shares are relative to this. #[arg(long)] pub root: PathBuf, /// Path to the SQLite database file (required). #[arg(long)] pub db: PathBuf, /// Port to listen on. #[arg(long, default_value_t = 8080)] pub port: u16, /// Address to bind. Use 0.0.0.0 to expose beyond localhost. #[arg(long, default_value = "127.0.0.1")] pub bind: String, /// Assume the server runs behind a TLS-terminating reverse proxy /// (sets the `Secure` attribute on the session cookie). #[arg(long)] pub https: bool, } #[cfg(test)] mod tests { use super::*; use clap::Parser; use std::path::PathBuf; #[test] fn defaults_applied() { let c = Cli::try_parse_from(["filebrowser-ng", "--root", "/r", "--db", "/d"]).unwrap(); assert_eq!(c.root, PathBuf::from("/r")); assert_eq!(c.db, PathBuf::from("/d")); assert_eq!(c.port, 8080); assert_eq!(c.bind, "127.0.0.1"); assert!(!c.https); } #[test] fn flags_override_defaults() { let c = Cli::try_parse_from([ "filebrowser-ng", "--root", "/r", "--db", "/d", "--port", "9000", "--bind", "0.0.0.0", "--https", ]) .unwrap(); assert_eq!(c.port, 9000); assert_eq!(c.bind, "0.0.0.0"); assert!(c.https); } #[test] fn required_args_enforced() { assert!(Cli::try_parse_from(["filebrowser-ng", "--root", "/r"]).is_err()); assert!(Cli::try_parse_from(["filebrowser-ng"]).is_err()); } }