logname: replace getopts with clap

This commit is contained in:
Idan Attias 2021-05-06 10:52:35 +03:00 committed by Sylvestre Ledru
parent cdd3998a44
commit b24b9d501b
3 changed files with 10 additions and 8 deletions

1
Cargo.lock generated
View file

@ -2068,6 +2068,7 @@ dependencies = [
name = "uu_logname"
version = "0.0.6"
dependencies = [
"clap",
"libc",
"uucore",
"uucore_procs",

View file

@ -16,6 +16,7 @@ path = "src/logname.rs"
[dependencies]
libc = "0.2.42"
clap = "2.33"
uucore = { version=">=0.0.8", package="uucore", path="../../uucore" }
uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" }

View file

@ -13,7 +13,8 @@
extern crate uucore;
use std::ffi::CStr;
use uucore::InvalidEncodingHandling;
use clap::App;
extern "C" {
// POSIX requires using getlogin (or equivalent code)
@ -31,15 +32,14 @@ fn get_userlogin() -> Option<String> {
}
}
static SYNTAX: &str = "";
static SUMMARY: &str = "Print user's login name";
static LONG_HELP: &str = "";
static VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn uumain(args: impl uucore::Args) -> i32 {
app!(SYNTAX, SUMMARY, LONG_HELP).parse(
args.collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(),
);
pub fn uumain(_: impl uucore::Args) -> i32 {
let _ = App::new(executable!())
.version(VERSION)
.about(SUMMARY)
.get_matches();
match get_userlogin() {
Some(userlogin) => println!("{}", userlogin),