package main import ( "errors" "fmt" "os" "text/tabwriter" "github.com/spf13/cobra" "git.wxccs.org/iceking2nd/winauth-go/internal/config" "git.wxccs.org/iceking2nd/winauth-go/internal/i18n" ) func newListCmd() *cobra.Command { return &cobra.Command{ Use: "list", Short: "List all authenticator entries", Long: "Prints a table of all entries in the config file. For encrypted configs, a password prompt will appear.", Args: cobra.NoArgs, RunE: runList, } } func runList(cmd *cobra.Command, args []string) error { const fn = "cmd.winauth.runList" path := resolveConfigPath(cmd) lang := preferredLanguage(path) _ = i18n.Init(lang) // best-effort; list output is English anyway cfg, _, err := cliLoadConfig(path) if err != nil { if errors.Is(err, config.ErrPasswordWrong) { return fmt.Errorf("wrong password") } return fmt.Errorf("load config: %w", err) } if len(cfg.Entries) == 0 { fmt.Fprintln(os.Stderr, "No entries found.") return nil } tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) fmt.Fprintln(tw, "NAME\tVENDOR\tICON\tHOTKEY") for _, e := range cfg.Entries { fmt.Fprintf(tw, "%s\t%s\t%s\t%s\n", e.Name, e.Vendor, e.IconName, e.Hotkey) } return tw.Flush() }