Skip to content

Commit

Permalink
style: Prefer exhaustive match
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Jul 9, 2024
1 parent 0462be6 commit 46131ca
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions clap_complete/src/shells/fish.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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");
Expand All @@ -26,7 +25,13 @@ 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() &&
// NOTE: Use exhaustive match to update this when new actions are added
// (e.g. HelpShort / HelpLong were only added recently).
match a.get_action() {
ArgAction::Set | ArgAction::Append | ArgAction::SetTrue | ArgAction::SetFalse | ArgAction::Count => true,
ArgAction::Help | ArgAction::HelpShort | ArgAction::HelpLong | ArgAction::Version => false,
}
});

let name = escape_name(bin_name);
Expand Down

0 comments on commit 46131ca

Please sign in to comment.