//! Integration with `clap` //! //! CLI argument structs are defined in this module. Execution logic for each //! command goes in a submodule. use std::path::PathBuf; use clap::{Parser, Subcommand}; use crate::error; mod serve; /// Command line arguments #[derive(Parser)] #[clap( about, version = crate::version(), )] pub(crate) struct Args { #[clap(subcommand)] pub(crate) command: Command, } #[derive(Subcommand)] pub(crate) enum Command { /// Run the server. Serve(ServeArgs), } /// Wrapper for the `--config` arg. /// /// This exists to centralize the `mut_arg` code that sets the help value based /// on runtime information. #[derive(clap::Args)] #[clap(mut_arg("config", |x| { let help = "Set the path to the configuration file"; x.help(help).long_help(format!( "{}\n\nIf this option is specified, the provided value is used \ as-is.\n\nIf this option is not specified, then the XDG Base \ Directory Specification is followed, searching for the path `{}` \ in the configuration directories. ", help, crate::config::DEFAULT_PATH.display(), )) }))] pub(crate) struct ConfigArg { /// Path to the configuration file #[clap(long, short)] pub(crate) config: Option, } #[derive(clap::Args)] pub(crate) struct ServeArgs { #[clap(flatten)] pub(crate) config: ConfigArg, } impl Args { pub(crate) async fn run(self) -> Result<(), error::Main> { match self.command { Command::Serve(args) => serve::run(args).await?, } Ok(()) } }