Initial commit
This commit is contained in:
20
src/main.rs
Normal file
20
src/main.rs
Normal file
@ -0,0 +1,20 @@
|
||||
//! A minimal argument parser. Structure your program invocation like a spell.
|
||||
|
||||
|
||||
|
||||
mod project;
|
||||
|
||||
|
||||
|
||||
/// Print the version of the project.
|
||||
fn print_version()
|
||||
{
|
||||
println!("{} v{}", project::get_name(), project::get_version());
|
||||
}
|
||||
|
||||
|
||||
/// The usual starting point of your project.
|
||||
fn main()
|
||||
{
|
||||
print_version();
|
||||
}
|
33
src/project.rs
Normal file
33
src/project.rs
Normal file
@ -0,0 +1,33 @@
|
||||
//! This is where the Projects build information can be retreived from.
|
||||
|
||||
|
||||
|
||||
/// The environment variable defined by Cargo for the name.
|
||||
const NAME: Option<&str> = option_env!("CARGO_PKG_NAME");
|
||||
|
||||
/// The environment variable defined by Cargo for the version.
|
||||
const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
|
||||
|
||||
/// The string to display if a value is not defined during compile time.
|
||||
const NOT_DEFINED: &'static str = "UNDEFINED";
|
||||
|
||||
|
||||
|
||||
/// Returns the name of the program as defined by the CARGO_PKG_NAME. This is
|
||||
/// set at compile time and comes from the Cargo.toml file.
|
||||
///
|
||||
/// If a value is not found, then it will return the not defined value.
|
||||
pub fn get_name() -> &'static str
|
||||
{
|
||||
NAME.unwrap_or(NOT_DEFINED)
|
||||
}
|
||||
|
||||
|
||||
/// Returns the name of the program as defined by the CARGO_PKG_VERSION. This is
|
||||
/// set at compile time and comes from the Cargo.toml file.
|
||||
///
|
||||
/// If a value is not found, then it will return the not defined value.
|
||||
pub fn get_version() -> &'static str
|
||||
{
|
||||
VERSION.unwrap_or(NOT_DEFINED)
|
||||
}
|
Reference in New Issue
Block a user