11package cmd
22
33import (
4+ "context"
5+ "fmt"
46 "os"
5- "sort"
67
8+ "github.com/dedene/lametric-cli/internal/api"
79 "github.com/dedene/lametric-cli/internal/output"
810)
911
1012// IconAliases maps friendly names to LaMetric icon IDs.
13+ // Use "lametric icons search <query>" to find more icons.
1114var IconAliases = map [string ]string {
12- "rocket" : "i120" ,
1315 "checkmark" : "i2867" ,
1416 "cross" : "a2868" ,
15- "heart" : "i339 " ,
16- "star" : "i2283 " ,
17+ "heart" : "a230 " ,
18+ "star" : "i635 " ,
1719 "fire" : "a2735" ,
1820 "warning" : "i555" ,
1921 "info" : "i65" ,
20- "clock" : "i82" ,
21- "calendar" : "i227" ,
22- "mail" : "i65" ,
22+ "clock" : "a82" ,
23+ "calendar" : "i66" ,
24+ "mail" : "i43" ,
25+ "email" : "i20907" ,
2326 "download" : "i120" ,
2427 "upload" : "i121" ,
28+ "rocket" : "a26304" ,
2529 "github" : "i32320" ,
2630 "slack" : "i36682" ,
2731 "thumbsup" : "i14180" ,
@@ -31,14 +35,20 @@ var IconAliases = map[string]string{
3135 "snow" : "i2289" ,
3236 "cloud" : "i2283" ,
3337 "music" : "i612" ,
34- "beer" : "i915 " ,
38+ "beer" : "i3253 " ,
3539 "coffee" : "i16041" ,
3640 "pizza" : "i8779" ,
3741 "dollar" : "i73" ,
3842 "bitcoin" : "i12949" ,
3943 "eye" : "i14092" ,
4044 "lock" : "i242" ,
4145 "unlock" : "i1370" ,
46+ "bell" : "a1370" ,
47+ "phone" : "i124" ,
48+ "home" : "i96" ,
49+ "error" : "i555" ,
50+ "success" : "i2867" ,
51+ "fail" : "a2868" ,
4252}
4353
4454// ResolveIcon returns the icon ID for a name or alias.
@@ -57,31 +67,84 @@ func ResolveIcon(nameOrID string) string {
5767 return nameOrID
5868}
5969
60- // IconsCmd lists available icon aliases.
61- type IconsCmd struct {}
70+ // IconsCmd manages icon search.
71+ type IconsCmd struct {
72+ Popular IconsPopularCmd `cmd:"" default:"1" help:"Show popular icons"`
73+ Search IconsSearchCmd `cmd:"" help:"Search icons by name from LaMetric cloud"`
74+ }
75+
76+ // IconsPopularCmd shows popular icons from the cloud.
77+ type IconsPopularCmd struct {
78+ Limit int `help:"Maximum results to show" default:"30" short:"n"`
79+ }
80+
81+ // Run fetches and displays popular icons.
82+ func (c * IconsPopularCmd ) Run (flags * RootFlags ) error {
83+ f := output .NewFormatter (os .Stdout , flags .JSON , flags .Plain , flags .NoColor )
84+
85+ spinner := output .NewSpinner ("Fetching popular icons..." )
86+ spinner .Start ()
87+
88+ icons , err := api .GetPopularIcons (context .Background (), c .Limit )
89+ spinner .Stop ()
90+
91+ if err != nil {
92+ return fmt .Errorf ("fetch icons: %w" , err )
93+ }
94+
95+ type iconResult struct {
96+ Code string `json:"code"`
97+ Title string `json:"title"`
98+ Type string `json:"type"`
99+ }
62100
63- // Run prints the icon alias table.
64- func (c * IconsCmd ) Run (flags * RootFlags ) error {
101+ results := make ([]iconResult , len (icons ))
102+ rows := make ([][]string , len (icons ))
103+ for i , icon := range icons {
104+ results [i ] = iconResult {Code : icon .Code , Title : icon .Title , Type : icon .Type }
105+ rows [i ] = []string {icon .Code , icon .Title , icon .Type }
106+ }
107+
108+ return f .Output (results , []string {"CODE" , "TITLE" , "TYPE" }, rows )
109+ }
110+
111+ // IconsSearchCmd searches icons in the LaMetric cloud library.
112+ type IconsSearchCmd struct {
113+ Query string `arg:"" help:"Search query (e.g., 'rocket', 'heart')"`
114+ Limit int `help:"Maximum results to show" default:"20" short:"n"`
115+ }
116+
117+ // Run searches for icons matching the query.
118+ func (c * IconsSearchCmd ) Run (flags * RootFlags ) error {
65119 f := output .NewFormatter (os .Stdout , flags .JSON , flags .Plain , flags .NoColor )
66120
67- type iconEntry struct {
68- Alias string `json:"alias"`
69- ID string `json:"id"`
121+ spinner := output .NewSpinner ("Searching icons..." )
122+ spinner .Start ()
123+
124+ icons , err := api .SearchIcons (context .Background (), c .Query , c .Limit )
125+ spinner .Stop ()
126+
127+ if err != nil {
128+ return fmt .Errorf ("search icons: %w" , err )
70129 }
71130
72- names := make ([] string , 0 , len ( IconAliases ))
73- for name := range IconAliases {
74- names = append ( names , name )
131+ if len ( icons ) == 0 {
132+ fmt . Printf ( "No icons found matching %q \n " , c . Query )
133+ return nil
75134 }
76- sort .Strings (names )
77-
78- entries := make ([]iconEntry , 0 , len (names ))
79- rows := make ([][]string , 0 , len (names ))
80- for _ , name := range names {
81- id := IconAliases [name ]
82- entries = append (entries , iconEntry {Alias : name , ID : id })
83- rows = append (rows , []string {name , id })
135+
136+ type iconResult struct {
137+ Code string `json:"code"`
138+ Title string `json:"title"`
139+ Type string `json:"type"`
140+ }
141+
142+ results := make ([]iconResult , len (icons ))
143+ rows := make ([][]string , len (icons ))
144+ for i , icon := range icons {
145+ results [i ] = iconResult {Code : icon .Code , Title : icon .Title , Type : icon .Type }
146+ rows [i ] = []string {icon .Code , icon .Title , icon .Type }
84147 }
85148
86- return f .Output (entries , []string {"ALIAS " , "ID " }, rows )
149+ return f .Output (results , []string {"CODE " , "TITLE" , "TYPE " }, rows )
87150}
0 commit comments