DEV Community

Hiroyuki Kuromiya
Hiroyuki Kuromiya

Posted on • Edited on

Introducing a CLI Tool for Automatically Detecting Unused Unleash Flags

Hello everyone! Today, I'd like to introduce a CLI tool I developed that automatically detects unused Unleash flags. By using this tool, you can easily identify outdated feature flags in your project and help clean up your codebase.

Tool Overview

  • Repository: stale-flag-detector
  • Function: Automatically detects unused Unleash flags
  • Installation: Clone the repository and generate the executable using the go build command

Basic Usage

After building the tool, you can display a list of stale flags by running it as follows:

% ./stale-flag-detector
Stale flags:
- unleash-ai-example-stale
- another-stale-flag
Enter fullscreen mode Exit fullscreen mode

Options

This tool has two main options:

  1. --exclude-potentially-stale-flags

    • Excludes potentially stale flags from the results
    • For more details on potentially stale flags, please refer to the Unleash documentation
  2. --output-regex

    • Outputs the results in regex format

Example of Regex Output

% ./stale-flag-detector --output-regex
(unleash-ai-example-stale|another-stale-flag)
Enter fullscreen mode Exit fullscreen mode

Practical Usage Example

The true value of this tool is realized when combined with other command-line tools. For example, by combining it with the pt command (The Platinum Searcher), you can easily identify where stale flags are being used in your project:

% pt -e `./stale-flag-detector --output-regex` ../sample-app-for-unleash-checker
../sample-app-for-unleash-checker/app/stale.py
9:if client.is_enabled("unleash-ai-example-stale"):
Enter fullscreen mode Exit fullscreen mode

Using this method provides the following advantages:

  • Accurately locate unused flags
  • Simplify codebase cleanup
  • Contribute to reducing technical debt

Summary

The stale-flag-detector is a powerful tool for streamlining the maintenance of projects using Unleash. It can help improve feature flag management and keep your codebase clean. Give it a try!

If you have any feedback or suggestions for improvement, please let us know through Issues or Pull Requests on the GitHub repository. We look forward to hearing your opinions!

Top comments (0)