Skip to content

Fix leading '--' stripping to preserve command data - #187

Merged
ocean merged 2 commits into
ahoy-cli:masterfrom
ocean:fix/issue-186-literal-separator
Sep 2, 2026
Merged

ocean merged 2 commits into
ahoy-cli:masterfrom
ocean:fix/issue-186-literal-separator

Conversation

@ocean

@ocean ocean commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #186. Ahoy removed every -- a user typed on the command line, so a separator meant as data never reached the wrapped tool. Now a leading -- is consumed, as it always was, and every later one is the command's own data.

This came out of the discussion on #163.

The issue

Plenty of tools need a -- of their own, and stripping it silently changed what the user asked for:

Typed Before After
ahoy k exec mypod -- ls /app kubectl exec mypod ls /app kubectl exec mypod -- ls /app
ahoy npm run build -- --verbose npm run build --verbose npm run build -- --verbose
ahoy cargo run -- --port 8080 cargo run --port 8080 cargo run -- --port 8080
ahoy git checkout -- deploy git checkout deploy git checkout -- deploy

The git case is the one that convinced me this was worth doing on its own. With a branch and a file sharing a name, and uncommitted edits to the file:

=== before: on 'main', file 'deploy' edited, branch 'deploy' also exists
running: ahoy git checkout -- deploy
Switched to branch 'deploy'
M deploy
result: branch=deploy file='MY UNSAVED EDITS'

=== after: on 'main', file 'deploy' edited, branch 'deploy' also exists
running: ahoy git checkout -- deploy
result: branch=main file='committed content'

A request to discard edits to a file switched the branch instead and left the edits in place. That is the same shape of failure as #182: the wrapped tool succeeds, having done something other than what was typed.

Original change

cmdArgs = args
if len(cmdArgs) > 0 && cmdArgs[0] == "--" {
    cmdArgs = cmdArgs[1:]
}

The old filter came from #101, fixing #100, where ahoy up -- --build reached docker-compose as -- --build. The intent was that a leading -- shields what follows, which urfave/cli needed at the time. The implementation stripped every occurrence rather than the first, and then continued into v3 unchanged.

Since #182, Ahoy does not parse a command's arguments at all, so a leading -- is no longer needed for its original purpose. Scripts and aliases still use it though, so it is still honoured, and ahoy up -- --build behaves exactly as it does today.

Compatibility

The only behaviour lost is a non-leading -- being silently deleted, which is the defect. A -- written inside the cmd: body in .ahoy.yml was never affected either way, since that string goes to the shell untouched.

Closes #186

Summary by CodeRabbit

  • Bug Fixes
    • Corrected command argument handling so only the initial -- separator is consumed.
    • Preserved subsequent -- values when passed to executed commands.
    • Improved handling of repeated separators and separator-only arguments.

Ahoy removed every '--' a user typed, so a separator meant as data never
reached the wrapped tool. That silently changed the request for anything
needing one of its own: kubectl exec, npm run, cargo run, git checkout.

The worst case is git. With a branch and a file sharing a name,
'ahoy git checkout -- deploy' arrived as 'git checkout deploy', so a
request to discard edits to a file switched branch instead and left the
edits in place.

The strip came from ahoy-cli#101, fixing ahoy-cli#100 ('ahoy up -- --build' reaching
docker-compose as '-- --build'). The intent there was that a leading '--'
shields what follows, which urfave/cli needed at the time; the
implementation stripped every occurrence instead of the first. Since ahoy-cli#182
ahoy no longer parses a command's arguments at all, so a leading '--' is
now only a readability habit, but scripts still use it and honouring it
costs nothing.

Now: a leading '--' is consumed, every later one is the command's data.

Claude-Session: https://claude.ai/code/session_01629NFuQxTr678Tdh8AD39d
@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 40dceeca-c7a4-4bef-90df-ed980fa97c20

📥 Commits

Reviewing files that changed from the base of the PR and between 968aefa and 5a77519.

📒 Files selected for processing (2)
  • ahoy.go
  • tests/argument-passthrough.bats

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

Ahoy now removes only a leading -- from wrapped command arguments. Later -- tokens remain unchanged. Tests cover repeated leading separators, separator-only input, and separator-plus-data input.

Changes

Separator pass-through

Layer / File(s) Summary
Argument handling and validation
ahoy.go, tests/argument-passthrough.bats
getCommands consumes one leading -- and preserves later occurrences. Tests verify the updated argument behaviour.

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

Merge Risk: ⚪ Minimal · up to 5a775

This change limits separator removal to the leading --, preserving later separators as command data while retaining existing leading-separator behavior; no actionable merge-blocking risk remains.

Suggested reviewers: hanoii

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: stripping only a leading -- while preserving later command data.
Linked Issues check ✅ Passed The implementation removes only one leading -- and preserves later occurrences. The tests cover leading, repeated, separator-only, and separator-plus-data cases. This satisfies issue #186.
Out of Scope Changes check ✅ Passed The changes are limited to argument handling in ahoy.go and tests for the required -- pass-through behaviour. No unrelated code changes are identified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ 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.

@ocean
ocean merged commit e5fecae into ahoy-cli:master Sep 2, 2026
13 checks passed
@ocean
ocean deleted the fix/issue-186-literal-separator branch September 2, 2026 07:59
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.

A literal -- cannot be passed to a wrapped command: every occurrence is stripped, not just a leading one

1 participant

⌂ 换网址