11//
2- // Copyright 2023-2025 The Chainloop Authors.
2+ // Copyright 2023-2026 The Chainloop Authors.
33//
44// Licensed under the Apache License, Version 2.0 (the "License");
55// you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ import (
2828func newAPITokenListCmd () * cobra.Command {
2929 var (
3030 includeRevoked bool
31+ statusFilter string
3132 project string
3233 scope string
3334 )
@@ -37,6 +38,12 @@ func newAPITokenListCmd() *cobra.Command {
3738 "global" ,
3839 }
3940
41+ var availableStatusFilters = []string {
42+ "active" ,
43+ "revoked" ,
44+ "all" ,
45+ }
46+
4047 cmd := & cobra.Command {
4148 Use : "list" ,
4249 Aliases : []string {"ls" },
@@ -46,10 +53,22 @@ func newAPITokenListCmd() *cobra.Command {
4653 return fmt .Errorf ("invalid scope %q, please chose one of: %v" , scope , availableScopes )
4754 }
4855
56+ if statusFilter != "" && ! slices .Contains (availableStatusFilters , statusFilter ) {
57+ return fmt .Errorf ("invalid status %q, please choose one of: %v" , statusFilter , availableStatusFilters )
58+ }
59+
4960 return nil
5061 },
5162 RunE : func (cmd * cobra.Command , args []string ) error {
52- res , err := action .NewAPITokenList (ActionOpts ).Run (context .Background (), includeRevoked , project , scope )
63+ // --all is deprecated: map it to --status all
64+ if includeRevoked {
65+ cmd .PrintErr ("Warning: --all is deprecated, use --status all instead\n " )
66+ if statusFilter == "" {
67+ statusFilter = "all"
68+ }
69+ }
70+
71+ res , err := action .NewAPITokenList (ActionOpts ).Run (context .Background (), statusFilter , project , scope )
5372 if err != nil {
5473 return fmt .Errorf ("listing API tokens: %w" , err )
5574 }
@@ -58,7 +77,11 @@ func newAPITokenListCmd() *cobra.Command {
5877 },
5978 }
6079
61- cmd .Flags ().BoolVarP (& includeRevoked , "all" , "a" , false , "show all API tokens including revoked ones" )
80+ cmd .Flags ().BoolVarP (& includeRevoked , "all" , "a" , false , "Deprecated: use --status all instead" )
81+ if err := cmd .Flags ().MarkDeprecated ("all" , "use --status all instead" ); err != nil {
82+ panic (err )
83+ }
84+ cmd .Flags ().StringVar (& statusFilter , "status" , "" , fmt .Sprintf ("filter by token status, available values: %v" , availableStatusFilters ))
6285 cmd .Flags ().StringVarP (& project , "project" , "p" , "" , "filter by project name" )
6386 cmd .Flags ().StringVarP (& scope , "scope" , "s" , "" , fmt .Sprintf ("filter by scope, available scopes: %v" , availableScopes ))
6487 return cmd
0 commit comments