Skip to content

feat: Print an undo command after a flag change - #123

Open
0xvikram wants to merge 2 commits into
Flagsmith:mainfrom
0xvikram:feat/undo-hints
Open

0xvikram wants to merge 2 commits into
Flagsmith:mainfrom
0xvikram:feat/undo-hints

Conversation

@0xvikram

Copy link
Copy Markdown

Part of #65: hint an undo command after a successful mutation.

After flag update, flag enable or flag disable succeeds, the CLI prints the command that puts the flag back, on stderr under the confirmation:

✓ Set undo-hint-check to 30 in environment Production (dtALjtDbbZmK8BVDXk5a8f)
  Undo: flagsmith flag update undo-hint-check --value 25
✓ Enabled undo-hint-check in environment Production (dtALjtDbbZmK8BVDXk5a8f)
  Undo: flagsmith flag update undo-hint-check --disable
  • The undo is worked out from the state the command already reads before the write, so it costs no extra request.
  • Segment overrides: an edit restores the previous enabled state, value or priority with --segment <id>; a newly created override is undone with flagsmith flag delete <feature> --segment <id>.
  • An explicit --project / --environment is repeated, so the command works from any directory. Values are shell-quoted, and a string that would be inferred as another type gets --type string.
  • No hint when the previous state can't be restated as a command (an unset value, re-weighted variants) or when nothing changed. No hint is better than a wrong one.

Not in this PR: the first half of #65 (showing a diff when confirming). That needs a decision on the format, so I left it for a follow-up.

Verified

  • TestFlagUpdateUndoHint (9 cases, including a failed update and the no-hint cases) and TestUndoValueArgs. The hint cases fail without the change.
  • go vet ./... and go test -race ./... pass.
  • On Flagsmith Cloud with a throwaway feature: set a value, enabled it, ran the printed undo, and the flag was back to its previous state.

This contribution was prepared with AI coding assistance.

After flag update, flag enable or flag disable succeeds, print the command
that puts the flag back, on stderr under the confirmation:

  ✓ Set max_items to 30 in environment Production (…)
    Undo: flagsmith flag update max_items --value 25

It is worked out from the state read before the write. A new segment override
is undone with flag delete --segment. An explicit --project or --environment
is repeated so the command works from anywhere. No hint is printed when the
previous state can't be restated as a command (an unset value, re-weighted
variants) or when nothing changed.

Part of Flagsmith#65.
@0xvikram
0xvikram requested a review from a team as a code owner November 27, 2026 09:02
@0xvikram
0xvikram requested review from a team and emyller and a balanced review from Copilot and removed request for a team November 27, 2026 09:02

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

Re-trigger cubic

Comment thread internal/cmd/flag_update.go Resolved
Comment thread internal/cmd/flag_update.go Resolved
Comment thread internal/cmd/undo.go Resolved
Comment thread internal/cmd/cmd_test.go Resolved
Comment thread internal/cmd/cmd_test.go Resolved
- Repeat an explicit --api-url and --organisation in the undo command.
- Print no hint when --value sets the value it already had.
- Print undo hints for --identifier updates: a new override is undone by
  deleting it, an existing one by restoring its state.
- Assert the hint is on stderr, after the confirmation lines.
- Add Given/When/Then sections to TestUndoValueArgs.

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 3 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval skipped because this PR is from an external contributor.

Re-trigger cubic

This branch has not been deployed

No deployments
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.

2 participants