#[macro_export]
macro_rules! check_help {
($context:ident) => {
if $context.is_flag_true("help") {
return Ok($crate::ShowHelpRequest($context));
}
};
}
#[macro_export]
macro_rules! check_version {
($context:ident) => {
if $context.is_flag_true("version") {
println!($context.version);
return $crate::done!();
}
};
}
#[macro_export]
macro_rules! check_authors {
($context:ident) => {
if $context.is_flag_true("authors") {
println!($context.authors);
return $crate::done!();
}
};
}
#[macro_export]
macro_rules! crate_license_file {
() => {
env!("CARGO_PKG_LICENSE_NAME")
};
}
#[macro_export]
macro_rules! crate_license {
() => {
env!("CARGO_PKG_LICENSE")
};
}
#[macro_export]
macro_rules! include_license_file {
() => {
include_str!($crate: crate_license_file)
};
}
#[macro_export]
macro_rules! check_license {
($context:ident, $license_func:expr) => {
if $context.is_flag_true("license") {
$license_func;
return done!();
}
};
}
#[macro_export]
macro_rules! check_copyright {
($context:ident) => {
if $context.is_flag_true("copyright") {
println!("{}", $context.copyright);
}
};
}
#[macro_export]
macro_rules! check_preset_flags {
($context:ident) => {
$crate::check_help($context)
$crate::check_authors($context)
$crate::check_version($context)
};
}
#[macro_export]
macro_rules! action_result {
() => {
Result<$crate::ActionResult,$crate::ActionError>
};
}
#[macro_export]
macro_rules! done {
() => {
Ok($crate::ActionResult::Done)
};
}
#[macro_export]
macro_rules! help_req {
($context:expr) => {
Ok($crate::ActionResult::ShowHelpRequest($context))
};
}
#[macro_export]
macro_rules! crate_name {
() => {
env!("CARGO_PKG_NAME")
};
}
#[macro_export]
macro_rules! crate_authors {
() => {
env!("CARGO_PKG_AUTHORS")
};
}
#[macro_export]
macro_rules! crate_version {
() => {
env!("CARGO_PKG_VERSION")
};
}
#[macro_export]
macro_rules! crate_description {
() => {
env!("CARGO_PKG_DESCRIPTION")
};
}
#[macro_export]
macro_rules! root_from_crate {
() => {
Command::with_base(
$crate::crate_name!(),
$crate::crate_authors!(),
$crate::crate_version!(),
$crate::crate_description!(),
None
),
};
($action:expr)=>{
Command::with_base(
$crate::crate_name!(),
$crate::crate_authors!(),
$crate::crate_version!(),
$crate::crate_description!(),
Some($action))
}
}
#[macro_export]
macro_rules! preset_root {
() => {
Command::with_base(
$crate::crate_name!(),
$crate::crate_authors!(),
$crate::crate_version!(),
$crate::crate_description!(),
None
),
};
($action:expr)=>{
Command::with_base(
$crate::crate_name!(),
$crate::crate_authors!(),
$crate::crate_version!(),
$crate::crate_description!(),
Some($action))
}
}