Skip to content

fix(cli): validate and reject misplaced flags placed after '--' - #163

Merged
HarshK97 merged 1 commit into
mainfrom
fix/cli-validate-misplaced-flags
Sep 19, 2026
Merged

HarshK97 merged 1 commit into
mainfrom
fix/cli-validate-misplaced-flags

Conversation

@HarshK97

Copy link
Copy Markdown
Owner

Problem

  1. When flags are placed after -- (e.g. diffm main path -- -f sbs), Cobra stops parsing options and dumps the flag into positional arguments.
  2. The CLI then tries to resolve the flag as a Git revision or file path, resulting in confusing downstream errors instead of explaining why the flag was ignored.

What Changed

  • Added validateNoMisplacedFlags to check positional arguments for arguments starting with -.
  • Allowed valid positional arguments through, specifically stdin ("-") and actual files on disk or in the Git index that start with -.
  • Ran the validation at the very start of rootCmd.Run so misplaced flags fail fast across all modes, including --parse-tree and --cst.
  • Added table-driven unit tests in cmd/diff_test.go covering valid paths, stdin, misplaced short/long flags, and disk files starting with a dash.

- Add validateNoMisplacedFlags to detect when options are placed after '--'
- Provide clear error messaging with guidance on flag placement
- Allow literal files starting with '-' when existing on disk or index
- Add unit test TestValidateNoMisplacedFlags
@HarshK97
HarshK97 merged commit d546f7c into main Sep 19, 2026
17 checks passed
@HarshK97
HarshK97 deleted the fix/cli-validate-misplaced-flags branch September 19, 2026 04:31
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