Skip to content

fix: handle expression arg that matches a filename#2714

Open
sjh9714 wants to merge 1 commit into
mikefarah:masterfrom
sjh9714:fix-expression-arg-filename-conflict
Open

fix: handle expression arg that matches a filename#2714
sjh9714 wants to merge 1 commit into
mikefarah:masterfrom
sjh9714:fix-expression-arg-filename-conflict

Conversation

@sjh9714
Copy link
Copy Markdown

@sjh9714 sjh9714 commented May 20, 2026

Summary

Fixes expression arguments that happen to match an existing filename.

What changed

  • Added processArgs() regression coverage for .version when a same-named file exists and an input file or stdin follows it.
  • Updated first-argument detection so expression-looking dot args followed by input are treated as expressions.
  • Preserved single-file usage, .yq expression files, and explicit path-qualified file args such as ./.version.

Why

Before this change, processArgs() skipped expression detection when the first arg existed as a file, so yq '.version' data.yml could read .version as an input file instead of evaluating .version against data.yml.

After this change, .version data.yml and .version - are parsed as expression plus input, while users can still force file interpretation with ./.version.

Testing

  • go test ./cmd -run TestProcessArgs -count=1 failed before the production fix with .version left in args instead of becoming the expression.
  • go test ./cmd -run TestProcessArgs -count=1
  • go test ./cmd -count=1
  • go test ./...
  • bash ./scripts/devtools.sh
  • make local test
  • git diff --check

Fixes #2477

Note: I used Codex to help inspect the code path and draft the regression test, but I reviewed the final diff and ran the listed verification commands locally.

@sjh9714 sjh9714 marked this pull request as ready for review May 20, 2026 07:21
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.

if the key in the command line is a filename is processed as file

1 participant