refactor/uucore ~ add util_name!(); correct implementation of executable!()

This commit is contained in:
Michael Debertol 2021-06-30 23:27:10 +02:00
parent f9559fea80
commit 6f58da00dd

View file

@ -5,19 +5,24 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
/// Deduce the name of the binary from the current source code filename.
///
/// e.g.: `src/uu/cp/src/cp.rs` -> `cp`
/// Get the utility name.
#[macro_export]
macro_rules! util_name(
() => ({
let crate_name = env!("CARGO_PKG_NAME");
if crate_name.starts_with("uu_") {
&crate_name[3..]
} else {
&crate_name
}
})
);
/// Get the executable name.
#[macro_export]
macro_rules! executable(
() => ({
let module = module_path!();
let module = module.split("::").next().unwrap_or(module);
if &module[0..3] == "uu_" {
&module[3..]
} else {
module
}
&std::env::args().next().unwrap()
})
);