mirror of
https://github.com/onyx-and-iris/lottery-cli.git
synced 2026-08-17 00:34:25 +00:00
add list subcommand
add renderKindList()
This commit is contained in:
24
cmd/lottery/list.go
Normal file
24
cmd/lottery/list.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
@@ -134,6 +134,7 @@ func maxLineWidth(blocks []string) int {
|
|||||||
return maxWidth
|
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 {
|
func renderDrawCollection(title string, entries []string) string {
|
||||||
if len(entries) == 0 {
|
if len(entries) == 0 {
|
||||||
return ""
|
return ""
|
||||||
@@ -149,3 +150,25 @@ func renderDrawCollection(title string, entries []string) string {
|
|||||||
|
|
||||||
return cardStyle.Render(title + "\n" + body)
|
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"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user