mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 05:27: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"
|
name = "whoami"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
authors = []
|
authors = []
|
||||||
|
description = "Print effective user ID."
|
||||||
build = "../../mkmain.rs"
|
build = "../../mkmain.rs"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
@ -9,14 +10,14 @@ name = "uu_whoami"
|
||||||
path = "whoami.rs"
|
path = "whoami.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
getopts = "0.2.14"
|
clap = "2.31"
|
||||||
winapi = { version = "0.3", features = ["lmcons"] }
|
winapi = { version = "0.3", features = ["lmcons"] }
|
||||||
advapi32-sys = "0.2.0"
|
advapi32-sys = "0.2.0"
|
||||||
|
|
||||||
[dependencies.uucore]
|
[dependencies.uucore]
|
||||||
path = "../uucore"
|
path = "../uucore"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["entries"]
|
features = ["entries", "wide"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "whoami"
|
name = "whoami"
|
||||||
|
|
|
@ -11,45 +11,34 @@
|
||||||
|
|
||||||
/* last synced with: whoami (GNU coreutils) 8.21 */
|
/* last synced with: whoami (GNU coreutils) 8.21 */
|
||||||
|
|
||||||
extern crate getopts;
|
#[macro_use]
|
||||||
|
extern crate clap;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
use getopts::Options;
|
|
||||||
|
|
||||||
mod platform;
|
mod platform;
|
||||||
|
|
||||||
static NAME: &'static str = "whoami";
|
// force a re-build whenever Cargo.toml changes
|
||||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
const _CARGO_TOML: &'static str = include_str!("Cargo.toml");
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
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");
|
if let Err(err) = app.get_matches_from_safe(args) {
|
||||||
opts.optflag("V", "version", "output version information and exit");
|
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..]) {
|
0
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
if matches.opt_present("version") {
|
|
||||||
println!("{} {}", NAME, VERSION);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
exec();
|
|
||||||
|
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec() {
|
pub fn exec() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue