fix(help-md-gen): infer real argument type for Options "Type" column#3858
Merged
Conversation
The generated docs/help/*.md "Type" column hardcoded "string" for any
option that takes an argument because qsv_docopt only exposes
"has-argument vs not" — never the underlying Rust type.
Parse each command's `Args` struct (the docopt deserialization target)
and map flag fields to {flag, integer, float, string} based on the
actual Rust type, unwrapping `Option<…>`/`Box<…>` wrappers and
handling `pub` visibility. The map is threaded through
generate_command_markdown → parse_options_with_docopt →
parse_option_line. Falls back to "string" when no Args struct is
found, preserving today's behavior for any odd-shaped command.
49 help files reflect the new types: ~135 options correctly flip to
"integer" (e.g. --jobs, --round, --cache-threshold,
--mode-cardinality-cap, --start/--end/--len/--index, --batch,
--timeout, --size-limit) and several to "float" (e.g. --epsilon,
--misrate, --min-score, --sample).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the auto-generated docs/help/*.md Options tables so the "Type" column reflects the real Rust type (integer/float/flag/string) of each option, instead of always showing string for any option that takes an argument. The generator now parses each command's Args struct directly from source and threads an arg_type_map through the existing options-parsing pipeline.
Changes:
- Adds
extract_arg_types_from_source/extract_arg_types_from_file/classify_rust_typeinsrc/help_markdown_gen.rs, plus four new unit tests covering common shapes,Option<Box<…>>unwrapping,pubvisibility, and missing-struct fallback. - Threads the resulting
HashMap<String, &'static str>throughgenerate_command_markdown→parse_options_with_docopt→parse_option_line, replacing the hard-coded"string"forDocoptArgument::Onecases. - Regenerates 49 help files so ~135 options flip to
integerand a handful (e.g.--epsilon,--misrate,--min-score,--sample) tofloat.
Reviewed changes
Copilot reviewed 50 out of 50 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/help_markdown_gen.rs | Adds Args-struct source parsing + type classifier, plumbs the resulting map through markdown generation; new tests. |
| docs/help/*.md (49 files) | Regenerated tables: numeric option rows switch from string to integer/float. |
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.
Summary
docs/help/*.mdOptions tables always showedstringfor any option that takes an argument becauseqsv_docoptonly exposes "has-argument vs not" — never the underlying Rust type.Argsstruct (the docopt deserialization target) and map flag fields to{flag, integer, float, string}based on the actual Rust type, unwrappingOption<…>/Box<…>wrappers and handlingpubvisibility.src/help_markdown_gen.rs:extract_arg_types_from_source/extract_arg_types_from_file/classify_rust_type, threaded throughgenerate_command_markdown→parse_options_with_docopt→parse_option_line. Falls back tostringwhen noArgsstruct is found, preserving today's behavior for any odd-shaped command.integer(e.g.--jobs,--round,--cache-threshold,--mode-cardinality-cap,--start/--end/--len/--index,--batch,--timeout,--size-limit) and several tofloat(e.g.--epsilon,--misrate,--min-score,--sample).Before / after (excerpt from
docs/help/slice.md)Test plan
cargo build --locked --bin qsv -F all_features— cleancargo clippy --bin qsv -F all_features -- -D warnings— cleancargo test --bin qsv -F all_features help_markdown_gen— 24/24 pass (4 new tests forextract_arg_types_from_source: common shapes, nestedOption<Box<…>>wrappers,pubvisibility, missing-struct fallback)cargo +nightly fmt./target/debug/qsv --generate-help-md— 72/72 commands succeedstats.md,slice.md,validate.md—integer/floatflips look right; noflagrows regressed; no obviously-numeric options remainstring🤖 Generated with Claude Code