move clap into utils
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
0734b52a8a
commit
3140f101c1
3 changed files with 5 additions and 2 deletions
33
src/utils/clap.rs
Normal file
33
src/utils/clap.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
//! Integration with `clap`
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
/// 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.
|
||||
#[allow(clippy::doc_markdown)]
|
||||
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(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Commandline arguments
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(version = version(), about, long_about = None)]
|
||||
pub(crate) struct Args {
|
||||
#[arg(short, long)]
|
||||
/// Optional argument to the path of a conduwuit config TOML file
|
||||
pub(crate) config: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// Parse commandline arguments into structured data
|
||||
#[must_use]
|
||||
pub(crate) fn parse() -> Args { Args::parse() }
|
|
@ -1,3 +1,4 @@
|
|||
pub(crate) mod clap;
|
||||
pub(crate) mod debug;
|
||||
pub(crate) mod error;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue