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, /// Display name of the root folder in the UI. Defaults to the folder's /// own name, which in a container is the mount point (e.g. "data"). #[arg(long, env = "FILEBROWSER_ROOT_NAME")] pub root_name: Option, /// 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, /// Folder for the thumbnail cache. Without it thumbnails are off and /// the grid shows icons only. Entries not used for a day are swept. #[arg(long, env = "FILEBROWSER_CACHE")] pub cache: Option, /// Public base URL of this server, e.g. `https://files.example.com`. /// Share and WebDAV links in the UI are built from it, and an `https` /// scheme is what tells the server it sits behind a TLS-terminating /// proxy. Without it links use whatever address the browser is connected /// to, and the server assumes plain HTTP. #[arg(long, env = "FILEBROWSER_PUBLIC_URL")] pub public_url: Option, } #[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_eq!(c.cache, None); } #[test] fn flags_override_defaults() { let c = Cli::try_parse_from([ "filebrowser-ng", "--root", "/r", "--db", "/d", "--port", "9000", "--bind", "0.0.0.0", ]) .unwrap(); assert_eq!(c.port, 9000); assert_eq!(c.bind, "0.0.0.0"); } #[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()); } }