2024-03-12 22:20:03 -04:00
|
|
|
//! Integration with `clap`
|
|
|
|
|
2024-03-13 02:12:14 -04:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2024-03-12 22:20:03 -04:00
|
|
|
use clap::Parser;
|
|
|
|
|
2024-03-22 19:50:57 -04:00
|
|
|
/// Returns the current version of the crate with extra info if supplied
|
|
|
|
///
|
|
|
|
/// Set the environment variable `CONDUIT_VERSION_EXTRA` to any UTF-8 string to
|
|
|
|
/// include it in parenthesis after the SemVer version. A common value are git
|
|
|
|
/// commit hashes.
|
2024-03-22 22:44:31 -04:00
|
|
|
#[allow(clippy::doc_markdown)]
|
2024-03-22 19:50:57 -04:00
|
|
|
fn version() -> String {
|
|
|
|
let cargo_pkg_version = env!("CARGO_PKG_VERSION");
|
|
|
|
|
|
|
|
match option_env!("CONDUIT_VERSION_EXTRA") {
|
|
|
|
Some(x) => format!("{} ({})", cargo_pkg_version, x),
|
|
|
|
None => cargo_pkg_version.to_owned(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-12 22:20:03 -04:00
|
|
|
/// Commandline arguments
|
|
|
|
#[derive(Parser, Debug)]
|
2024-03-22 19:50:57 -04:00
|
|
|
#[clap(version = version(), about, long_about = None)]
|
2024-03-12 22:20:03 -04:00
|
|
|
pub struct Args {
|
|
|
|
#[arg(short, long)]
|
|
|
|
/// Optional argument to the path of a conduwuit config TOML file
|
2024-03-13 02:12:14 -04:00
|
|
|
pub 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-03-12 22:20:03 -04:00
|
|
|
pub fn parse() -> Args { Args::parse() }
|