Files
GiteaMailTemplates/tools/cli/list.go
T
KenanZhuandClaude Opus 4.8 da8bb2e1a2 style(tools): unify console output with [I/W/E] [Module] color-coded format
- Add ANSI color coding: [I]=green, [W]=yellow, [E]=red
- Format: [Level] [Module] message with 4-char indent for data rows
- Error detail lines use |-> tree connector
- Remove extra blank lines between outputs (except list)
- Modules: CLI, Preview, Builder, Server, Watcher

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 14:21:25 +08:00

58 lines
1.2 KiB
Go

package cli
import (
"fmt"
"os"
"path/filepath"
"sort"
"github.com/urfave/cli/v2"
"gitea-mail-templates/tools/preview"
)
// ListCommand returns the "list" subcommand.
func ListCommand() *cli.Command {
return &cli.Command{
Name: "list",
Usage: "List available theme styles in the target folder",
UsageText: "go run . list [--folder <themes-dir>]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "folder",
Value: "../themes",
Usage: "Path to the themes directory",
},
},
Action: runList,
}
}
func runList(c *cli.Context) error {
folder := c.String("folder")
themes, err := preview.DiscoverThemes(folder)
if err != nil {
return err
}
absDir, _ := filepath.Abs(folder)
fmt.Printf("\033[32m[I]\033[0m [Preview] Available styles in '%s' (%d):\n", filepath.Base(absDir), len(themes))
sort.Strings(themes)
for _, t := range themes {
count := 0
filepath.Walk(filepath.Join(folder, t), func(path string, info os.FileInfo, err error) error {
if err != nil {
return nil
}
if filepath.Ext(path) == ".tmpl" {
count++
}
return nil
})
fmt.Printf("\033[32m[I]\033[0m [Preview] %-16s (%d .tmpl files)\n", t, count)
}
return nil
}