Replace structopt and clap 2 with clap 4 - #15
Open
bmesuere wants to merge 1 commit into
Open
Conversation
Clears the last five advisories in the tree: structopt is in maintenance mode (RUSTSEC-2022-0104) and clap 2 drags in ansi_term (RUSTSEC-2021-0139), atty (RUSTSEC-2021-0145, RUSTSEC-2024-0375) and proc-macro-error (RUSTSEC-2024-0370). Together with the fst upgrade this leaves the dependency tree with none. The derive translation is mechanical: StructOpt becomes Args or Parser, #[structopt(...)] becomes #[arg(...)] on fields and #[command(...)] on containers, short flags take a char rather than a string, and parse(from_os_str) is gone since clap 4 handles PathBuf itself. The one part that needed thought is the argument enums. clap 4 dropped Arg::possible_values, and deriving ValueEnum would have changed the accepted strings, which matter here: Rank's CLI list deliberately leaves out "no rank" even though its FromStr accepts it. Keeping PossibleValuesParser over the existing variants() lists preserves both the accepted values and the listing in the help output. Verified against the old binary: identical flags, defaults and accepted values across all 20 subcommands, identical output on filter, prot2tryp, prot2kmer, translate and uniq, and the same accept/reject decisions for every rank, method and strategy, including "no rank" still being refused. Help text is reformatted by clap 4 (Usage: rather than USAGE:, flags and options in one section, values quoted). The website documentation shows this output in places. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This clears the remaining five:
structoptis in maintenance mode (RUSTSEC-2022-0104), andclap2 drags inansi_term(RUSTSEC-2021-0139),atty(RUSTSEC-2021-0145, RUSTSEC-2024-0375) andproc-macro-error(RUSTSEC-2024-0370).The mechanical part
StructOptbecomesArgs(orParserfor the top-level enum),#[structopt(...)]becomes#[arg(...)]on fields and#[command(...)]on containers, short flags take acharinstead of a&str, andparse(from_os_str)disappears because clap 4 handlesPathBufitself.The part that needed thought
clap 4 dropped
Arg::possible_values. DerivingValueEnumwould have been the idiomatic replacement, but it would have changed the accepted strings — and one of them matters:Rank's CLI list deliberately omits"no rank"even though itsFromStraccepts it. KeepingPossibleValuesParserover the existingvariants()lists preserves both the accepted values and the listing in the help output.Verification
I built the old binary from
phase1and compared the two directly, rather than trusting the help text to look similar."", multi-word ranks as"species group",uniq's newline default as"\n". No value changed.filter(defaults,-m/-M,-c),prot2tryp,prot2kmer -k,translate(-f 1,-f 1R -n,-a) anduniq(default,-d,-w).species,"species group",bogus,rmq,lca*— including"no rank"still refused.cargo +nightly fmt --checkclean, and the full pipeline still runs end to end through FragGeneScanRs to tryptic peptides.Worth knowing
Help output is reformatted by clap 4:
Usage:rather thanUSAGE:, flags and options merged into one section, values quoted. The website documentation reproduces this output in places, so those pages will drift.Exit codes for CLI usage errors change from 1 to 2. clap 4 uses exit code 2 for argument errors where clap 2 used 1. Verified:
translate -f 9,filter --bogusandtaxa2agg -m nopeall went from 1 to 2. Runtime errors (missing file, malformed input) still exit 1. Anything scripting against a nonzero exit is fine; anything matching on-eq 1specifically is not.Error wording also changed, e.g.
Found argument '10' which wasn't expectedbecameunexpected argument '10' found.