From 76b9c46241c24d379916509f4230495ab1ef9d09 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 9 Jul 2024 07:33:33 +0700 Subject: [PATCH] style: Prefer matching with enum name --- clap_complete/src/shells/fish.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/clap_complete/src/shells/fish.rs b/clap_complete/src/shells/fish.rs index a04465d0dc6..3fdf8b733a4 100644 --- a/clap_complete/src/shells/fish.rs +++ b/clap_complete/src/shells/fish.rs @@ -1,6 +1,6 @@ use std::io::Write; -use clap::{builder, Arg, Command, ValueHint}; +use clap::{builder, Arg, ArgAction, Command, ValueHint}; use crate::generator::{utils, Generator}; @@ -16,7 +16,6 @@ impl Generator for Fish { } fn generate(&self, cmd: &Command, buf: &mut dyn Write) { - use clap::ArgAction::{Help, HelpLong, HelpShort, Version}; let bin_name = cmd .get_bin_name() .expect("crate::generate should have set the bin_name"); @@ -26,7 +25,14 @@ impl Generator for Fish { // However, we prefer to fallback to the old behavior when there are no regular flags. `-h` and `-v` is not // a regular flag and it behaves like a command. E.g., `rustup --version toolchain` is not a valid command line. let has_global_flags = cmd.get_arguments().any(|a| { - !a.is_positional() && !matches!(a.get_action(), Help | HelpShort | HelpLong | Version) + !a.is_positional() + && !matches!( + a.get_action(), + ArgAction::Help + | ArgAction::HelpShort + | ArgAction::HelpLong + | ArgAction::Version + ) }); let name = escape_name(bin_name);