mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-04-20 16:40:29 +00:00
66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"sort"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newStatusCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "status",
|
|
Short: "Show all configured accounts",
|
|
RunE: runStatus,
|
|
}
|
|
}
|
|
|
|
func runStatus(cmd *cobra.Command, args []string) error {
|
|
cfg, err := loadConfig()
|
|
if err != nil {
|
|
return fmt.Errorf("loading config: %w", err)
|
|
}
|
|
|
|
if len(cfg.Registries) == 0 {
|
|
fmt.Fprintf(os.Stderr, "No accounts configured.\n")
|
|
fmt.Fprintf(os.Stderr, "Run: docker-credential-atcr login\n")
|
|
return nil
|
|
}
|
|
|
|
// Sort registry URLs for stable output
|
|
var urls []string
|
|
for url := range cfg.Registries {
|
|
urls = append(urls, url)
|
|
}
|
|
sort.Strings(urls)
|
|
|
|
for _, url := range urls {
|
|
reg := cfg.Registries[url]
|
|
fmt.Printf("%s\n", url)
|
|
|
|
// Sort handles for stable output
|
|
var handles []string
|
|
for h := range reg.Accounts {
|
|
handles = append(handles, h)
|
|
}
|
|
sort.Strings(handles)
|
|
|
|
for _, handle := range handles {
|
|
acct := reg.Accounts[handle]
|
|
marker := " "
|
|
if handle == reg.Active {
|
|
marker = "* "
|
|
}
|
|
did := ""
|
|
if acct.DID != "" {
|
|
did = fmt.Sprintf(" (%s)", acct.DID)
|
|
}
|
|
fmt.Printf(" %s%s%s\n", marker, handle, did)
|
|
}
|
|
fmt.Println()
|
|
}
|
|
|
|
return nil
|
|
}
|