Skip to content

feat: add --language / -l flag to chardetect CLI#342

Merged
dan-blanchard merged 7 commits intomainfrom
add-language-to-cli
Mar 14, 2026
Merged

feat: add --language / -l flag to chardetect CLI#342
dan-blanchard merged 7 commits intomainfrom
add-language-to-cli

Conversation

@dan-blanchard
Copy link
Copy Markdown
Member

Summary

  • Adds --language / -l flag to chardetect that includes the detected language (ISO 639-1 code + English name) in output
  • Normal mode: test.txt: utf-8 fr (French) with confidence 0.99
  • Minimal mode: utf-8 fr
  • Uses und (Undetermined) when language is None
  • Moves ISO_TO_LANGUAGE dict from scripts/utils.py to src/chardet/_utils.py for shared access (CLI + scripts)

Test plan

  • 8 new tests covering all output format combinations (normal, minimal, stdin, -l short form, None language)
  • All 8028 existing tests pass with no regressions
  • Ruff lint + format clean

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

dan-blanchard and others added 6 commits March 14, 2026 13:40
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Clarify that _LANGUAGE_NAME_TO_ISO and normalize_language stay in scripts/utils.py
- Add fallback behavior for unknown ISO codes
- Specify argparse help text
- Ensure stdin tests for --minimal + --language

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Surfaces the detected language (ISO 639-1 code + English name) in CLI
output. Uses "und" (Undetermined) when language is None.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (798aedf) to head (bf8d56a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #342   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         1381      1390    +9     
=========================================
+ Hits          1381      1390    +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dan-blanchard dan-blanchard merged commit 2831276 into main Mar 14, 2026
15 checks passed
@dan-blanchard dan-blanchard deleted the add-language-to-cli branch March 14, 2026 23:32
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.

1 participant