mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-03 14:37:45 +00:00
refactor/uucore ~ add util_name!()
; correct implementation of executable!()
This commit is contained in:
parent
f9559fea80
commit
6f58da00dd
1 changed files with 15 additions and 10 deletions
|
@ -5,19 +5,24 @@
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
/// Deduce the name of the binary from the current source code filename.
|
/// Get the utility name.
|
||||||
///
|
#[macro_export]
|
||||||
/// e.g.: `src/uu/cp/src/cp.rs` -> `cp`
|
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_export]
|
||||||
macro_rules! executable(
|
macro_rules! executable(
|
||||||
() => ({
|
() => ({
|
||||||
let module = module_path!();
|
&std::env::args().next().unwrap()
|
||||||
let module = module.split("::").next().unwrap_or(module);
|
|
||||||
if &module[0..3] == "uu_" {
|
|
||||||
&module[3..]
|
|
||||||
} else {
|
|
||||||
module
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue