fix(token): respect --active flag in JSON output
Summary
Fixes #8155 (closed)
The token list command was ignoring the --active flag when outputting JSON format. The command was returning the raw API response (apiTokens) instead of the filtered list (outputTokens), causing inactive tokens to be included even when --active was specified.
Changes
-
Fixed: JSON output now uses
outputTokens(filtered) instead ofapiTokens(unfiltered) -
Removed: Unused
apiTokensvariable and assignments -
Added: Test case for
--active --output jsonto prevent regression
Test Coverage
Added test case: "list active personal access tokens as json"
- Verifies that only 1 active token is returned when using
--active --output json - Validates the returned token is the correct active one
All existing tests continue to pass, confirming the fix doesn't break unfiltered JSON output.
Before/After
Before (bug):
$ glab token list -U @me -a -F json | jq '[.[]|select(.active == false)]|length'
14 # ❌ Should be 0
After (fixed):
$ glab token list -U @me -a -F json | jq '[.[]|select(.active == false)]|length'
0 # ✅ Correct