finger: fix smart defaults for both -s/-l and -H/-o arg pairs
This commit is contained in:
+20
-21
@@ -58,12 +58,20 @@ pub struct Args {
|
|||||||
|
|
||||||
/// When used in conjunction with the -s option, the office location and
|
/// When used in conjunction with the -s option, the office location and
|
||||||
/// office phone information is displayed instead of the name of the remote host.
|
/// office phone information is displayed instead of the name of the remote host.
|
||||||
#[arg(long, short, requires = "short", conflicts_with = "host")]
|
// TODO: this is default true, should be false when host is true
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
short,
|
||||||
|
requires = "short",
|
||||||
|
conflicts_with = "host",
|
||||||
|
default_value = "true",
|
||||||
|
default_value_if("host", ArgPredicate::IsPresent, "false")
|
||||||
|
)]
|
||||||
office: bool,
|
office: bool,
|
||||||
|
|
||||||
/// This option restricts the gecos output to only the users' real name.
|
/// This option restricts the gecos output to only the users' real name.
|
||||||
/// It also has the side-effect of restricting the output of the remote host
|
/// It also has the side-effect of restricting the output of the remote host
|
||||||
/// when used in conjunction with the -h option.
|
/// when used in conjunction with the -H option.
|
||||||
#[arg(long, short, requires = "short")]
|
#[arg(long, short, requires = "short")]
|
||||||
gecos: bool,
|
gecos: bool,
|
||||||
|
|
||||||
@@ -91,15 +99,7 @@ pub struct Args {
|
|||||||
/// Mail status is shown as ``No Mail.'' if there is no mail at all,
|
/// Mail status is shown as ``No Mail.'' if there is no mail at all,
|
||||||
/// ``Mail last read DDD MMM ## HH:MM YYYY (TZ)'' if the person has looked at their mailbox since new mail arriving,
|
/// ``Mail last read DDD MMM ## HH:MM YYYY (TZ)'' if the person has looked at their mailbox since new mail arriving,
|
||||||
/// or ``New mail received ...'', ``Unread since ...'' if they have new mail.
|
/// or ``New mail received ...'', ``Unread since ...'' if they have new mail.
|
||||||
#[arg(
|
#[arg(long, short, conflicts_with = "short")]
|
||||||
long,
|
|
||||||
short,
|
|
||||||
conflicts_with = "short",
|
|
||||||
default_value_ifs([
|
|
||||||
("short", ArgPredicate::IsPresent, "false"),
|
|
||||||
("users", ArgPredicate::IsPresent, "true"),
|
|
||||||
]),
|
|
||||||
)]
|
|
||||||
long: bool,
|
long: bool,
|
||||||
|
|
||||||
/// Prevent the -l option of finger from displaying the contents of
|
/// Prevent the -l option of finger from displaying the contents of
|
||||||
@@ -126,15 +126,19 @@ pub struct Args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn determine_request_info(args: &Args) -> FingerRequestInfo {
|
fn determine_request_info(args: &Args) -> FingerRequestInfo {
|
||||||
if args.long {
|
let is_long = if args.long {
|
||||||
|
true
|
||||||
|
} else if args.short {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
args.users.is_some()
|
||||||
|
};
|
||||||
|
|
||||||
|
if is_long {
|
||||||
FingerRequestInfo::Long {
|
FingerRequestInfo::Long {
|
||||||
prevent_files: args.prevent_files,
|
prevent_files: args.prevent_files,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(
|
|
||||||
args.short,
|
|
||||||
"Either short or long output format must be selected"
|
|
||||||
);
|
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
!args.host || !args.office,
|
!args.host || !args.office,
|
||||||
"Host and office options cannot both be enabled for short output format"
|
"Host and office options cannot both be enabled for short output format"
|
||||||
@@ -155,11 +159,6 @@ fn determine_request_info(args: &Args) -> FingerRequestInfo {
|
|||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
debug_assert_ne!(
|
|
||||||
args.short, args.long,
|
|
||||||
"Short and long output formats cannot both be enabled or both be disabled at the same time"
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(shell) = args.completions {
|
if let Some(shell) = args.completions {
|
||||||
generate(shell, &mut Args::command(), "rwho", &mut std::io::stdout());
|
generate(shell, &mut Args::command(), "rwho", &mut std::io::stdout());
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|||||||
Reference in New Issue
Block a user