From dd49700eb1b8de1e5bb6676fcbf9728c1ba1de69 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 1 Aug 2026 04:19:18 +0100 Subject: [PATCH] add list subcommand add renderKindList() --- cmd/lottery/list.go | 24 ++++++++++++++++++++++++ cmd/lottery/render.go | 23 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 cmd/lottery/list.go diff --git a/cmd/lottery/list.go b/cmd/lottery/list.go new file mode 100644 index 0000000..d8ea93e --- /dev/null +++ b/cmd/lottery/list.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/onyx-and-iris/lottery-cli" +) + +// listCmd represents the list command. +var listCmd = &cobra.Command{ + Use: "list", + Aliases: []string{"ls"}, + Short: "List all available lottery kinds.", + RunE: func(cmd *cobra.Command, args []string) error { + fmt.Println(renderKindList(lottery.AllKinds())) + return nil + }, +} + +func init() { + rootCmd.AddCommand(listCmd) +} diff --git a/cmd/lottery/render.go b/cmd/lottery/render.go index dbfd9d8..3d2af39 100644 --- a/cmd/lottery/render.go +++ b/cmd/lottery/render.go @@ -134,6 +134,7 @@ func maxLineWidth(blocks []string) int { return maxWidth } +// renderDrawCollection renders a collection of draw entries into a single string with a title and separator lines. func renderDrawCollection(title string, entries []string) string { if len(entries) == 0 { return "" @@ -149,3 +150,25 @@ func renderDrawCollection(title string, entries []string) string { return cardStyle.Render(title + "\n" + body) } + +// renderKindList renders a list of lottery kinds into a formatted string. +func renderKindList(kinds []lottery.Kind) string { + lines := make([]string, 0, len(kinds)+1) + lines = append( + lines, + labelStyle.Render("Total:")+" "+numbersStyle.Render(strconv.Itoa(len(kinds))), + ) + + for _, kind := range kinds { + lines = append( + lines, + specialStyle.Render("•")+ + " "+numbersStyle.Render(kindPromptLabel(kind))+ + " "+labelStyle.Render("("+string(kind)+")"), + ) + } + + return cardStyle.Render( + titleStyle.Render("Available lottery kinds") + "\n" + strings.Join(lines, "\n"), + ) +}