2024-03-12 22:20:03 -04:00
|
|
|
//! Integration with `clap`
|
|
|
|
|
|
2024-03-13 02:12:14 -04:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
2024-05-20 08:11:05 +00:00
|
|
|
use clap::Parser;
|
2024-07-22 21:16:46 +00:00
|
|
|
use conduit::{Config, Result};
|
2024-03-22 19:50:57 -04:00
|
|
|
|
2024-03-12 22:20:03 -04:00
|
|
|
/// Commandline arguments
|
|
|
|
|
#[derive(Parser, Debug)]
|
2024-06-24 22:06:20 +00:00
|
|
|
#[clap(version = conduit::version(), about, long_about = None)]
|
2024-05-20 08:11:05 +00:00
|
|
|
pub(crate) struct Args {
|
2024-03-12 22:20:03 -04:00
|
|
|
#[arg(short, long)]
|
|
|
|
|
/// Optional argument to the path of a conduwuit config TOML file
|
2024-05-20 08:11:05 +00:00
|
|
|
pub(crate) config: Option<PathBuf>,
|
2024-03-12 22:20:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Parse commandline arguments into structured data
|
2024-03-22 22:44:31 -04:00
|
|
|
#[must_use]
|
2024-07-22 21:16:46 +00:00
|
|
|
pub(super) fn parse() -> Args { Args::parse() }
|
|
|
|
|
|
|
|
|
|
/// Synthesize any command line options with configuration file options.
|
|
|
|
|
pub(crate) fn update(config: &mut Config, args: &Args) -> Result<()> {
|
|
|
|
|
// Indicate the admin console should be spawned automatically if the
|
|
|
|
|
// configuration file hasn't already.
|
|
|
|
|
config.admin_console_automatic |= args.console.unwrap_or(false);
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|