@@ -19,33 +19,47 @@ const (
19
19
)
20
20
21
21
var statusCmd = & cobra.Command {
22
- Use : "status" ,
22
+ Use : "status [host...] " ,
23
23
Short : "Show the status of configured access tokens" ,
24
- Long : `Display all configured access tokens and validate them with their respective providers.` ,
24
+ Long : `Display all configured access tokens and validate them with their respective providers.
25
+
26
+ If no hosts are specified, all configured tokens are shown.
27
+ If one or more hosts are specified, only tokens for those hosts are displayed.` ,
25
28
RunE : runStatus ,
26
29
SilenceUsage : true ,
27
30
}
28
31
29
- func runStatus (_ * cobra.Command , _ []string ) error {
32
+ func runStatus (_ * cobra.Command , args []string ) error {
30
33
cfg , err := config .New (configPath )
31
34
if err != nil {
32
35
return fmt .Errorf ("failed to initialize config: %w" , err )
33
36
}
34
37
35
- hosts , err := cfg .ListTokens ()
36
- if err != nil {
37
- return fmt .Errorf ("failed to list tokens: %w" , err )
38
- }
38
+ var hosts []string
39
+ if len (args ) > 0 {
40
+ // Use the specified hosts
41
+ hosts = args
42
+ } else {
43
+ // Get all configured hosts
44
+ hosts , err = cfg .ListTokens ()
45
+ if err != nil {
46
+ return fmt .Errorf ("failed to list tokens: %w" , err )
47
+ }
39
48
40
- if len (hosts ) == 0 {
41
- fmt .Println ("No access tokens configured." )
42
- fmt .Printf ("Config file: %s\n " , cfg .GetPath ())
43
- fmt .Println ("\n Run 'nix-auth login' to add a token." )
49
+ if len (hosts ) == 0 {
50
+ fmt .Println ("No access tokens configured." )
51
+ fmt .Printf ("Config file: %s\n " , cfg .GetPath ())
52
+ fmt .Println ("\n Run 'nix-auth login' to add a token." )
44
53
45
- return nil
54
+ return nil
55
+ }
46
56
}
47
57
48
- fmt .Printf ("Access Tokens (%d configured in %s)\n \n " , len (hosts ), cfg .GetPath ())
58
+ if len (args ) > 0 {
59
+ fmt .Printf ("Access Tokens (showing %d hosts from %s)\n \n " , len (hosts ), cfg .GetPath ())
60
+ } else {
61
+ fmt .Printf ("Access Tokens (%d configured in %s)\n \n " , len (hosts ), cfg .GetPath ())
62
+ }
49
63
50
64
ctx := context .Background ()
51
65
@@ -78,6 +92,15 @@ func runStatus(_ *cobra.Command, _ []string) error {
78
92
continue
79
93
}
80
94
95
+ // Check if token is empty (host not configured)
96
+ if token == "" {
97
+ _ , _ = fmt .Fprintf (w , " Provider\t %s\n " , providerName )
98
+ _ , _ = fmt .Fprintf (w , " Status\t ✗ No token configured\n " )
99
+ _ = w .Flush ()
100
+
101
+ continue
102
+ }
103
+
81
104
_ , _ = fmt .Fprintf (w , " Provider\t %s\n " , providerName )
82
105
83
106
// Validate token and get user info
0 commit comments