laravel / pennant

A simple, lightweight library for managing feature flags.
https://laravel.com/docs/pennant
MIT License
482 stars 49 forks source link

[1.x] Allow excluding features from purge command #89

Closed timacdonald closed 9 months ago

timacdonald commented 9 months ago

Re-implementation of https://github.com/laravel/pennant/pull/87

Documentation: https://github.com/laravel/docs/pull/9448

Allows for excluding features from the purge command. This command now has the following API:

# Purge everything from storage (already exists)

php artisan pennant:purge

# Purge specific features from storage (already exists)

php artisan pennant:purge foo bar

# Purge all features from storage except those specified (new ✨)

php artisan pennant:purge --except=foo --except=bar

# Purge all features from storage except those registered (new ✨)

php artisan pennant:purge --except-registered

--except-registered?

You could run this on deploy to clear out feature flags you no longer use.

[!WARNING] Pennant allows you to dynamically register features, i.e., they don't have to be defined in a service provider. If you use this flag it may clear features you still use in your application if you are using dynamic registration.

Use in combination

The command handles using all of these in combination, e.g., it will be able to handle the following...

php artisan pennant:purge foo bar --except=bar --except-registered

The excepts will always take precedence and ensure that any features found in that list are not purged, even if they are explicitly passed to the command like we did with foo and bar.

3rd party drivers

Drivers should implement the CanListStoredFeatures interface if they wish to support these new features. This contract adds a single new method, stored, which returns a unique list of stored feature names - similar to the defined interface method which returns a unique list of all the defined feature names.