[PR #1856] [MERGED] fix(args): Add backward compatibility for single-dash long options #2621

Closed
opened 2026-01-29 17:23:08 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/CCExtractor/ccextractor/pull/1856
Author: @cfsmp3
Created: 12/20/2025
Status: Merged
Merged: 12/20/2025
Merged by: @cfsmp3

Base: masterHead: fix/issue-1576-legacy-single-dash-options


📝 Commits (2)

  • dd3dab7 fix(args): Add backward compatibility for single-dash long options (#1576)
  • 77624ec style: Run cargo fmt on Rust code

📊 Changes

1 file changed (+117 additions, -0 deletions)

View changed files

📝 src/rust/src/lib.rs (+117 -0)

📄 Description

Summary

  • Fixes issue where scripts using -quiet (single-dash) instead of --quiet (double-dash) would fail silently with exit code 7 and produce zero-length output files
  • Adds normalize_legacy_option() function that pre-processes command-line arguments to convert legacy single-dash long options to double-dash format before passing to clap
  • Maintains full backward compatibility with old scripts while preserving correct behavior for short options like -o

Root Cause

The Rust-based argument parser (clap) only accepts double-dash long options (--quiet), but old versions of ccextractor accepted single-dash (-quiet). When clap received -quiet, it parsed it as five individual short options -q -u -i -e -t. Since -q wasn't defined, it failed with exit code 7.

Users with scripts that redirected stderr (> /dev/null 2>&1) never saw the error message, causing the "intermittent" zero-length output described in the issue.

Changes

src/rust/src/lib.rs:

  • Added normalize_legacy_option() function that converts single-dash long options to double-dash
  • Pre-processes all arguments before passing to clap's parser
  • Added 6 unit tests covering all edge cases

Test Results

Test Case Before Fix After Fix
-quiet Exit code 7, no output Exit code 0, correct output ✓
--quiet Works Works ✓
-stdout Exit code 7 Works ✓
-autoprogram Exit code 7 Works ✓
Short options (-o) Works Works ✓
Numeric options (-1, -12) Works Works ✓

All 292 Rust tests pass (286 existing + 6 new).

Test plan

  • Verify -quiet now works (was failing before)
  • Verify --quiet still works
  • Verify short options like -o still work
  • Verify numeric options like -1, -12 still work
  • Run full Rust test suite
  • CI passes

Fixes #1576

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/CCExtractor/ccextractor/pull/1856 **Author:** [@cfsmp3](https://github.com/cfsmp3) **Created:** 12/20/2025 **Status:** ✅ Merged **Merged:** 12/20/2025 **Merged by:** [@cfsmp3](https://github.com/cfsmp3) **Base:** `master` ← **Head:** `fix/issue-1576-legacy-single-dash-options` --- ### 📝 Commits (2) - [`dd3dab7`](https://github.com/CCExtractor/ccextractor/commit/dd3dab7d52c45da4c9d76b7aada57240bb4358db) fix(args): Add backward compatibility for single-dash long options (#1576) - [`77624ec`](https://github.com/CCExtractor/ccextractor/commit/77624ec678325d751fc43c41410af8b4b8d23ab6) style: Run cargo fmt on Rust code ### 📊 Changes **1 file changed** (+117 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/rust/src/lib.rs` (+117 -0) </details> ### 📄 Description ## Summary - Fixes issue where scripts using `-quiet` (single-dash) instead of `--quiet` (double-dash) would fail silently with exit code 7 and produce zero-length output files - Adds `normalize_legacy_option()` function that pre-processes command-line arguments to convert legacy single-dash long options to double-dash format before passing to clap - Maintains full backward compatibility with old scripts while preserving correct behavior for short options like `-o` ## Root Cause The Rust-based argument parser (clap) only accepts double-dash long options (`--quiet`), but old versions of ccextractor accepted single-dash (`-quiet`). When clap received `-quiet`, it parsed it as five individual short options `-q -u -i -e -t`. Since `-q` wasn't defined, it failed with exit code 7. Users with scripts that redirected stderr (`> /dev/null 2>&1`) never saw the error message, causing the "intermittent" zero-length output described in the issue. ## Changes **src/rust/src/lib.rs:** - Added `normalize_legacy_option()` function that converts single-dash long options to double-dash - Pre-processes all arguments before passing to clap's parser - Added 6 unit tests covering all edge cases ## Test Results | Test Case | Before Fix | After Fix | |-----------|-----------|-----------| | `-quiet` | Exit code 7, no output | Exit code 0, correct output ✓ | | `--quiet` | Works | Works ✓ | | `-stdout` | Exit code 7 | Works ✓ | | `-autoprogram` | Exit code 7 | Works ✓ | | Short options (`-o`) | Works | Works ✓ | | Numeric options (`-1`, `-12`) | Works | Works ✓ | All 292 Rust tests pass (286 existing + 6 new). ## Test plan - [x] Verify `-quiet` now works (was failing before) - [x] Verify `--quiet` still works - [x] Verify short options like `-o` still work - [x] Verify numeric options like `-1`, `-12` still work - [x] Run full Rust test suite - [ ] CI passes Fixes #1576 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 17:23:08 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/ccextractor#2621