mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 04:57:45 +00:00
whoami: switch to clap
This commit is contained in:
parent
155fea53b2
commit
7b1554cc2c
2 changed files with 21 additions and 31 deletions
|
@ -2,6 +2,7 @@
|
|||
name = "whoami"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
description = "Print effective user ID."
|
||||
build = "../../mkmain.rs"
|
||||
|
||||
[lib]
|
||||
|
@ -9,14 +10,14 @@ name = "uu_whoami"
|
|||
path = "whoami.rs"
|
||||
|
||||
[dependencies]
|
||||
getopts = "0.2.14"
|
||||
clap = "2.31"
|
||||
winapi = { version = "0.3", features = ["lmcons"] }
|
||||
advapi32-sys = "0.2.0"
|
||||
|
||||
[dependencies.uucore]
|
||||
path = "../uucore"
|
||||
default-features = false
|
||||
features = ["entries"]
|
||||
features = ["entries", "wide"]
|
||||
|
||||
[[bin]]
|
||||
name = "whoami"
|
||||
|
|
|
@ -11,45 +11,34 @@
|
|||
|
||||
/* last synced with: whoami (GNU coreutils) 8.21 */
|
||||
|
||||
extern crate getopts;
|
||||
|
||||
#[macro_use]
|
||||
extern crate clap;
|
||||
#[macro_use]
|
||||
extern crate uucore;
|
||||
|
||||
use getopts::Options;
|
||||
|
||||
mod platform;
|
||||
|
||||
static NAME: &'static str = "whoami";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
// force a re-build whenever Cargo.toml changes
|
||||
const _CARGO_TOML: &'static str = include_str!("Cargo.toml");
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> i32 {
|
||||
let mut opts = Options::new();
|
||||
let app = app_from_crate!();
|
||||
|
||||
opts.optflag("h", "help", "display this help and exit");
|
||||
opts.optflag("V", "version", "output version information and exit");
|
||||
if let Err(err) = app.get_matches_from_safe(args) {
|
||||
if err.kind == clap::ErrorKind::HelpDisplayed
|
||||
|| err.kind == clap::ErrorKind::VersionDisplayed
|
||||
{
|
||||
println!("{}", err);
|
||||
0
|
||||
} else {
|
||||
show_error!("{}", err);
|
||||
1
|
||||
}
|
||||
} else {
|
||||
exec();
|
||||
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(f) => crash!(1, "{}", f),
|
||||
};
|
||||
if matches.opt_present("help") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
println!("");
|
||||
println!("Usage:");
|
||||
println!(" {} [OPTIONS]", NAME);
|
||||
println!("");
|
||||
println!("{}", opts.usage("print effective userid"));
|
||||
return 0;
|
||||
0
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
exec();
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
pub fn exec() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue