//! The `iz` binary: the command line, logging and the process lifetime. //! //! `iz [--config ] [serve]` runs the server; a bare `iz` does the same. `iz export`, `iz restore` and //! `iz fsck` are the operator commands (see `cli`). The configuration file is the `--config` path, then //! `IZ_CONFIG`, then `config/iz.toml`. Exit status 0 is success, 1 a failure, 2 a usage error. // The page handlers nest many view and store futures; the default limit is too small for their types. #![recursion_limit = "256"] mod assets; mod attachments; mod auth; mod backup; mod boot; mod cli; mod directory; mod family; mod health; mod i18n; mod in_store; mod live; mod mail; mod mover; mod oidc; mod pages; mod security; mod serve; mod state; mod sweeper; mod views; use std::path::Path; use std::process::ExitCode; use clap::Parser; use cli::{Cli, Command}; use tracing_subscriber::EnvFilter; /// Logs to stderr. The level comes from `RUST_LOG`, and defaults to `info`. fn init_logging() { let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); tracing_subscriber::fmt() .with_env_filter(filter) .with_writer(std::io::stderr) .init(); } /// Runs the server and maps its outcome to an exit status. async fn serve(config: &Path) -> ExitCode { match boot::serve(config).await { Ok(()) => ExitCode::SUCCESS, Err(error) => { tracing::error!(error = %error, "iz stopped with an error"); ExitCode::FAILURE } } } #[tokio::main] async fn main() -> ExitCode { let cli = match Cli::try_parse() { Ok(cli) => cli, Err(error) => { // Help and version are not failures; a usage error is exit 2. let code = if error.use_stderr() { 2 } else { 0 }; let _ = error.print(); return ExitCode::from(code); } }; init_logging(); let config = cli::config_path(cli.config); match cli.command.unwrap_or(Command::Serve) { Command::Serve => serve(&config).await, Command::Export { out } => cli::export::run(&config, &out).await, Command::Restore { from } => cli::restore::run(&config, &from).await, Command::Fsck { remote } => cli::fsck::run(&config, remote).await, } }