Skip to content

Fix double-hyphen (--) parsing in CLI commands#1990

Merged
aknysh merged 4 commits intomainfrom
aknysh/fix-workflows-5
Jan 18, 2026
Merged

Fix double-hyphen (--) parsing in CLI commands#1990
aknysh merged 4 commits intomainfrom
aknysh/fix-workflows-5

Conversation

@aknysh
Copy link
Copy Markdown
Member

@aknysh aknysh commented Jan 18, 2026

what

  • Fixed issue where args after -- (POSIX end-of-options marker) were incorrectly parsed by Cobra/pflag
  • The stack flag value was being corrupted when commands included -- followed by terraform flags like -consolidate-warnings=false
  • Added named constant endOfOptionsMarker to replace repeated "--" string literal (linting fix)

why

  • Commands like atmos terraform plan vpc --stack nonprod -- -consolidate-warnings=false were failing with corrupted stack values
  • The stack value would become olidate-warnings=false instead of nonprod because pflag was incorrectly parsing the -consolidate-warnings=false argument after --
  • Per POSIX convention, everything after -- should be passed through to the subprocess without being parsed by the CLI

references

Summary by CodeRabbit

  • Bug Fixes

    • Corrected command-line parsing so the "--" end-of-options marker properly isolates subsequent flags/args and prevents corruption of preceding values.
  • Tests

    • Added comprehensive tests and scenario fixtures covering various "--" usages to verify parsing, precedence, and edge cases; updated CLI error/help snapshots to reflect added workflows.
  • Chores

    • Bumped several Go module dependencies to newer patch/minor releases.

✏️ Tip: You can customize this high-level summary in your review settings.

@aknysh aknysh requested a review from a team as a code owner January 18, 2026 02:02
@aknysh aknysh added the patch A minor, backward compatible change label Jan 18, 2026
@github-actions github-actions bot added the size/l Large size PR label Jan 18, 2026
@aknysh aknysh self-assigned this Jan 18, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 18, 2026

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

  • go.mod

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 18, 2026

📝 Walkthrough

Walkthrough

Adds POSIX "--" end-of-options handling to the compatibility flag translator so args after "--" are passed through untouched; adds unit and integration tests reproducing issue #1967; updates three go module dependencies; updates test fixtures and a snapshot.

Changes

