Skip to content

fix: case-insensitive arguments. - #42

Open
Skyrion9 wants to merge 2 commits into
rodrigomatta:mainfrom
Skyrion9:case-sensitivity
Open

fix: case-insensitive arguments.#42
Skyrion9 wants to merge 2 commits into
rodrigomatta:mainfrom
Skyrion9:case-sensitivity

Conversation

@Skyrion9

@Skyrion9 Skyrion9 commented Jul 15, 2026

Copy link
Copy Markdown
  • Normalize arguments to lowercase before comparison so that --codec-CPU etc. will still be accepted as valid flags instead of being silenlty ignored.

Summary by CodeRabbit

  • Bug Fixes
    • Command-line options are now recognized regardless of letter casing, including model, output, server, host, port, logging, and help options.
    • Mixed-case flags such as --Log-Level are accepted consistently.
  • Documentation
    • Updated the documented Metal short option from -M to -mt to match the supported flag.

- Normalize arguments to lowercase before comparison so that --codec-CPU etc. will still be accepted as valid flags instead of being silenlty ignored.
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Command-line parsing in src/main.cpp lowercases dash-prefixed arguments before matching them, making supported options case-insensitive while updating the Metal short flag to -mt.

Changes

CLI option parsing

Layer / File(s) Summary
Normalize and dispatch CLI options
src/main.cpp
Dash-prefixed arguments are normalized to lowercase before matching model, tokenizer, generation, codec, logging, server, host, port, and help options; Metal selection and usage text use -mt.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: argument parsing is made case-insensitive.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main.cpp`:
- Around line 158-164: Restrict the lowercase transformation in the
argument-normalization block to dash-prefixed flags longer than two characters,
preserving case for short options such as -M, -H, and -P. Keep the existing
long-option matching flow unchanged and ensure comparisons against uppercase
short flags remain reachable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8c0af40f-6075-497b-940c-5bd4b55fdd7f

📥 Commits

Reviewing files that changed from the base of the PR and between 2c33261 and f140614.

📒 Files selected for processing (1)
  • src/main.cpp

Comment thread src/main.cpp
Comment on lines +158 to +164

// Normalize flag arguments to lowercase for case-insensitive matching
std::string arg_lower = arg;
if (!arg.empty() && arg[0] == '-') {
std::transform(arg_lower.begin(), arg_lower.end(), arg_lower.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Case-insensitive short options create collisions and dead code.

Lowercasing all dash-prefixed arguments introduces critical logic errors for short options that rely on case sensitivity:

  • -M (Metal) is lowercased to -m, colliding with --model at line 166.
  • -H (Host) is lowercased to -h, colliding with --help at line 234.
  • -P (Port) is lowercased to -p, which skips the condition chain entirely.

Additionally, comparisons like arg_lower == "-M" and arg_lower == "-H" become dead code because arg_lower will never contain uppercase letters after the transformation.

To fix this while keeping long options case-insensitive, restrict the lowercase transformation to flags longer than 2 characters. This correctly preserves standard short flags like -M, -H, and -P.

🐛 Proposed fix
-        if (!arg.empty() && arg[0] == '-') {
+        if (arg.length() > 2 && arg[0] == '-') {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Normalize flag arguments to lowercase for case-insensitive matching
std::string arg_lower = arg;
if (!arg.empty() && arg[0] == '-') {
std::transform(arg_lower.begin(), arg_lower.end(), arg_lower.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
}
// Normalize flag arguments to lowercase for case-insensitive matching
std::string arg_lower = arg;
if (arg.length() > 2 && arg[0] == '-') {
std::transform(arg_lower.begin(), arg_lower.end(), arg_lower.begin(),
[](unsigned char c) { return static_cast<char>(std::tolower(c)); });
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main.cpp` around lines 158 - 164, Restrict the lowercase transformation
in the argument-normalization block to dash-prefixed flags longer than two
characters, preserving case for short options such as -M, -H, and -P. Keep the
existing long-option matching flow unchanged and ensure comparisons against
uppercase short flags remain reachable.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main.cpp`:
- Line 76: Fix the Metal CLI contract around the help text in main.cpp and the
argument normalization/dispatch logic: either update README.md to document the
actual -m form, or preserve the documented -M alias by ensuring normalization
does not convert it into the model option and dispatches it as Metal. Apply the
same correction to both Metal help entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c289fcc-7128-4f18-9a91-b18722abae8c

📥 Commits

Reviewing files that changed from the base of the PR and between f140614 and 29c5de3.

📒 Files selected for processing (1)
  • src/main.cpp

Comment thread src/main.cpp
safe_print(" -v, --vulkan <id> Vulkan device index (-1 = CPU)\n");
safe_print(" -c, --cuda <id> CUDA device index (-1 = CPU)\n");
safe_print(" -M, --metal Use Metal backend (macOS only)\n");
safe_print(" -mt, --metal Use Metal backend (macOS only)\n");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Update the documented Metal flag or preserve -M as an alias.

README.md still documents -M, --metal, but normalization converts -M to -m, which dispatches it as the model option instead of selecting Metal. This breaks the existing documented CLI contract.

Proposed documentation fix
- | `-M`, `--metal` | off | Use the default Metal device on macOS |
+ | `-mt`, `--metal` | off | Use the default Metal device on macOS |

Also applies to: 178-178

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main.cpp` at line 76, Fix the Metal CLI contract around the help text in
main.cpp and the argument normalization/dispatch logic: either update README.md
to document the actual -m form, or preserve the documented -M alias by ensuring
normalization does not convert it into the model option and dispatches it as
Metal. Apply the same correction to both Metal help entries.

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