Skip to content

Add artisan commands for feature flag management#10

Open
stevethomas wants to merge 2 commits into
mainfrom
v2/artisan-commands
Open

Add artisan commands for feature flag management#10
stevethomas wants to merge 2 commits into
mainfrom
v2/artisan-commands

Conversation

@stevethomas

Copy link
Copy Markdown
Member

Summary

Re-opened from #5. Originally merged but reverted from main to keep v1.x clean — this is targeted at v2.

  • feature:manage — interactive table to toggle feature states
  • feature:on / feature:off — turn individual features on/off
  • feature:set — set a feature to a specific state (on/off/dynamic)

Test plan

  • Existing tests pass
  • New command tests pass
  • Commands work interactively via php artisan

JonathanLouw and others added 2 commits April 16, 2026 16:34
* Add artisan commands for managing feature flags

Adds interactive `feature:manage` command for SSH-based flag toggling
with table display, selection, and confirmation. Also adds scriptable
`feature:on`, `feature:off`, and `feature:state` commands for
automation. All commands delegate to existing FeatureFlags methods
which handle cache invalidation and event dispatching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix code style

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Document artisan commands in README

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
);

if ($this->confirm("Set '{$selected}' to '{$newState}'?")) {
FeatureFlag::updateFeatureState($selected, FeatureState::from($newState));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The ManageFeaturesCommand does not handle a potential MissingFeatureException, which can cause the artisan command to crash if a feature is not found during execution.
Severity: LOW

Suggested Fix

Wrap the call to FeatureFlag::updateFeatureState() at line 47 of ManageFeaturesCommand.php within a try-catch block. Catch the MissingFeatureException and output a user-friendly error message to the console, consistent with the error handling in other feature flag commands.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/Commands/ManageFeaturesCommand.php#L47

Potential issue: The `ManageFeaturesCommand` calls `FeatureFlag::updateFeatureState()`
without a `try-catch` block. If a feature is not found, `updateFeatureState()`
internally calls `getFeatureModel()`, which throws a `MissingFeatureException` by
default. This can occur in a race condition where a feature is deleted from the database
after the command has loaded the list of features but before the user selects one to
manage. Unlike other commands like `TurnOnFeatureCommand` which handle this exception,
`ManageFeaturesCommand` will crash with an unhandled exception instead of displaying a
graceful error message to the user running the command.

Did we get this right? 👍 / 👎 to inform future reviews.

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