Cohort / File(s) Summary
Dependency Updates
go.mod
Bumped module versions: github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.18→v1.20.19, github.com/charmbracelet/x/ansi v0.11.3→v0.11.4, github.com/clipperhouse/displaywidth v0.6.1→v0.7.0
Flag Parsing Logic
pkg/flags/compat/compatibility_flags.go
Introduced endOfOptionsMarker ("--"); treat it as non-flag input during validation; when encountered, pass marker into Atmos, move all following args into separatedArgs, and stop further Cobra/pflag parsing
Compatibility Tests
pkg/flags/compat/compatibility_flags_test.go
Added TestCompatibilityFlagTranslator_DoubleHyphenSeparator covering multiple scenarios around -- and separated args
Workflow Utils Tests
internal/exec/workflow_utils_test.go
Added tests TestDoubleHyphenStackInsertion and TestDoubleHyphenIssue1967 (note: duplicate test blocks present) to validate stack insertion and parsing around --
Integration E2E Tests
tests/cli_double_hyphen_test.go
New end-to-end tests: TestDoubleHyphenSeparator, TestDoubleHyphenWithConsolidateWarnings (reproduces #1967), and TestDoubleHyphenStackNotOverwritten asserting correct stack isolation from post--- flags
Fixtures & Snapshots
tests/fixtures/scenarios/workflows/stacks/workflows/test.yaml, tests/snapshots/TestCLICommands_atmos_workflow_not_found.stderr.golden
Added multiple workflow test cases exercising -- behaviors and updated the workflow list snapshot to include the new fixtures

Sequence Diagram(s)

mermaid
sequenceDiagram
participant User
participant AtmosCLI as Atmos CLI
participant CompatTranslator as CompatibilityTranslator
participant Cobra as Cobra/pflag
participant Subproc as Subprocess (Terraform)
User->>AtmosCLI: run command with "--" and flags after
AtmosCLI->>CompatTranslator: build translation input
CompatTranslator->>Cobra: scan args until "--"
Cobra-->>CompatTranslator: parsed flags (pre---)
CompatTranslator-->>CompatTranslator: on "--", mark endOfOptions and collect remaining args into separatedArgs
CompatTranslator->>AtmosCLI: return atmosArgs + separatedArgs
AtmosCLI->>Subproc: invoke subprocess with atmosArgs then "--" and separatedArgs
Subproc-->>User: executes receiving separated args untouched

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

Possibly related PRs

Suggested reviewers

  • osterman
🚥 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 directly and concisely describes the main fix: resolving double-hyphen (--) parsing issues in CLI commands, which aligns with the primary changeset.
Linked Issues check ✅ Passed The PR fully addresses issue #1967 by fixing argument parsing after '--', preventing stack value corruption when Terraform flags follow the separator.
Out of Scope Changes check ✅ Passed All changes directly support the double-hyphen parsing fix: flag handling updates, comprehensive test coverage across unit and integration levels, and fixture additions.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch aknysh/fix-workflows-5

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 and usage tips.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 18, 2026

📝 Walkthrough

Walkthrough

This PR resolves issue #1967 by refactoring double-hyphen (--) argument handling in Atmos workflows. It introduces proper POSIX end-of-options semantics to prevent stack values from being corrupted when terraform flags are passed after --. The fix updates flag translation logic, adds extensive test coverage, and bumps three dependencies to patch versions.

Changes

Cohort / File(s) Summary
Dependency Updates
LICENSE, go.mod
Updated three dependencies to patch versions: aws-sdk-go-v2/feature/s3/manager (v1.20.18→v1.20.19), charmbracelet/x/ansi (v0.11.3→v0.11.4), clipperhouse/displaywidth (v0.6.1→v0.7.0)
Core Double-Hyphen Logic
pkg/flags/compat/compatibility_flags.go
Introduced internal endOfOptionsMarker constant and refactored flag translation to properly detect and handle -- as POSIX end-of-options marker, separating arguments before and after the delimiter
Unit & Integration Tests
internal/exec/workflow_utils_test.go, pkg/flags/compat/compatibility_flags_test.go, tests/cli_double_hyphen_test.go
Added 424 lines of test coverage validating: stack insertion before --, argument preservation after --, stack value integrity, and terraform flag pass-through in workflows
Test Fixtures & Snapshots
tests/fixtures/scenarios/workflows/stacks/workflows/test.yaml, tests/snapshots/TestCLICommands_atmos_workflow_not_found.stderr.golden
Added workflow test fixtures covering stack precedence, multiple flags after --, and shell parsing; updated snapshot with new workflow entries

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • osterman
  • aknysh
🚥 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 'Fix double-hyphen (--) parsing in CLI commands' clearly and concisely describes the main change: addressing a parsing bug with the POSIX end-of-options marker in command-line argument handling.
Linked Issues check ✅ Passed The PR addresses all core requirements from issue #1967: fixes double-hyphen argument parsing, prevents stack corruption from flags after --, adds endOfOptionsMarker constant for code clarity, and includes comprehensive tests validating correct pass-through behavior.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the double-hyphen parsing fix: compatibility flag handling, internal utility functions, comprehensive test coverage, and dependency version updates. No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch aknysh/fix-workflows-5

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@internal/exec/workflow_utils_test.go`:
- Around line 1610-1625: The test re-implements the stack insertion loop from
workflow_utils.go (the block that checks for "--" and inserts "-s" with
tt.workflowStack into args), which can drift if production logic changes;
extract that insertion into a single helper (e.g., InsertWorkflowStack or
ApplyWorkflowStack) in workflow_utils.go and call it from both the production
code and workflow_utils_test.go instead of duplicating the loop, and also fix
the two inline comments in workflow_utils_test.go to end with periods to satisfy
godot.

In `@tests/cli_double_hyphen_test.go`:
- Around line 49-95: The workspace assertion is brittle: Terraform sometimes
emits `Workspace "nonprod" doesn't exist.` instead of `Switched to workspace
"nonprod"`, causing CI flakes; update the test that checks combinedOutput (the
block that uses tt.stderrContains and combinedOutput := stdout.String() +
stderr.String()) to accept either message (e.g., assert that combinedOutput
contains tt.stderrContains OR contains `Workspace "<stack>" doesn't exist.`), or
broaden the expectation by checking for either substring using tt.expectedStack
(from tests entries) so the assertion is resilient to both `Switched to
workspace "<stack>"` and `Workspace "<stack>" doesn't exist.`.
🧹 Nitpick comments (1)
tests/cli_double_hyphen_test.go (1)

32-35: Prefer t.Setenv/t.Cleanup for env isolation.

Using os.Unsetenv can leak state across tests. Prefer t.Setenv (set empty if lookup semantics allow) or wrap an unset helper with t.Cleanup to restore prior values. Based on learnings, prefer t.Setenv for env isolation in tests.

Also applies to: 121-124, 172-175

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@internal/exec/workflow_utils_test.go`:
- Around line 1620-1624: The two inline comments in the test block that
manipulate args (the comment "Insert before the \"--\"" and the comment "Append
at the end") need trailing periods to satisfy godot linting; update those
comments to "Insert before the \"--\"." and "Append at the end." respectively in
the code that appends tt.workflowStack to args (refer to variables args, idx and
tt.workflowStack in this test helper block).

In `@tests/cli_double_hyphen_test.go`:
- Around line 41-69: The test cases in tests/cli_double_hyphen_test.go pass
unknown flags after the "--" which can make Terraform fail before emitting the
workspace switch message; update the three affected test entries (the ones with
name values "stack before double-hyphen is parsed correctly", "short stack flag
before double-hyphen", and "stack=value syntax before double-hyphen") to use
valid Terraform plan flags after the "--" (for example "-input=false",
"-lock=false", or "-no-color") in their args slices so the command advances far
enough to produce the "Switched to workspace \"nonprod\"" output while still
verifying pass-through of arguments.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 18, 2026

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 74.93%. Comparing base (10080ca) to head (dc084c9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/flags/compat/compatibility_flags.go 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1990   +/-   ##
=======================================
  Coverage   74.92%   74.93%           
=======================================
  Files         777      777           
  Lines       71302    71307    +5     
=======================================
+ Hits        53423    53433   +10     
+ Misses      14399    14395    -4     
+ Partials     3480     3479    -1     
Flag Coverage Δ
unittests 74.93% <87.50%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/flags/compat/compatibility_flags.go 92.00% <87.50%> (+0.27%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aknysh aknysh requested a review from osterman January 18, 2026 05:17
@aknysh aknysh merged commit 722a5c3 into main Jan 18, 2026
57 checks passed
@aknysh aknysh deleted the aknysh/fix-workflows-5 branch January 18, 2026 20:03
@github-actions
Copy link
Copy Markdown

These changes were released in v1.204.1-rc.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch A minor, backward compatible change size/l Large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

atmos workflow parsing error on double hyphen

2 participants