Fall back to all language types when --type matches nothing - #1819
Open
arimu1 wants to merge 1 commit into
Open
Conversation
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
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.
Closes #1705.
What
When
--type/-Tfilters out every language in the repository,get_loc_by_language_sortednow 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:mainMarkdown (60.0 %),TOML (40.0 %)Tests
tests/repo.rsgetstest_repo_with_only_prose_falls_back_to_all_language_types, backed by a newmake_repo_with_only_prose.shfixture (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:I initially tried to reuse the existing
make_repo_without_code.sh, but its README is created withtouch, 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_selecteddirectly.Notes
LanguageTypeinlanguage.teragainsEnumIter(andCopy) so the fallback can enumerate every variant.--typelong help, and the two checked-in copies of it that would otherwise drift:docs/onefetch.1anddocs/wiki/command-line-options.md.-Texplicitly 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, andcargo clippy --all-targetsare all clean on macOS aarch64.