1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

users: fix long_help text and clippy warning

This commit is contained in:
Jan Scheer 2021-05-29 01:51:00 +02:00
parent bb268d1500
commit 714661774b
2 changed files with 25 additions and 24 deletions

View file

@ -6,19 +6,14 @@
// * For the full copyright and license information, please view the LICENSE
// * file that was distributed with this source code.
/* last synced with: whoami (GNU coreutils) 8.22 */
// Allow dead code here in order to keep all fields, constants here, for consistency.
#![allow(dead_code)]
#[macro_use]
extern crate uucore;
use uucore::utmpx::*;
use clap::{App, Arg};
use uucore::utmpx::{self, Utmpx};
static ABOUT: &str = "Display who is currently logged in, according to FILE.";
static VERSION: &str = env!("CARGO_PKG_VERSION");
static ABOUT: &str = "Print the user names of users currently logged in to the current host";
static ARG_FILES: &str = "files";
@ -26,13 +21,23 @@ fn get_usage() -> String {
format!("{0} [FILE]", executable!())
}
fn get_long_usage() -> String {
format!(
"Output who is currently logged in according to FILE.
If FILE is not specified, use {}. /var/log/wtmp as FILE is common.",
utmpx::DEFAULT_FILE
)
}
pub fn uumain(args: impl uucore::Args) -> i32 {
let usage = get_usage();
let after_help = get_long_usage();
let matches = App::new(executable!())
.version(VERSION)
.about(ABOUT)
.usage(&usage[..])
.after_help(&after_help[..])
.arg(Arg::with_name(ARG_FILES).takes_value(true).max_values(1))
.get_matches_from(args);
@ -44,7 +49,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
let filename = if !files.is_empty() {
files[0].as_ref()
} else {
DEFAULT_FILE
utmpx::DEFAULT_FILE
};
let mut users = Utmpx::iter_all_records()

View file

@ -1,27 +1,23 @@
use crate::common::util::*;
use std::env;
#[test]
fn test_users_noarg() {
new_ucmd!().succeeds();
}
#[test]
#[cfg(any(target_vendor = "apple", target_os = "linux"))]
fn test_users_check_name() {
let result = TestScenario::new(util_name!()).ucmd_keepenv().succeeds();
#[cfg(target_os = "linux")]
let util_name = util_name!();
#[cfg(target_vendor = "apple")]
let util_name = format!("g{}", util_name!());
// Expectation: USER is often set
let key = "USER";
let expected = TestScenario::new(&util_name)
.cmd_keepenv(util_name)
.env("LANGUAGE", "C")
.succeeds()
.stdout_move_str();
match env::var(key) {
Err(e) => println!("Key {} isn't set. Found {}", &key, e),
Ok(username) =>
// Check if "users" contains the name of the user
{
println!("username found {}", &username);
// println!("result.stdout {}", &result.stdout);
if !result.stdout_str().is_empty() {
result.stdout_contains(&username);
}
}
}
new_ucmd!().succeeds().stdout_is(&expected);
}