Skip to content

Commit 0e34f66

Browse files
committed
feat: allow to check the status of a specific host
1 parent 4cd13a4 commit 0e34f66

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ View all configured tokens:
103103
nix-auth status
104104
```
105105

106+
View specific tokens by host:
107+
108+
```bash
109+
nix-auth status github.com # Check a single host
110+
nix-auth status github.com gitlab.com # Check multiple hosts
111+
```
112+
106113
### Logout
107114

108115
Remove a token interactively:

cmd/status.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,47 @@ const (
1919
)
2020

2121
var statusCmd = &cobra.Command{
22-
Use: "status",
22+
Use: "status [host...]",
2323
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.`,
2528
RunE: runStatus,
2629
SilenceUsage: true,
2730
}
2831

29-
func runStatus(_ *cobra.Command, _ []string) error {
32+
func runStatus(_ *cobra.Command, args []string) error {
3033
cfg, err := config.New(configPath)
3134
if err != nil {
3235
return fmt.Errorf("failed to initialize config: %w", err)
3336
}
3437

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+
}
3948

40-
if len(hosts) == 0 {
41-
fmt.Println("No access tokens configured.")
42-
fmt.Printf("Config file: %s\n", cfg.GetPath())
43-
fmt.Println("\nRun '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("\nRun 'nix-auth login' to add a token.")
4453

45-
return nil
54+
return nil
55+
}
4656
}
4757

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+
}
4963

5064
ctx := context.Background()
5165

@@ -78,6 +92,15 @@ func runStatus(_ *cobra.Command, _ []string) error {
7892
continue
7993
}
8094

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+
81104
_, _ = fmt.Fprintf(w, " Provider\t%s\n", providerName)
82105

83106
// Validate token and get user info

0 commit comments

Comments
 (0)