Skip to content

fix(help-md-gen): infer real argument type for Options "Type" column#3858

Merged
jqnatividad merged 1 commit into
masterfrom
fix-help-option-datatype
May 15, 2026
Merged

fix(help-md-gen): infer real argument type for Options "Type" column#3858
jqnatividad merged 1 commit into
masterfrom
fix-help-option-datatype

Conversation

@jqnatividad
Copy link
Copy Markdown
Collaborator

Summary

  • Generated docs/help/*.md Options tables always showed string for any option that takes an argument because qsv_docopt only exposes "has-argument vs not" — never the underlying Rust type.
  • Now 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.
  • New helpers in src/help_markdown_gen.rs: extract_arg_types_from_source / extract_arg_types_from_file / classify_rust_type, threaded through generate_command_markdownparse_options_with_docoptparse_option_line. Falls back to string when no Args struct is found, preserving today's behavior for any odd-shaped command.
  • 49 help files regenerated: ~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).

Before / after (excerpt from docs/help/slice.md)

-| `‑s,‑‑start` | string  | The index of the record to slice from. |
-| `‑e,‑‑end`   | string  | The index of the record to slice to. |
-| `‑l,‑‑len`   | string  | The length of the slice (can be used instead of --end). |
-| `‑i,‑‑index` | string  | Slice a single record (shortcut for -s N -l 1). |
+| `‑s,‑‑start` | integer | The index of the record to slice from. |
+| `‑e,‑‑end`   | integer | The index of the record to slice to. |
+| `‑l,‑‑len`   | integer | The length of the slice (can be used instead of --end). |
+| `‑i,‑‑index` | integer | Slice a single record (shortcut for -s N -l 1). |

Test plan

  • cargo build --locked --bin qsv -F all_features — clean
  • cargo clippy --bin qsv -F all_features -- -D warnings — clean
  • cargo test --bin qsv -F all_features help_markdown_gen24/24 pass (4 new tests for extract_arg_types_from_source: common shapes, nested Option<Box<…>> wrappers, pub visibility, missing-struct fallback)
  • cargo +nightly fmt
  • ./target/debug/qsv --generate-help-md72/72 commands succeed
  • Spot-checked stats.md, slice.md, validate.mdinteger/float flips look right; no flag rows regressed; no obviously-numeric options remain string

🤖 Generated with Claude Code

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>
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_type in src/help_markdown_gen.rs, plus four new unit tests covering common shapes, Option<Box<…>> unwrapping, pub visibility, and missing-struct fallback.
  • Threads the resulting HashMap<String, &'static str> through generate_command_markdownparse_options_with_docoptparse_option_line, replacing the hard-coded "string" for DocoptArgument::One cases.
  • Regenerates 49 help files so ~135 options flip to integer and a handful (e.g. --epsilon, --misrate, --min-score, --sample) to float.

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.

@jqnatividad jqnatividad merged commit 29ba751 into master May 15, 2026
22 checks passed
@jqnatividad jqnatividad deleted the fix-help-option-datatype branch May 15, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants