Skip to content

Fall back to all language types when --type matches nothing - #1819

Open
arimu1 wants to merge 1 commit into
o2sh:mainfrom
arimu1:fix/1705-fallback-all-types
Open

Fall back to all language types when --type matches nothing#1819
arimu1 wants to merge 1 commit into
o2sh:mainfrom
arimu1:fix/1705-fallback-all-types

Conversation

@arimu1

@arimu1 arimu1 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Closes #1705.

What

When --type/-T filters out every language in the repository, get_loc_by_language_sorted now retries the count over all four types instead of returning nothing. That's the "second pass over the repo if the original sum is 0" option from @spenserblack's comment on the issue — I went with it over summing undisplayed languages up front so the common case keeps a single pass.

The retry is guarded twice: it only runs when the first pass found nothing, and it's skipped when the selection already covers every type (all_types_selected), so there's no pointless second walk.

Before / after

On a repo holding only a README and a compose.yaml — the case from the issue:

Languages field
main (nothing, and no ascii-art language)
this branch Markdown (60.0 %), TOML (40.0 %)

Tests

tests/repo.rs gets test_repo_with_only_prose_falls_back_to_all_language_types, backed by a new make_repo_with_only_prose.sh fixture (a README with actual prose, no code).

I checked it's a real regression test rather than one that happens to pass — reverting just the src/ change and rerunning gives:

assertion `left == right` failed
  left: None
 right: Some(Markdown)

I initially tried to reuse the existing make_repo_without_code.sh, but its README is created with touch, so it has zero lines and there's genuinely nothing for the fallback to find — hence the separate fixture.

Two small unit tests cover all_types_selected directly.

Notes

  • LanguageType in language.tera gains EnumIter (and Copy) so the fallback can enumerate every variant.
  • Updated the --type long help, and the two checked-in copies of it that would otherwise drift: docs/onefetch.1 and docs/wiki/command-line-options.md.
  • One behavioural thing worth a second opinion: the fallback fires whenever the filter matches nothing, including when the user passed -T explicitly rather than relying on the default. That's what the issue asks for and it can't be distinguished from the default at the clap level, but if you'd rather it only apply to the default selection, say so and I'll rework it.

cargo test (127 unit + 8 integration), cargo fmt --check, and cargo clippy --all-targets are all clean on macOS aarch64.

When --type/-T filters out every language present in the repository
(e.g. the default 'programming markup' on a repo holding only prose or
data files), onefetch showed no Languages field and no ascii-art
dominant language. Redo the count over every type in that case so the
user still gets output.

The retry only runs when the first pass found nothing and the selection
wasn't already every type, so repos that do match keep their single
pass.

Closes o2sh#1705
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.

Fallback to all types if the selected types aren't present

1 participant