mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 10:18:11 +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
|
||||
// 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()
|
||||
})
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue